Say I have a line like this:
var code = "Private Sub DoSomething(ByVal foo As Integer)\r\n DoSomethingElse(foo)\r\nEnd Sub";
When I pass my ANTLR parser with this line, I get a parsing tree that looks something like this:
[SubStmtContext]
[VisibilityContext]
[ArgListContext]
[ArgContext]
[AmbiguousIdentifierContext]
[AsTypeClauseContext]
[BlockContext]
[ImplicitCallStmt_InBlockContext]
[ICS_B_SubCallContext]
[CertainIdentifierContext]
[ArgsCallContext]
[ArgCallContext]
[ValueStmtContext]
[ImplicitCallStmt_InStmtContext]
[ICS_S_VariableCallContext]
[VariableCallStmtContext]
[AmbiguousIdentifierContext]
The base class ParserRuleContextcontains the properties IToken Startand IToken Stop, each of which sets the number Linec StartIndexand a StopIndex.
So, back to my input line, I have an identifier DoSomethingin row 1, the beginning of column position 12 and stop 22 - why is it that I have an identifier DoSomethingElsein row 2, beginning 51 of the column position and stop 65?
ANTLR, \r\n , ? - , ... , DoSomethingElse 2, 4 18, ?
, :
public IParseTree Parse(string code)
{
var input = new AntlrInputStream(code);
var lexer = new VBLexer(input);
var tokens = new CommonTokenStream(lexer);
var parser = new VBParser(tokens);
var result = parser.StartRule();
return result;
}
. - ?