private static IEnumerable <NodeRegex> GetPaddingRegexps(Syntax.Node renderer, NodeRegexContext ctx) { int padding; int.TryParse(GetNormalizedParamValue(renderer, "padding").DefaultIfEmpty("0").First(), out padding); var padChar = GetParamValue(renderer, "padCharacter").DefaultIfEmpty("").First().DefaultIfEmpty(' ').First(); var fixedLength = GetNormalizedParamValue(renderer, "fixedLength").DefaultIfEmpty("false").First() == "true"; if (padding == 0) { return(GetInnerLayoutRegexps(renderer, ctx).Select(ctx.ApplyContextLimitationsToOutputRegex)); } if (fixedLength) { return(GetInnerLayoutRegexps( renderer, ctx.PushWrapper(new RegexModifyingWrapper(WrapperType.NotHandleable, renderer, "padding with fixedLength=True")) )); } var paddingRe = new NodeRegex( string.Format("{0}{{0,{1}}}", ctx.GetRegexFromStringLiteral(new string(padChar, 1)), Math.Abs(padding) ), renderer.Description, NodeRegexFlags.None, renderer.NodeStart, renderer.NodeEnd ); if (padding > 0) { return (EnumOne(paddingRe) .Concat(GetInnerLayoutRegexps(renderer, ctx)) .Select(ctx.ApplyContextLimitationsToOutputRegex)); } else { return (GetInnerLayoutRegexps(renderer, ctx) .Concat(EnumOne(paddingRe)) .Select(ctx.ApplyContextLimitationsToOutputRegex)); } }
public NodeRegex ApplyContextLimitationsToOutputRegex(NodeRegex n) { var notHandleable = wrappersStack.FirstOrDefault(w => w.Type == WrapperType.NotHandleable); if (notHandleable.Type != WrapperType.Invalid) { n.Regex = NotSpecificRegexp; n.WrapperThatMakesRegexNotSpecific = notHandleable; n.Flags |= NodeRegexFlags.IsNotSpecific; } var conditional = wrappersStack.FirstOrDefault(w => w.Type == WrapperType.Conditional); if (conditional.Type != WrapperType.Invalid) { n.WrapperThatMakesRegexConditional = conditional; n.Flags |= NodeRegexFlags.IsConditional; } if (regexpLevel > 0) { n.Flags |= NodeRegexFlags.IsNotTopLevelRegex; } return(n); }
static IEnumerable <NodeRegex> EnumOne(NodeRegex value) { yield return(value); }