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

How can I use the matchLongest lexer option? #406

Closed
wrycode opened this issue May 9, 2024 · 2 comments
Closed

How can I use the matchLongest lexer option? #406

wrycode opened this issue May 9, 2024 · 2 comments

Comments

@wrycode
Copy link

wrycode commented May 9, 2024

It's a private field and I don't see a way to set it

@alecthomas
Copy link
Owner

It looks like dead code, I'll remove it. What are you trying to achieve?

@wrycode
Copy link
Author

wrycode commented May 10, 2024

My project needs to parse input with user-defined 'form' dictionaries where a form could be one or multiple characters from the input stream, and the largest should be selected first. It's for phonetics. One example is 'kw', which makes the 'q' form, where 'k' and 'w' are also individual forms when they're not found together.

Struct tags can't be changed at runtime, so I was just converting each 'form' to a token in the lexer. It's possible to generate regex like kw|(k?w) but it gets kind of messy. Now my plan is to generate a prefix tree data structure from the user's form dictionary and just write my own parser that traverses the prefix tree while scanning the input to find the longest match.

I appreciate your work on this library.

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