Beispiel #1
0
        internal IRule GetRuleWithModifier(string name)
        {
            /*
             *      rule?
             *      rule*
             *      rule+
             *      'rule'
             */
            bool sw(string c) => name.StartsWith(c);
            bool ew(string c) => name.EndsWith(c);

            if (ew("?") || ew("*") || ew("+"))
            {
                return(ModifiedRule.CreateModifiedRule(GetRule(name.TrimEnd('?', '*', '+')), name.Last()));
            }

            if (sw("'") && ew("'"))
            {
                var r = new Lexrule("inline" + inlineId++, name.Trim('\''));
                lexer.InsertRule(0, r);
                return(r);
            }

            return(GetRule(name));
        }
Beispiel #2
0
        internal static IRule CreateModifiedRule(IRule inner, char type)
        {
            ModifiedRule rule = type switch {
                '?' => new Optional(),
                '*' => new ZeroOrMore(),
                '+' => new OneOrMore(),
                _ => null
            };

            if (rule == null)
            {
                return(inner);
            }

            rule.inner = inner;
            return(rule);
        }