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

Move parser to solely use $ for variables for 2021 edition support #27

Merged
merged 2 commits into from
Jun 30, 2022

Conversation

udoprog
Copy link
Owner

@udoprog udoprog commented Jun 29, 2022

We have to stop using # as a delimiter, because the 2021 edition reserved any identifier-prefixed # tokens making expressions like these no longer be legal:

quote!(hello#world);

This would be seen as the hello#world token by Rust 2021, and since the hello prefix is not recognized by the Rust compiler and would not compile. See https://doc.rust-lang.org/edition-guide/rust-2021/reserving-syntax.html for more.

$ does not suffer from this (and is more in the spirit of macros) so we're now moving all syntax to use it even if that means it's a bit more verbose.

This implements the following parser changes:

  • #var is now $var.
  • #(var + 5) is now $(var + 5)
  • #_(hello world) is now $[str](hello world).
  • #_(hello $world) is now $[str](hello $world) (runtime evaluation, like having hello ${world} in javascript).
  • #_(hello $(world + 1)) is now $[str](hello $(world + 1)) (runtime evaluation, like having hello ${world + 1} in javascript).
  • #_(hello #world) is now $[str](hello $[const](world)) (compile time evaluation, whatever value world has will become a component of the generated string).

The following control sequences are changed:

  • #<space> becomes $[' ']
  • #<push> becomes $['\r'].
  • #<line> becomes $['\n'].

This change will be part of the genco 0.17 release.

@udoprog
Copy link
Owner Author

udoprog commented Jun 29, 2022

This is being tested in https://github.com/reproto/reproto/tree/genco-2021

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

Successfully merging this pull request may close these issues.

None yet

1 participant