Skip to content

Commit

Permalink
remove EnumVariat::name from DSL v2 (#697)
Browse files Browse the repository at this point in the history
Since it is no longer needed after enums were simplified in #610.
We can just use the referenced item name directly.
  • Loading branch information
OmarTawfik authored Dec 6, 2023
1 parent 64233cb commit 7a3c1fb
Show file tree
Hide file tree
Showing 7 changed files with 222 additions and 357 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ fn check_enum_items(analysis: &mut Analysis) {
let mut variants = HashSet::new();

for variant in &item.variants {
let name = &variant.name;
if !variants.insert(&**name) {
analysis.errors.add(name, &Errors::ExistingVariant(name));
let reference = &variant.reference;
if !variants.insert(&**reference) {
analysis
.errors
.add(reference, &Errors::ExistingVariant(reference));
}
}
}
Expand Down Expand Up @@ -165,7 +167,7 @@ fn calculate_defined_in(analysis: &mut Analysis, item: &SpannedItem) -> VersionS
enum Errors<'err> {
#[error("An item with the name '{0}' already exists.")]
ExistingItem(&'err Identifier),
#[error("A variant with the name '{0}' already exists.")]
#[error("A variant referencing '{0}' already exists.")]
ExistingVariant(&'err Identifier),
#[error("An expression with the name '{0}' already exists.")]
ExistingExpression(&'err Identifier),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,7 @@ fn check_enum(analysis: &mut Analysis, item: &SpannedEnumItem, enablement: &Vers
let enablement = update_enablement(analysis, enablement, enabled);

for variant in variants {
let SpannedEnumVariant {
name: _,
enabled,
reference,
} = variant;
let SpannedEnumVariant { reference, enabled } = variant;

let enablement = update_enablement(analysis, &enablement, enabled);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ pub struct EnumItem {
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[derive_spanned_type(ParseInputTokens, WriteOutputTokens)]
pub struct EnumVariant {
pub name: Identifier,
pub reference: Identifier,

pub enabled: Option<VersionSpecifier>,

pub reference: Identifier,
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ codegen_language_macros::compile!(Language(
Enum(
name = Bar,
variants = [
EnumVariant(name = Variant1, reference = Baz),
EnumVariant(name = Variant2, reference = Baz),
EnumVariant(name = Variant1, reference = Baz)
EnumVariant(reference = Baz1),
EnumVariant(reference = Baz2),
EnumVariant(reference = Baz1)
]
),
Token(
name = Baz,
definitions = [TokenDefinition(scanner = Atom("baz"))]
name = Baz1,
definitions = [TokenDefinition(scanner = Atom("baz1"))]
),
Token(
name = Baz2,
definitions = [TokenDefinition(scanner = Atom("baz2"))]
)
]
)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: A variant with the name 'Variant1' already exists.
--> src/fail/definitions/duplicate_variant_name/test.rs:19:44
error: A variant referencing 'Baz1' already exists.
--> src/fail/definitions/duplicate_variant_name/test.rs:19:49
|
19 | EnumVariant(name = Variant1, reference = Baz)
| ^^^^^^^^
19 | EnumVariant(reference = Baz1)
| ^^^^
Loading

0 comments on commit 7a3c1fb

Please sign in to comment.