Merge pull request #28215 from ProvableHQ/doc-annotation-lex-parse

Clarify ABNF vs. lexer/parser annotations.
This commit is contained in:
d0cd 2024-07-10 19:15:17 -07:00 committed by GitHub
commit 14463e0098
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 2 deletions

View File

@ -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() }),

View File

@ -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,