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

Lexing of string interpolation #36

Open
kubouch opened this issue Dec 28, 2024 · 0 comments
Open

Lexing of string interpolation #36

kubouch opened this issue Dec 28, 2024 · 0 comments
Labels

Comments

@kubouch
Copy link
Collaborator

kubouch commented Dec 28, 2024

Nushell supports string interpolation:

  • $"foo(<expression>)bar" (double-quoted string supports escapes)
  • $'foo(<expression>)bar' (single-quoted string doesn't have escapes)
    where <expression> can be any valid Nushell syntax.

This is problematic to lex because we need to lex the parts outside the () as string chunks and tha parts inside () as full Nushell syntax. We need to somehow be able to switch to a different lexing mode when encountering $" or $', then switch to the default mode when encountering (, go back to the string interpolation mode on ) and finally return to the default mode on " or '.

Two possible solutions:

  • Use morph() inside lex() to switch between the string interpolation and default Nushell lexers. Related Logos issue: Context-dependent lexing maciejhirsz/logos#116, example code is mentioned in the issue.
  • If the above is too unwieldy, switch back to on-demand lexing, i.e., make Tokens.advance() lex and fetch the next token from the Logos lexer iterator instead of lexing everything in advance. This would make is possible to switch the lexer during parsing, making it possibly easier to implement, but also possibly slower.
@kubouch kubouch added the lexer label Dec 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant