Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we reuse the results from the scanner/lexer for the full parse? #55

Open
f-markus opened this issue May 5, 2023 · 2 comments
Open

Comments

@f-markus
Copy link

f-markus commented May 5, 2023

For performance reasons, I'm starting with just the lexer (so the app is really responsive to user inputs):

var parser = new Irony.Parsing.Parser.Parser(_langData);
parser.Scanner.VsSetSource(source, 0, 0);
do { 
  var token = parser.Scanner.VsReadToken(ref state); 
} while (...)

Afterwards, for the full parse, it would be nice to reuse the already calculated tokens. Something like so

var tree = parser.Parse(tokenlist);

I already played around a little bit, but I was not successful. I managed to supply a list of tokens, but it seems that during parsing, some additional state is stored with the tokens. This state seems not to be there when just calling VsReadToken().

Am I missing something?

@rivantsov
Copy link
Contributor

You are right, there's no such direct facility, unfortunately. You can try workaround.
Add token list to ParseContext.BufferedTokens; it is internal but you can reach it using Reflection. And then provide empty source text to Parser. The parser would consume all bufferred tokens first and then empty actual source.

@rivantsov
Copy link
Contributor

or just add another consturctor to Parser class, and add tokens to BufferTokens

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants