Exemplo n.º 1
0
        public static EntityTemplate Parse(string templateJson, IAntlrErrorStrategy errorStrategy = null)
        {
            var lexer  = new EntityTemplateLexer(new AntlrInputStream(templateJson));
            var parser = new EntityTemplateParser(new CommonTokenStream(lexer))
            {
                ErrorHandler = errorStrategy ?? new BailErrorStrategy()
            };

            var ast = parser.template();

            ValidatorVisitor.Reset();
            ValidatorVisitor.Visit(ast);

            try
            {
                ValidatorVisitor.ThrowExceptionIfErrors();
            }
            catch (Exception e)
            {
                throw new InvalidDataException($"Tried to parse template from json: '{templateJson}' but failed. See inner exception for details", e);
            }
            var parserVisitor = new EntityTemplateParserVisitor();

            return(parserVisitor.Visit(ast));
        }
Exemplo n.º 2
0
        public static MalinaParser Create(ITokenStream stream, IAntlrErrorStrategy strategy = null)
        {
            var parser = new MalinaParser(stream);

            if (strategy == null)
            {
                strategy = new MalinaErrorStrategy();
            }
            parser.ErrorHandler = strategy;
            return(parser);
        }