Esempio n. 1
0
        private void Load(AntlrInputStream input)
        {
            var scopedTypeMap = new TypeMap(_loader, _rootTypeMap);
            var parserContext = new ParserContext(_loader, scopedTypeMap);
            var listener      = new RuleSharpParserListener(parserContext, _defaultRuleSet);

            var lexer       = new RuleSharpLexer(input);
            var tokenStream = new CommonTokenStream(lexer);
            var walker      = new ParseTreeWalker();

            try
            {
                var parser = new RuleSharpParser(tokenStream);
                parser.ErrorHandler = new BailErrorStrategy();
                var tree = parser.compilation_unit();
                walker.Walk(listener, tree);
            }
            catch (ParseCanceledException pce)
            {
                var re       = (RecognitionException)pce.InnerException;
                var location = tokenStream.GetSourceLocation(re.Context);
                throw new RulesParseException("Failed to parse rules", location, re);
            }
            catch (RecognitionException re)
            {
                var location = tokenStream.GetSourceLocation(re.Context);
                throw new RulesParseException("Failed to parse rules", location, re);
            }
            catch (InternalParseException pe)
            {
                var location = tokenStream.GetSourceLocation(pe.Context);
                throw new RulesParseException(pe.Message, location, pe.InnerException);
            }
        }
Esempio n. 2
0
        private void Load(AntlrInputStream input)
        {
            var scopedTypeMap = new TypeMap(_loader, _rootTypeMap);
            var parserContext = new ParserContext(_loader, scopedTypeMap);
            var listener      = new RuleSharpParserListener(parserContext, _defaultRuleSet);

            var tree   = ParseTree(input);
            var walker = new ParseTreeWalker();

            walker.Walk(listener, tree);
        }