public ParserState(string input) { var inputStream = new AntlrInputStream(input); lexer = new TheLexer(inputStream); var commonTokenStream = new CommonTokenStream(lexer); parser = new TheParser(commonTokenStream); errorListener = new ErrorListener(commonTokenStream); lexer.RemoveErrorListeners(); parser.RemoveErrorListeners(); parser.AddErrorListener(errorListener); }
/// <summary> /// Will convert the input to a Regular Expression String, but will not enclose it with reuired options. Used for testing purposes. /// </summary> /// <param name="input">A string in Impression format.</param> public static string ConvertNoOptions(string input) { var inputStream = new AntlrInputStream(input); var lexer = new TheLexer(inputStream); var commonTokenStream = new CommonTokenStream(lexer); var parser = new TheParser(commonTokenStream); var errorListener = new ErrorListener(commonTokenStream); lexer.RemoveErrorListeners(); parser.RemoveErrorListeners(); parser.AddErrorListener(errorListener); var context = parser.expressionSeq(); var visitor = new Visitor(errorListener); var result = visitor.Visit(context); if (visitor.errorListener.hadErrors) { throw new InvalidOperationException(visitor.errorListener.PrintErrors()); } return(result); }