Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify ABNF vs. lexer/parser annotations. #28215

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/parser/src/parser/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ impl<N: Network> ParserContext<'_, N> {
let span = start + identifier.span;

// TODO: Verify that this check is sound.
// Check that there is no whitespace in between the `@` symbol and identifier.
// Check that there is no whitespace or comments in between the `@` symbol and identifier.
match identifier.span.hi.0 - start.lo.0 > 1 + identifier.name.to_string().len() as u32 {
true => Err(ParserError::space_in_annotation(span).into()),
false => Ok(Annotation { identifier, span, id: self.node_builder.next_id() }),
Expand Down
10 changes: 9 additions & 1 deletion compiler/parser/src/tokenizer/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,18 @@ pub enum Token {
Arrow,
BigArrow,
Underscore,
At,
At, // @ is not a symbol token in the ABNF grammar (see explanation about annotations below)
// There is no symbol for `)group` here (unlike the ABNF grammar),
// because we handle that differently in the lexer.

// The ABNF grammar has annotations as tokens,
// defined as @ immediately followed by an identifier.
// Here instead we regard the @ sign alone as a token (see `At` above),
// and we lex it separately from the identifier that is supposed to follow it in an annotation.
// When parsing annotations, we check that there is no whitespace or comments
// between the @ and the identifier, thus eventually complying to the ABNF grammar.
// See the parse_annotation function.

// Type keywords
Address,
Bool,
Expand Down
Loading