示例#1
0
        public Parser Generate(ParserGenerationContext ctx)
        {
            if (Defined)
            {
                return(GeneratedParser);
            }
            Defined = true;

            GeneratedParser.Definition = Expression.Generate(ctx);

            var matchWhitespace  = Options.Any(x => x.Option == "match-whitespace");
            var ignoreWhitespace = Options.Any(x => x.Option == "skip-whitespace");

            foreach (var option in Options.Where(x => x.Option == "whitespace-rule"))
            {
                var arg  = option.Args.First();
                var rule = ctx.GetRule(arg, ((Identifier)arg).Value);
                GeneratedParser.Definition = new WhitespaceRuleParser(GeneratedParser.Definition, rule);
            }

            if (matchWhitespace && !ignoreWhitespace)
            {
                GeneratedParser.Definition = GeneratedParser.Definition.MatchWhitespace;
            }
            else if (ignoreWhitespace && !matchWhitespace)
            {
                GeneratedParser.Definition = GeneratedParser.Definition.IgnoreWhitespace;
            }

            return(GeneratedParser);
        }
示例#2
0
        public Parser Generate(string rootParserName = null)
        {
            if (rootParserName == null)
            {
                return(ParserGenerationContext.Generate(Rules));
            }

            var root = Rules.FirstOrDefault(x => x.Identifier == rootParserName);

            if (root == null)
            {
                throw new ArgumentException("No rule found with the given name.", "rootParserName");
            }

            return(ParserGenerationContext.Generate(new[] { root }.Concat(Rules.Where(x => x != root)).ToArray()));
        }
示例#3
0
        public static Parser Generate(params Rule[] rules)
        {
            if (rules.Length == 0)
            {
                return(Parser.Null("No rules specified"));
            }

            var ctx = new ParserGenerationContext();

            ctx.AddRules(rules);
            var result = rules.First().Generate(ctx);

            if (ctx._errors.Any())
            {
                throw new ParserGenerationException(ctx._errors.ToArray());
            }

            return(result);
        }
示例#4
0
        public Parser Generate(ParserGenerationContext ctx)
        {
            if (Defined)
            {
                return(GeneratedParser);
            }
            Defined = true;

            GeneratedParser.Definition = Expression.Generate(ctx);

            var matchWhitespace  = Options.Contains("match-whitespace");
            var ignoreWhitespace = Options.Contains("skip-whitespace");

            if (matchWhitespace && !ignoreWhitespace)
            {
                GeneratedParser.Definition = GeneratedParser.Definition.MatchWhitespace;
            }
            else if (ignoreWhitespace && !matchWhitespace)
            {
                GeneratedParser.Definition = GeneratedParser.Definition.IgnoreWhitespace;
            }

            return(GeneratedParser);
        }
示例#5
0
 public override Parser Generate(ParserGenerationContext ctx)
 {
     return base.Generate(ctx).Repeated;
 }
示例#6
0
        public static Parser Generate(params Rule[] rules)
        {
            if (rules.Length == 0) {
                return Parser.Null("No rules specified");
            }

            var ctx = new ParserGenerationContext();
            ctx.AddRules(rules);
            var result = rules.First().Generate(ctx);

            if (ctx._errors.Any()) {
                throw new ParserGenerationException(ctx._errors.ToArray());
            }

            return result;
        }
示例#7
0
 public override Parser Generate(ParserGenerationContext ctx)
 {
     return Value;
 }
示例#8
0
 public override Parser Generate(ParserGenerationContext ctx)
 {
     return Expression.Generate(ctx);
 }
示例#9
0
 public Parser Generate(ParserGenerationContext ctx)
 {
     return Alternation.Generate(ctx);
 }
示例#10
0
 public abstract Parser Generate(ParserGenerationContext ctx);
示例#11
0
 public Parser Generate(ParserGenerationContext ctx)
 {
     return(Parser.Concat(Factors.Select(x => x.Generate(ctx)).ToArray()));
 }
示例#12
0
 public Parser Generate(ParserGenerationContext ctx)
 {
     return(Parser.Alternation(Concatenations.Select(x => x.Generate(ctx)).ToArray()));
 }
示例#13
0
 public Parser Generate(ParserGenerationContext ctx)
 {
     return(Alternation.Generate(ctx));
 }
示例#14
0
 public Parser Generate(ParserGenerationContext ctx)
 {
     return Parser.Alternation(Concatenations.Select(x => x.Generate(ctx)).ToArray());
 }
示例#15
0
 public override Parser Generate(ParserGenerationContext ctx)
 {
     return(ctx.GetRule(this, Value));
 }
示例#16
0
 public Parser Generate(ParserGenerationContext ctx)
 {
     return Parser.Concat(Factors.Select(x => x.Generate(ctx)).ToArray());
 }
示例#17
0
 public override Parser Generate(ParserGenerationContext ctx)
 {
     return(Value);
 }
示例#18
0
 public abstract Parser Generate(ParserGenerationContext ctx);
示例#19
0
 public override Parser Generate(ParserGenerationContext ctx)
 {
     return(Regex);
 }
示例#20
0
 public override Parser Generate(ParserGenerationContext ctx)
 {
     return ctx.GetRule(this, Value);
 }
示例#21
0
 public override Parser Generate(ParserGenerationContext ctx)
 {
     return(Expression.Generate(ctx));
 }
示例#22
0
 public override Parser Generate(ParserGenerationContext ctx)
 {
     return base.Generate(ctx).Optional;
 }
示例#23
0
 public override Parser Generate(ParserGenerationContext ctx)
 {
     return(base.Generate(ctx).Optional);
 }
示例#24
0
 public override Parser Generate(ParserGenerationContext ctx)
 {
     return Regex;
 }
示例#25
0
 public override Parser Generate(ParserGenerationContext ctx)
 {
     return(base.Generate(ctx).Repeated);
 }
示例#26
0
        public Parser Generate(ParserGenerationContext ctx)
        {
            if (Defined) return GeneratedParser;
            Defined = true;

            GeneratedParser.Definition = Expression.Generate(ctx);

            var matchWhitespace = Options.Contains("match-whitespace");
            var ignoreWhitespace = Options.Contains("skip-whitespace");

            if (matchWhitespace && !ignoreWhitespace) {
                GeneratedParser.Definition = GeneratedParser.Definition.MatchWhitespace;
            } else if (ignoreWhitespace && !matchWhitespace) {
                GeneratedParser.Definition = GeneratedParser.Definition.IgnoreWhitespace;
            }

            return GeneratedParser;
        }
示例#27
0
        public Parser Generate(ParserGenerationContext ctx)
        {
            if (Defined) return GeneratedParser;
            Defined = true;

            GeneratedParser.Definition = Expression.Generate(ctx);

            var matchWhitespace = Options.Any(x => x.Option == "match-whitespace");
            var ignoreWhitespace = Options.Any(x => x.Option == "skip-whitespace");

            foreach (var option in Options.Where(x => x.Option == "whitespace-rule"))
            {
                var arg = option.Args.First();
                var rule = ctx.GetRule(arg, ((Identifier) arg).Value);
                GeneratedParser.Definition = new WhitespaceRuleParser(GeneratedParser.Definition, rule);
            }

            if (matchWhitespace && !ignoreWhitespace) {
                GeneratedParser.Definition = GeneratedParser.Definition.MatchWhitespace;
            } else if (ignoreWhitespace && !matchWhitespace) {
                GeneratedParser.Definition = GeneratedParser.Definition.IgnoreWhitespace;
            }

            return GeneratedParser;
        }