Skip to content

Commit cb1ab72

Browse files
committed
xdr_codegen/parser: allow struct members to be declared as 'enum identifier'
Some specs have a construct like enum foo { A = 0, B = 1 }; struct blah { enum foo type; int a; }; Previously that wouldn't parse because the member declaration was expected to start with an identifier, not the keyword 'enum'. But it's a reasonable construct so there's no reason to disallow it.
1 parent 504ea56 commit cb1ab72

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

xdr_codegen/src/parser.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,12 @@ impl<'src> Parser<'src> {
505505
let name = self.expect_identifier("Expected identifier after 'struct'");
506506
XdrType::Name(name.to_string())
507507
}
508+
TokenKind::Enum => {
509+
// Don't allow anonymous enum declared within outer structs, but do allow using
510+
// "enum identifier" as a long form of "identifier":
511+
let name = self.expect_identifier("Expected identifier after 'enum'");
512+
XdrType::Name(name.to_string())
513+
}
508514
TokenKind::Identifier(name) => XdrType::Name(name.to_string()),
509515
_ => Parser::error("Expected type specifier to begin declaration", Some(tok)),
510516
}

0 commit comments

Comments
 (0)