public CSNode ParseScript(string script) { AntlrInputStream inputStream = new AntlrInputStream(script); CSScriptLexer lexer = new CSScriptLexer(inputStream); CommonTokenStream commonTokenStream = new CommonTokenStream(lexer); CSScriptParser parser = new CSScriptParser(commonTokenStream); parser.AddErrorListener(new CSDebugLogListener()); CSScriptParser.CodeContext code = parser.code(); CSNodeGenerator generator = new CSNodeGenerator(); return(generator.Visit(code)); }
public override CSNode VisitCode(CSScriptParser.CodeContext context) { CSNode node = new CSNode(context.Start.Line, context.Start.Column); CSScriptParser.LineContext[] lines = context.line(); int len = lines.Length; node._children = new CSNode[len]; for (int i = 0; i < len; ++i) { node._children[i] = Visit(lines[i]); } return(node); }
/// <summary> /// Visit a parse tree produced by <see cref="CSScriptParser.code"/>. /// <para> /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/> /// on <paramref name="context"/>. /// </para> /// </summary> /// <param name="context">The parse tree.</param> /// <return>The visitor result.</return> public virtual Result VisitCode([NotNull] CSScriptParser.CodeContext context) { return(VisitChildren(context)); }