-
-
Notifications
You must be signed in to change notification settings - Fork 264
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
Allow use of rust keywords as pest rules #750
Conversation
This prefixes all non-builtin rules with r# to allow for use of rust keywords as pest rules. This refactors code to use format_ident! rather than Ident::new (with format! internally in some cases), as it does the same thing internally. Span is defined to fallback to Span::call_site() in case of being given a non-ident, so there shouldn't be any issues. Updated generate_complete test case and removed the rust keyword restriction from the validator.
* Updated tests that use identifiers to escape them with `r#` * Changed the previously added `generate_complete` `r#if` test to ensure using an identifier as an expression is properly emitted * Removed some redundant Ident::new() inside of `format_ident!` calls
This is super interesting. What compatibility breaks could there be? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great stuff! there's at least one semver breaking change, so one possibly suggestion may be to keep the old unused public function and mark it deprecated.
Also, would it be possible to add or extend derive
's tests to have a grammar that uses some Rust keywords?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
cargo fmt
- bring back
validate_rust_keywords
and mark it deprecated:
Checking pest_meta
Checking <unknown> v2.5.0 -> v2.5.1 (patch change)
Completed [ 0.116s] 22 checks; 21 passed, 1 failed, 0 unnecessary
--- failure function_missing: pub fn removed or renamed ---
Description:
A publicly-visible function cannot be imported by its prior path. A `pub use` may have been removed, or the function itself may have been renamed or removed entirely.
ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
impl: https://github.com/obi1kenobi/cargo-semver-check/tree/v0.14.0/src/queries/function_missing.ron
Failed in:
function pest_meta::validator::validate_rust_keywords, previously in file meta/src/validator.rs:120
Final [ 0.117s] semver requires new major version: 1 major and 0 minor checks failed
There shouldn't be any compatibility breaks, as |
`generate_rule` was checking the name after formatting for whether it was `WHITESPACE` or `COMMENT`. Re-imported proc_macro2::Span for tests since they still use it.
This prefixes all non-builtin rules with
r#
to allow for use of rust keywords as pest rules. This is my first pull request so please let me know if I should make any changes.This refactors code to use
format_ident!
rather thanIdent::new
(withformat!
internally in the case of_PEST_GRAMMAR_{}
), as it works the same internally, with theSpan
falling back toSpan::call_site()
when not given anIdent
, so there shouldn't be any issues.Updated test cases that use identifiers as expressions to test escaping them
Fixes #747