Skip to content

Commit 2533795

Browse files
committed
Early attempt at supporting all versions
1 parent 5d323de commit 2533795

File tree

4,079 files changed

+94539
-1243
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,079 files changed

+94539
-1243
lines changed

crates/codegen-v2/parser/src/parser/item_builders.rs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ use serde::Serialize;
99
#[derive(Serialize, Debug, Clone)]
1010
struct RustCode(String);
1111

12-
// TODO(v2): Support multiple versions
13-
pub(crate) const VERSION: Version = Version::new(0, 8, 30);
12+
// Version range for filtering: [MIN_VERSION, MAX_VERSION)
13+
// A VersionSpecifier is enabled if it overlaps with this range
14+
pub(crate) const MIN_VERSION: Version = Version::new(0, 4, 11);
15+
pub(crate) const MAX_VERSION: Version = Version::new(0, 9, 0); // exclusive
1416

1517
/// An `LALRPOPItemInner` represents a single LALRPOP rule, for example:
1618
///
@@ -68,9 +70,35 @@ struct LALRPOPField {
6870
rule: RustCode,
6971
}
7072

71-
/// Checks if a given version specifier enables the supported version
73+
/// Checks if a given version specifier enables any version in the supported range
7274
fn is_enabled(enabled: Option<&VersionSpecifier>) -> bool {
73-
enabled.as_ref().is_none_or(|v| v.contains(&VERSION))
75+
enabled
76+
.as_ref()
77+
.is_none_or(|spec| overlaps_with_version_range(spec))
78+
}
79+
80+
/// Check if a VersionSpecifier overlaps with [MIN_VERSION, MAX_VERSION)
81+
pub(crate) fn overlaps_with_version_range(spec: &VersionSpecifier) -> bool {
82+
match spec {
83+
VersionSpecifier::Always => true,
84+
VersionSpecifier::Never => false,
85+
// "From X onwards" overlaps with [min, max) if X < max
86+
VersionSpecifier::From { from } => from < &MAX_VERSION,
87+
// "Until X" overlaps with [min, max) if X > min
88+
VersionSpecifier::Till { till } => till > &MIN_VERSION,
89+
// Range [from, till) overlaps with [min, max) if from < max && till > min
90+
VersionSpecifier::Range { from, till } => from < &MAX_VERSION && till > &MIN_VERSION,
91+
}
92+
}
93+
94+
pub(crate) fn contains_enabled_versions(spec: &VersionSpecifier) -> bool {
95+
match spec {
96+
VersionSpecifier::Always => true,
97+
VersionSpecifier::Never => false,
98+
VersionSpecifier::From { from } => from <= &MIN_VERSION,
99+
VersionSpecifier::Till { till } => &MAX_VERSION < till,
100+
VersionSpecifier::Range { from, till } => from <= &MIN_VERSION && &MAX_VERSION < till,
101+
}
74102
}
75103

76104
/// Helper rules for LALRPOP matching rules

crates/codegen-v2/parser/src/parser/parser_builder.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ use language_v2_definition::model::{
66

77
use crate::lexer::{Lexeme, LexerModel};
88
use crate::parser::item_builders::{
9-
enum_item_to_lalrpop_items, precedence_item_to_lalrpop_items, repeated_item_to_lalrpop_items,
10-
separated_item_to_lalrpop_items, struct_item_to_lalrpop_items, VERSION,
9+
contains_enabled_versions, enum_item_to_lalrpop_items, overlaps_with_version_range,
10+
precedence_item_to_lalrpop_items, repeated_item_to_lalrpop_items,
11+
separated_item_to_lalrpop_items, struct_item_to_lalrpop_items,
1112
};
1213
use crate::parser::{LALRPOPItem, ParserSection, ParserTopic};
1314

@@ -119,14 +120,14 @@ impl<'a> ParserBuilder<'a> {
119120
..
120121
} => {
121122
// For Keywords, we need to consider reserved and unreserved forms.
122-
if reserved.contains(&VERSION) {
123+
if overlaps_with_version_range(reserved) {
123124
terminals
124125
.entry(kind.clone())
125126
.or_default()
126127
.insert(format!("{kind}_Reserved"));
127128
}
128129

129-
if !reserved.contains(&VERSION) {
130+
if !contains_enabled_versions(&reserved) {
130131
// In particular, for unreserved keywords we add it also to the
131132
// corresponding identifier
132133
if let Some(identifier) = identifier {

crates/solidity-v2/inputs/language/src/definition.rs

Lines changed: 141 additions & 94 deletions
Large diffs are not rendered by default.

crates/solidity-v2/outputs/cargo/cst/src/structured_cst/nodes.generated.rs

Lines changed: 0 additions & 119 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)