private void Highlighting(object sender, TextChangedEventArgs e) { try { //ANTLRReaderStream input = new ANTLRReaderStream(Code.Document) string text = new TextRange(Code.Document.ContentStart, Code.Document.ContentEnd).Text; //ANTLRInputStream reader = new ANTLRInputStream(text); ANTLRStringStream input = new ANTLRStringStream(text); GrammarLexer lexer = new GrammarLexer((Antlr4.Runtime.ICharStream)input); ITokenStream tokens = new CommonTokenStream((Antlr.Runtime.ITokenSource)lexer); GrammarParser parser = new GrammarParser((Antlr4.Runtime.ITokenStream)tokens); parser.prog(); } catch (Exception ex) { } }
// Public methods public FeatureSelection Execute(CustomRule targetCustomRule) { // Get the expression string expr = targetCustomRule.Expression; // OBS: an example for syntax: ">root.TotalScore=SumOf(>root.>descendants.ScoreValue)"; if (expr == null || expr == "") { return(null); } // Parse the expression AntlrInputStream inputToParse = new AntlrInputStream(expr); GrammarLexer lexer = new GrammarLexer(inputToParse); CommonTokenStream tokens = new CommonTokenStream(lexer); GrammarParser grammarParser = new GrammarParser(tokens); IParseTree tree = grammarParser.prog(); Visitor visitor = new Visitor(configInstance); // Execute it and return the parent FeatureSelection of the modified AttributeValue (left side of the expression) var result = visitor.Visit(tree); return(result as FeatureSelection); }