diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-01-04 17:19:49 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-01-04 17:23:52 +0100 |
| commit | 77c06ebc24ab3a43dc2268763ff8f10963f875b4 (patch) | |
| tree | 344636fbd070f9e62946c22083cb4364958af64e /src/parse | |
| parent | 32af3095f810c25d402b8d00917051cc832d63f6 (diff) | |
None literal 🕳
Diffstat (limited to 'src/parse')
| -rw-r--r-- | src/parse/mod.rs | 1 | ||||
| -rw-r--r-- | src/parse/tests.rs | 1 | ||||
| -rw-r--r-- | src/parse/tokens.rs | 8 |
3 files changed, 9 insertions, 1 deletions
diff --git a/src/parse/mod.rs b/src/parse/mod.rs index e6cac17f..ef4ce46f 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -326,6 +326,7 @@ fn value(p: &mut Parser) -> Option<Expr> { } // Basic values. + Some(Token::None) => Expr::Lit(Lit::None), Some(Token::Bool(b)) => Expr::Lit(Lit::Bool(b)), Some(Token::Int(i)) => Expr::Lit(Lit::Int(i)), Some(Token::Float(f)) => Expr::Lit(Lit::Float(f)), diff --git a/src/parse/tests.rs b/src/parse/tests.rs index d01d09a5..8de03aff 100644 --- a/src/parse/tests.rs +++ b/src/parse/tests.rs @@ -614,6 +614,7 @@ fn test_parse_values() { t!("{name}" Block(Id("name"))); t!("{ke-bab}" Block(Id("ke-bab"))); t!("{α}" Block(Id("α"))); + t!("{none}" Block(Expr::Lit(Lit::None))); t!("{true}" Block(Bool(true))); t!("{false}" Block(Bool(false))); t!("{1.0e-4}" Block(Float(1e-4))); diff --git a/src/parse/tokens.rs b/src/parse/tokens.rs index ff7f11bd..74ec47e9 100644 --- a/src/parse/tokens.rs +++ b/src/parse/tokens.rs @@ -294,6 +294,7 @@ impl<'s> Tokens<'s> { self.s.eat_while(is_id_continue); let string = self.s.eaten_from(start); match string { + "none" => Token::None, "true" => Token::Bool(true), "false" => Token::Bool(false), _ => Token::Ident(string), @@ -377,6 +378,7 @@ mod tests { use super::*; use crate::parse::tests::check; + use Option::None; use Token::{ BlockComment as BC, Ident as Id, LeftBrace as LB, LeftBracket as L, LeftParen as LP, LineComment as LC, RightBrace as RB, RightBracket as R, @@ -679,7 +681,11 @@ mod tests { } #[test] - fn test_tokenize_bools() { + fn test_tokenize_keywords() { + // Test none. + t!(Header[" /"]: "none" => Token::None); + t!(Header[" /"]: "None" => Id("None")); + // Test valid bools. t!(Header[" /"]: "false" => Bool(false)); t!(Header[" /"]: "true" => Bool(true)); |
