File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
crates/formality-macros/src Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -27,9 +27,19 @@ pub(crate) fn derive_parse_with_spec(
27
27
28
28
let type_name = Literal :: string ( & format ! ( "`{}`" , s. ast( ) . ident) ) ;
29
29
30
- if s. variants ( ) . len ( ) == 1 {
30
+ if let syn:: Data :: Struct ( _) = s. ast ( ) . data {
31
+ // For structs, where there is only one variant, use the external grammar (if any).
31
32
stream. extend ( parse_variant ( & type_name, & s. variants ( ) [ 0 ] , external_spec) ?) ;
32
33
} else {
34
+ // If there are multiple variants, there should not be an external grammar.
35
+ // Parse them all and require an unambiguous parse.
36
+ if external_spec. is_some ( ) {
37
+ return Err ( syn:: Error :: new_spanned (
38
+ & s. ast ( ) . ident ,
39
+ "for enums provide the grammar on each variant" . to_string ( ) ,
40
+ ) ) ;
41
+ }
42
+
33
43
stream. extend ( quote ! {
34
44
let mut __results = vec![ ] ;
35
45
} ) ;
You can’t perform that action at this time.
0 commit comments