idents in annotation name and for arguements, no white space between @ and annotation-name

This commit is contained in:
gluax 2021-03-24 12:08:07 -04:00
parent fd52192d58
commit 600cf120f9
3 changed files with 17 additions and 5 deletions

View File

@ -509,9 +509,7 @@ formatted-string = double-quote
; Two names are currently supported.
; An argument is a sequence of one or more letters, digits, and underscores.
annotation-name = %s"@context" / %s"@test"
annotation-argument = 1*( letter / digit / "_" )
annotation-name = "@" identifier
; A natural (number) is a sequence of one or more digits.
; Note that we allow leading zeros, e.g. '007'.
@ -656,7 +654,6 @@ token = keyword
/ package-name
/ format-string
/ annotation-name
/ annotation-argument
/ symbol
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -1012,7 +1009,7 @@ print-call = print-function print-arguments
; Note that no parentheses are used if there are no arguments.
annotation = annotation-name
[ "(" annotation-argument *( "," annotation-argument ) ")" ]
[ "(" identifier *( "," identifier ) ")" ]
; A function declaration defines a function.
; This could be called 'function-definition' instead,

View File

@ -57,6 +57,13 @@ impl SyntaxError {
Self::new_from_span("unexpected EOF".to_string(), span)
}
pub fn unexpected_whitespace(left: &str, right: &str, span: &Span) -> Self {
Self::new_from_span(
format!("Unexpected white space between terms {} and {}", left, right),
span,
)
}
pub fn unexpected(got: &Token, expected: &[Token], span: &Span) -> Self {
Self::new_from_span(
format!(

View File

@ -88,6 +88,14 @@ impl ParserContext {
&name.span,
)));
}
if start.col_stop != name.span.col_start {
let mut error_span = &start + &name.span;
error_span.col_start = start.col_stop - 1;
error_span.col_stop = name.span.col_start - 1;
return Err(SyntaxError::unexpected_whitespace("@", &name.name, &error_span));
}
let end_span;
let arguments = if self.eat(Token::LeftParen).is_some() {
let mut args = vec![];