Skip to content

Commit

Permalink
using single references for enums to eliminate backtracking
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarTawfik committed Nov 3, 2023
1 parent af35add commit 55a278c
Show file tree
Hide file tree
Showing 5 changed files with 342 additions and 691 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,18 @@ fn check_enum(analysis: &mut Analysis, item: &EnumItem, enablement: &VersionSet)
let EnumVariant {
name: _,
enabled,
error_recovery: _,
fields,
reference,
} = &**variant;

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

check_fields(analysis, Some(name), &fields, &enablement);
check_reference(
analysis,
Some(name),
reference,
&enablement,
ReferenceFilter::Nodes,
);
}
}

Expand Down
3 changes: 1 addition & 2 deletions crates/codegen/language/definition/src/model/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ mod wrapper {

pub enabled: Option<VersionSpecifier>,

pub error_recovery: Option<FieldsErrorRecovery>,
pub fields: IndexMap<Identifier, Field>,
pub reference: Identifier,
}

#[derive(Debug, Eq, PartialEq, Serialize)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@ codegen_language_macros::compile!(Language(
title = "Section One",
topics = [Topic(
title = "Topic One",
items = [Enum(
name = Bar,
variants = [
EnumVariant(name = Variant1, fields = ()),
EnumVariant(name = Variant2, fields = ()),
EnumVariant(name = Variant1, fields = ())
]
)]
items = [
Enum(
name = Bar,
variants = [
EnumVariant(name = Variant1, reference = Baz),
EnumVariant(name = Variant2, reference = Baz),
EnumVariant(name = Variant1, reference = Baz)
]
),
Token(
name = Baz,
definitions = [TokenDefinition(scanner = Atom("baz"))]
)
]
)]
)]
));
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:18:40
--> src/fail/definitions/duplicate_variant_name/test.rs:19:44
|
18 | EnumVariant(name = Variant1, fields = ())
| ^^^^^^^^
19 | EnumVariant(name = Variant1, reference = Baz)
| ^^^^^^^^
Loading

0 comments on commit 55a278c

Please sign in to comment.