Skip to content

How to correctly parse the text in the specified range? #7

Answered by danipen
pengsongkun741 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @pengsongkun741.

The call to IGrammar.TokenizeLine(string lineText, StackElement prevState) should allow null values for the prevState param for those cases you want to parse a single line.

The line you are parsing should be well-formed from a lexer point of view.

If not, you should include some prev/next lines to build a well-formed text chunk, doing the following to maintain a parsing context:

StackElement ruleStack = null;

foreach (string line in linesToParse)
{
    ITokenizeLineResult result = grammar.TokenizeLine(line, ruleStack);
    ruleStack = result.RuleStack;

    // process the result.GetTokens() for the line you're interested in
}

Replies: 9 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by danipen
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
2 participants
Converted from issue

This discussion was converted from issue #3 on December 14, 2021 08:30.