Skip to content

Commit

Permalink
hack: Try to preserve DSL v1 behaviour a bit more
Browse files Browse the repository at this point in the history
This allows using `constructor` keyword in 0.4.22 but some
keywords are too eagerly reserved like `leave` in Yul since 0.6.0,
whereas it's actually reserved in 0.7.1.

See #568.
  • Loading branch information
Xanewok committed Nov 12, 2023
1 parent 08a20b6 commit 8f3e978
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 30 deletions.
19 changes: 14 additions & 5 deletions crates/solidity/inputs/language/src/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,26 +193,35 @@ fn resolve_token(
}

fn resolve_keyword(keyword: model::KeywordItem) -> codegen_grammar::ScannerDefinitionNode {
// FIXME: Handle reserved keywords using the given "Identifier" parser
let _identifier = keyword.identifier;
// TODO(#568): Handle reserved keywords using the given "Identifier" parser
let _ = keyword.identifier;

let defs: Vec<_> = keyword
.definitions
.into_iter()
.map(|def| {
// FIXME: Properly support contextual keywords.
// Currently, to minimize the diff and ease the transition to the DSL v2, we treat them as normal keywords.
// Moreover, since the DSL v1 only treats "enablement" as being reserved, we try to preserve that for now.
let value = resolve_keyword_value(def.value);
// If missing, the default is "Always"
match (def.enabled, def.reserved) {
// Contextual keywords (never reserved)
// TODO(#568): Properly support contextual keywords.
// Currently, to minimize the diff and ease the transition to the DSL v2, we treat them as normal keywords.
// Moreover, since the DSL v1 only treats "enablement" as being reserved, we try to preserve that for now.
(enabled, Some(VersionSpecifier::Never)) => match enabled {
Some(enabled) => {
ScannerDefinitionNode::Versioned(Box::new(value), enabled_to_range(enabled))
}
None => value,
},
// TODO(#568): If a contextual keyword was enabled at some point and then reserved, for now we treat it
// as a reserved keyword starting from when it was being used, to preserve the DSL v1 behaviour.
(
Some(VersionSpecifier::From { from: enabled }),
Some(VersionSpecifier::From { from: reserved }),
) if enabled < reserved => ScannerDefinitionNode::Versioned(
Box::new(value),
enabled_to_range(VersionSpecifier::From { from: enabled }),
),
(_, Some(reserved)) => {
ScannerDefinitionNode::Versioned(Box::new(value), enabled_to_range(reserved))
}
Expand Down
8 changes: 4 additions & 4 deletions crates/solidity/outputs/cargo/crate/src/generated/language.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions crates/solidity/outputs/npm/crate/src/generated/language.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

0 comments on commit 8f3e978

Please sign in to comment.