_ token in parser and symbol in abnf

This commit is contained in:
gluax 2021-03-24 11:40:26 -04:00
parent c9daf4a8a9
commit fd52192d58
5 changed files with 9 additions and 8 deletions

View File

@ -645,7 +645,7 @@ symbol = "!" / "&&" / "||"
/ "[" / "]" / "[" / "]"
/ "{" / "}" / "{" / "}"
/ "," / "." / ".." / "..." / ";" / ":" / "::" / "?" / "," / "." / ".." / "..." / ";" / ":" / "::" / "?"
/ "->" / "->" / "_"
; Everything defined above, other than comments and whitespace, ; Everything defined above, other than comments and whitespace,
; is a token, as defined by the following rule. ; is a token, as defined by the following rule.

View File

@ -153,7 +153,7 @@ impl ParserContext {
} }
_ => GroupCoordinate::SignLow, _ => GroupCoordinate::SignLow,
}, },
Token::Ident(x) if x == "_" => GroupCoordinate::Inferred, Token::Underscore => GroupCoordinate::Inferred,
Token::Int(value) => GroupCoordinate::Number(value.clone(), token.span.clone()), Token::Int(value) => GroupCoordinate::Number(value.clone(), token.span.clone()),
_ => return None, _ => return None,
}) })

View File

@ -43,14 +43,11 @@ fn eat_identifier(input: &[u8]) -> Option<(&[u8], &[u8])> {
if input.is_empty() { if input.is_empty() {
return None; return None;
} }
if !input[0].is_ascii_alphabetic() && input[0] != b'_' { if !input[0].is_ascii_alphabetic() {
// Allow _ at start. // Allow _ at start.
return None; return None;
} }
if input.len() == 1 && input[0] == b'_' {
// But only if it the length of the identifer is 1.
return None;
}
let mut i = 1usize; let mut i = 1usize;
while i < input.len() { while i < input.len() {
if !input[i].is_ascii_alphanumeric() && input[i] != b'_' { if !input[i].is_ascii_alphanumeric() && input[i] != b'_' {
@ -283,6 +280,7 @@ impl Token {
} }
return (&input[1..], Some(Token::Assign)); return (&input[1..], Some(Token::Assign));
} }
b'_' => return (&input[1..], Some(Token::Underscore)),
b'@' => return (&input[1..], Some(Token::At)), b'@' => return (&input[1..], Some(Token::At)),
b'[' => return (&input[1..], Some(Token::LeftSquare)), b'[' => return (&input[1..], Some(Token::LeftSquare)),
b']' => return (&input[1..], Some(Token::RightSquare)), b']' => return (&input[1..], Some(Token::RightSquare)),

View File

@ -172,6 +172,7 @@ mod tests {
- -
-= -=
-> ->
_
. .
.. ..
... ...
@ -221,7 +222,7 @@ mod tests {
} }
assert_eq!( assert_eq!(
output, output,
r#""test" "test{}test" "test{}" "{}test" "test{" "test}" "test{test" "test}test" "te{{}}" aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8 test_ident 12345 address as bool circuit const else false field for function group i128 i64 i32 i16 i8 if import in input let mut return static string test true u128 u64 u32 u16 u8 self Self console ! != && ( ) * ** **= *= + += , - -= -> . .. ... / /= : :: ; < <= = == > >= @ [ ] { { } } || & &= | |= ^ ^= ~ << <<= >> >>= >>> >>>= % %= ||= &&= ? // test r#""test" "test{}test" "test{}" "{}test" "test{" "test}" "test{test" "test}test" "te{{}}" aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8 test_ident 12345 address as bool circuit const else false field for function group i128 i64 i32 i16 i8 if import in input let mut return static string test true u128 u64 u32 u16 u8 self Self console ! != && ( ) * ** **= *= + += , - -= -> _ . .. ... / /= : :: ; < <= = == > >= @ [ ] { { } } || & &= | |= ^ ^= ~ << <<= >> >>= >>> >>>= % %= ||= &&= ? // test
/* test */ // /* test */ //
"# "#
); );

View File

@ -85,6 +85,7 @@ pub enum Token {
DoubleColon, DoubleColon,
Question, Question,
Arrow, Arrow,
Underscore,
// Syntactic Grammr // Syntactic Grammr
// Types // Types
@ -298,6 +299,7 @@ impl fmt::Display for Token {
OrEq => write!(f, "||="), OrEq => write!(f, "||="),
AndEq => write!(f, "&&="), AndEq => write!(f, "&&="),
Question => write!(f, "?"), Question => write!(f, "?"),
Underscore => write!(f, "_"),
} }
} }
} }