Example #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);
            }
        }