-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Lua lexer #3
Comments
Wow! I'm happy this package finding it's use outside of my own projects already! Thank you for this example. In short, try to tokenize a code with empty strings. In my opinion, it is only safe to discard things that won't be missed when you try to glue the tokens array back and it will still be valid code. Otherwise be ready to think about edge cases.
In theory, it might be possible to keep track of rules that returned an empty match and return at most a single token at current offset. This will complicate the implementation and I'm not sure it's a good idea. Related note: you produce Another note:
This is ultimately a designer's choice but, if putting an effort to keep things separate to this point, I'd think whether keeping this information in rules and tokens could be beneficial for the parser as well, like this: const opRules = ops.map((v) => ({ name: 'Operation', str: v }));
const keywordRules = keywords.map((v) => ({ name: 'Keyword', str: v }));
const symbolRules = symbols.map((v) => ({ name: 'Symbol', str: v })); Rule names don't have to be unique. It is very similar to making a single regex rule that will match any of listed values. For a PR, example should be self-contained, like the existing ones. Just call the lexer with minimal sample(s) to illustrate variety of supported grammar and log to console. Project tests run all examples and store the output as a snapshot. I'm more concerned about comments. Examples must be that - examples for those who are learning how to use the package. Link(s) to official grammar is a must for an existing language. And any comments to describe the lexer design. The bigger the grammar - the more explanation it might need. (I was quite lazy about samples and comments because my examples essentially are excerpts from peberminta examples. Big samples would also lead to unnecessarily big snapshots.) |
Thank you so much for leac, its API is very elegant and easy to use.
I'm creating the new assignments for the compilers class at the college of engineering UBA (University of Buenos Aires). The students might use the following lua lexer which I want to share with you in case you find it useful. If I find the time I'll write some more tests and add an example in a PR.
The text was updated successfully, but these errors were encountered: