Remove source-level `void` keyword
41b8d492b9772d325bb283d0bf752e13e8638f05b6d6bad97c91b0b58df4f08c
1 parent
f08c3877
lib/std/lang/parser.rad
+0 -4
| 2068 | 2068 | } |
|
| 2069 | 2069 | case scanner::TokenKind::Bool => { |
|
| 2070 | 2070 | advance(p); |
|
| 2071 | 2071 | return node(p, ast::NodeValue::TypeSig(ast::TypeSig::Bool)); |
|
| 2072 | 2072 | } |
|
| 2073 | - | case scanner::TokenKind::Void => { |
|
| 2074 | - | advance(p); |
|
| 2075 | - | return node(p, ast::NodeValue::TypeSig(ast::TypeSig::Void)); |
|
| 2076 | - | } |
|
| 2077 | 2073 | case scanner::TokenKind::Opaque => { |
|
| 2078 | 2074 | advance(p); |
|
| 2079 | 2075 | return node(p, ast::NodeValue::TypeSig(ast::TypeSig::Opaque)); |
|
| 2080 | 2076 | } |
|
| 2081 | 2077 | case scanner::TokenKind::Fn => { |
lib/std/lang/parser/tests.rad
+8 -0
| 1105 | 1105 | let body = decl.body else throw testing::TestError::Failed; |
|
| 1106 | 1106 | let case ast::NodeValue::Block(_) = body.value |
|
| 1107 | 1107 | else throw testing::TestError::Failed; |
|
| 1108 | 1108 | } |
|
| 1109 | 1109 | ||
| 1110 | + | /// Test scanning source-level `void` produces an identifier, not a type keyword. |
|
| 1111 | + | @test fn testParseTypeVoidRejected() throws (testing::TestError) { |
|
| 1112 | + | let mut arena = ast::nodeArena(&mut ARENA_STORAGE[..]); |
|
| 1113 | + | let mut parser = super::mkParser(scanner::SourceLoc::String, "void", &mut arena, &mut STRING_POOL); |
|
| 1114 | + | super::advance(&mut parser); |
|
| 1115 | + | try testing::expect(super::check(&parser, scanner::TokenKind::Ident)); |
|
| 1116 | + | } |
|
| 1117 | + | ||
| 1110 | 1118 | /// Test parsing a function declaration with attributes. |
|
| 1111 | 1119 | @test fn testParseFnDeclAttributes() throws (testing::TestError) { |
|
| 1112 | 1120 | let node = try! parseStmtStr("pub extern fn run();"); |
|
| 1113 | 1121 | let case ast::NodeValue::FnDecl(decl) = node.value |
|
| 1114 | 1122 | else throw testing::TestError::Failed; |
lib/std/lang/scanner.rad
+2 -3
| 102 | 102 | // Trait-related tokens. |
|
| 103 | 103 | Trait, Instance, |
|
| 104 | 104 | ||
| 105 | 105 | // Type-related tokens. |
|
| 106 | 106 | I8, I16, I32, I64, U8, U16, U32, U64, |
|
| 107 | - | Void, Opaque, Fn, Bool, Union, Record, As |
|
| 107 | + | Opaque, Fn, Bool, Union, Record, As |
|
| 108 | 108 | } |
|
| 109 | 109 | ||
| 110 | 110 | /// A reserved keyword. |
|
| 111 | 111 | record Keyword { |
|
| 112 | 112 | /// Keyword string. |
| 114 | 114 | /// Corresponding token. |
|
| 115 | 115 | tok: TokenKind, |
|
| 116 | 116 | } |
|
| 117 | 117 | ||
| 118 | 118 | /// Sorted keyword table for binary search. |
|
| 119 | - | const KEYWORDS: [Keyword; 52] = [ |
|
| 119 | + | const KEYWORDS: [Keyword; 51] = [ |
|
| 120 | 120 | { name: "align", tok: TokenKind::Align }, |
|
| 121 | 121 | { name: "and", tok: TokenKind::And }, |
|
| 122 | 122 | { name: "as", tok: TokenKind::As }, |
|
| 123 | 123 | { name: "assert", tok: TokenKind::Assert }, |
|
| 124 | 124 | { name: "bool", tok: TokenKind::Bool }, |
| 165 | 165 | { name: "u64", tok: TokenKind::U64 }, |
|
| 166 | 166 | { name: "u8", tok: TokenKind::U8 }, |
|
| 167 | 167 | { name: "undefined", tok: TokenKind::Undefined }, |
|
| 168 | 168 | { name: "union", tok: TokenKind::Union }, |
|
| 169 | 169 | { name: "use", tok: TokenKind::Use }, |
|
| 170 | - | { name: "void", tok: TokenKind::Void }, |
|
| 171 | 170 | { name: "while", tok: TokenKind::While }, |
|
| 172 | 171 | ]; |
|
| 173 | 172 | ||
| 174 | 173 | /// Describes where source code originated from. |
|
| 175 | 174 | pub union SourceLoc { |
lib/std/lang/scanner/tests.rad
+8 -0
| 245 | 245 | let tok4: super::Token = super::next(&mut s); |
|
| 246 | 246 | try testing::expect(tok4.kind == super::TokenKind::Static); |
|
| 247 | 247 | try testing::expect(tok4.source.len == 6); |
|
| 248 | 248 | } |
|
| 249 | 249 | ||
| 250 | + | @test fn testScanVoidAsIdent() throws (testing::TestError) { |
|
| 251 | + | let mut s = testScanner("void"); |
|
| 252 | + | let tok: super::Token = super::next(&mut s); |
|
| 253 | + | try testing::expect(tok.kind == super::TokenKind::Ident); |
|
| 254 | + | try testing::expect(tok.source.len == 4); |
|
| 255 | + | } |
|
| 256 | + | ||
| 257 | + | ||
| 250 | 258 | @test fn testScanWhitespaceAndComments() throws (testing::TestError) { |
|
| 251 | 259 | let mut s = testScanner( |
|
| 252 | 260 | " \t\n // This is a comment..\n 42" |
|
| 253 | 261 | ); |
|
| 254 | 262 | let tok: super::Token = super::next(&mut s); |