Skip to content

Commit

Permalink
Merge pull request #28215 from ProvableHQ/doc-annotation-lex-parse
Browse files Browse the repository at this point in the history
Clarify ABNF vs. lexer/parser annotations.
  • Loading branch information
d0cd authored Jul 11, 2024
2 parents fcdedc3 + 9ce7dab commit 14463e0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
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

0 comments on commit 14463e0

Please sign in to comment.