Esempio n. 1
0
        public DslParser.PatternContext Parse(string data)
        {
            DslParser.PatternContext pattern = null;
            var errorListener = new AntlrMemoryErrorListener()
            {
                IsPattern = true
            };

            errorListener.FileName = "Pattern";
            errorListener.FileData = data;
            errorListener.Logger   = Logger;
            try
            {
                var      inputStream = new AntlrInputStream(data);
                DslLexer lexer       = new DslLexer(inputStream);

                lexer.RemoveErrorListeners();
                lexer.AddErrorListener(errorListener);

                var       tokenStream = new CommonTokenStream(lexer);
                DslParser parser      = new DslParser(tokenStream);
                parser.RemoveErrorListeners();
                parser.AddErrorListener(errorListener);
                pattern = parser.pattern();
            }
            catch (Exception ex)
            {
                Logger.LogError(new ParsingException("Pattern", ex)
                {
                    IsPattern = true
                });
                throw;
            }

            return(pattern);
        }
Esempio n. 2
0
        public DslParser.PatternContext Parse(string patternKey, string data)
        {
            DslParser.PatternContext pattern = null;
            var sourceFile = new TextFile(data)
            {
                PatternKey = patternKey ?? data
            };
            var errorListener = new AntlrMemoryErrorListener()
            {
                IsPattern  = true,
                SourceFile = sourceFile,
                Logger     = Logger
            };

            try
            {
                var      inputStream = new AntlrInputStream(data);
                DslLexer lexer       = new DslLexer(inputStream);

                lexer.RemoveErrorListeners();
                lexer.AddErrorListener(errorListener);

                var       tokenStream = new CommonTokenStream(lexer);
                DslParser parser      = new DslParser(tokenStream);
                parser.RemoveErrorListeners();
                parser.AddErrorListener(errorListener);
                pattern = parser.pattern();
            }
            catch (Exception ex) when(!(ex is ThreadAbortException))
            {
                Logger.LogError(new ParsingException(sourceFile, ex));
                throw;
            }

            return(pattern);
        }