| ... | @@ -17,15 +17,15 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -17,15 +17,15 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 17 | defer stack.deinit(); | 17 | defer stack.deinit(); |
| 18 | | 18 | |
| 19 | const arena = &tree_arena.allocator; | 19 | const arena = &tree_arena.allocator; |
| 20 | const root_node = try arena.construct(ast.Node.Root { | 20 | const root_node = try arena.construct(ast.Node.Root{ |
| 21 | .base = ast.Node { .id = ast.Node.Id.Root }, | 21 | .base = ast.Node{ .id = ast.Node.Id.Root }, |
| 22 | .decls = ast.Node.Root.DeclList.init(arena), | 22 | .decls = ast.Node.Root.DeclList.init(arena), |
| 23 | .doc_comments = null, | 23 | .doc_comments = null, |
| 24 | // initialized when we get the eof token | 24 | // initialized when we get the eof token |
| 25 | .eof_token = undefined, | 25 | .eof_token = undefined, |
| 26 | }); | 26 | }); |
| 27 | | 27 | |
| 28 | var tree = ast.Tree { | 28 | var tree = ast.Tree{ |
| 29 | .source = source, | 29 | .source = source, |
| 30 | .root_node = root_node, | 30 | .root_node = root_node, |
| 31 | .arena_allocator = tree_arena, | 31 | .arena_allocator = tree_arena, |
| ... | @@ -36,9 +36,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -36,9 +36,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 36 | var tokenizer = Tokenizer.init(tree.source); | 36 | var tokenizer = Tokenizer.init(tree.source); |
| 37 | while (true) { | 37 | while (true) { |
| 38 | const token_ptr = try tree.tokens.addOne(); | 38 | const token_ptr = try tree.tokens.addOne(); |
| 39 | *token_ptr = tokenizer.next(); | 39 | token_ptr.* = tokenizer.next(); |
| 40 | if (token_ptr.id == Token.Id.Eof) | 40 | if (token_ptr.id == Token.Id.Eof) break; |
| 41 | break; | | |
| 42 | } | 41 | } |
| 43 | var tok_it = tree.tokens.iterator(0); | 42 | var tok_it = tree.tokens.iterator(0); |
| 44 | | 43 | |
| ... | @@ -63,33 +62,27 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -63,33 +62,27 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 63 | Token.Id.Keyword_test => { | 62 | Token.Id.Keyword_test => { |
| 64 | stack.append(State.TopLevel) catch unreachable; | 63 | stack.append(State.TopLevel) catch unreachable; |
| 65 | | 64 | |
| 66 | const block = try arena.construct(ast.Node.Block { | 65 | const block = try arena.construct(ast.Node.Block{ |
| 67 | .base = ast.Node { | 66 | .base = ast.Node{ .id = ast.Node.Id.Block }, |
| 68 | .id = ast.Node.Id.Block, | | |
| 69 | }, | | |
| 70 | .label = null, | 67 | .label = null, |
| 71 | .lbrace = undefined, | 68 | .lbrace = undefined, |
| 72 | .statements = ast.Node.Block.StatementList.init(arena), | 69 | .statements = ast.Node.Block.StatementList.init(arena), |
| 73 | .rbrace = undefined, | 70 | .rbrace = undefined, |
| 74 | }); | 71 | }); |
| 75 | const test_node = try arena.construct(ast.Node.TestDecl { | 72 | const test_node = try arena.construct(ast.Node.TestDecl{ |
| 76 | .base = ast.Node { | 73 | .base = ast.Node{ .id = ast.Node.Id.TestDecl }, |
| 77 | .id = ast.Node.Id.TestDecl, | | |
| 78 | }, | | |
| 79 | .doc_comments = comments, | 74 | .doc_comments = comments, |
| 80 | .test_token = token_index, | 75 | .test_token = token_index, |
| 81 | .name = undefined, | 76 | .name = undefined, |
| 82 | .body_node = &block.base, | 77 | .body_node = &block.base, |
| 83 | }); | 78 | }); |
| 84 | try root_node.decls.push(&test_node.base); | 79 | try root_node.decls.push(&test_node.base); |
| 85 | try stack.append(State { .Block = block }); | 80 | try stack.append(State{ .Block = block }); |
| 86 | try stack.append(State { | 81 | try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{ |
| 87 | .ExpectTokenSave = ExpectTokenSave { | 82 | .id = Token.Id.LBrace, |
| 88 | .id = Token.Id.LBrace, | 83 | .ptr = &block.rbrace, |
| 89 | .ptr = &block.rbrace, | 84 | } }); |
| 90 | } | 85 | try stack.append(State{ .StringLiteral = OptionalCtx{ .Required = &test_node.name } }); |
| 91 | }); | | |
| 92 | try stack.append(State { .StringLiteral = OptionalCtx { .Required = &test_node.name } }); | | |
| 93 | continue; | 86 | continue; |
| 94 | }, | 87 | }, |
| 95 | Token.Id.Eof => { | 88 | Token.Id.Eof => { |
| ... | @@ -99,29 +92,25 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -99,29 +92,25 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 99 | }, | 92 | }, |
| 100 | Token.Id.Keyword_pub => { | 93 | Token.Id.Keyword_pub => { |
| 101 | stack.append(State.TopLevel) catch unreachable; | 94 | stack.append(State.TopLevel) catch unreachable; |
| 102 | try stack.append(State { | 95 | try stack.append(State{ .TopLevelExtern = TopLevelDeclCtx{ |
| 103 | .TopLevelExtern = TopLevelDeclCtx { | 96 | .decls = &root_node.decls, |
| 104 | .decls = &root_node.decls, | 97 | .visib_token = token_index, |
| 105 | .visib_token = token_index, | 98 | .extern_export_inline_token = null, |
| 106 | .extern_export_inline_token = null, | 99 | .lib_name = null, |
| 107 | .lib_name = null, | 100 | .comments = comments, |
| 108 | .comments = comments, | 101 | } }); |
| 109 | } | | |
| 110 | }); | | |
| 111 | continue; | 102 | continue; |
| 112 | }, | 103 | }, |
| 113 | Token.Id.Keyword_comptime => { | 104 | Token.Id.Keyword_comptime => { |
| 114 | const block = try arena.construct(ast.Node.Block { | 105 | const block = try arena.construct(ast.Node.Block{ |
| 115 | .base = ast.Node {.id = ast.Node.Id.Block }, | 106 | .base = ast.Node{ .id = ast.Node.Id.Block }, |
| 116 | .label = null, | 107 | .label = null, |
| 117 | .lbrace = undefined, | 108 | .lbrace = undefined, |
| 118 | .statements = ast.Node.Block.StatementList.init(arena), | 109 | .statements = ast.Node.Block.StatementList.init(arena), |
| 119 | .rbrace = undefined, | 110 | .rbrace = undefined, |
| 120 | }); | 111 | }); |
| 121 | const node = try arena.construct(ast.Node.Comptime { | 112 | const node = try arena.construct(ast.Node.Comptime{ |
| 122 | .base = ast.Node { | 113 | .base = ast.Node{ .id = ast.Node.Id.Comptime }, |
| 123 | .id = ast.Node.Id.Comptime, | | |
| 124 | }, | | |
| 125 | .comptime_token = token_index, | 114 | .comptime_token = token_index, |
| 126 | .expr = &block.base, | 115 | .expr = &block.base, |
| 127 | .doc_comments = comments, | 116 | .doc_comments = comments, |
| ... | @@ -129,27 +118,23 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -129,27 +118,23 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 129 | try root_node.decls.push(&node.base); | 118 | try root_node.decls.push(&node.base); |
| 130 | | 119 | |
| 131 | stack.append(State.TopLevel) catch unreachable; | 120 | stack.append(State.TopLevel) catch unreachable; |
| 132 | try stack.append(State { .Block = block }); | 121 | try stack.append(State{ .Block = block }); |
| 133 | try stack.append(State { | 122 | try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{ |
| 134 | .ExpectTokenSave = ExpectTokenSave { | 123 | .id = Token.Id.LBrace, |
| 135 | .id = Token.Id.LBrace, | 124 | .ptr = &block.rbrace, |
| 136 | .ptr = &block.rbrace, | 125 | } }); |
| 137 | } | | |
| 138 | }); | | |
| 139 | continue; | 126 | continue; |
| 140 | }, | 127 | }, |
| 141 | else => { | 128 | else => { |
| 142 | putBackToken(&tok_it, &tree); | 129 | putBackToken(&tok_it, &tree); |
| 143 | stack.append(State.TopLevel) catch unreachable; | 130 | stack.append(State.TopLevel) catch unreachable; |
| 144 | try stack.append(State { | 131 | try stack.append(State{ .TopLevelExtern = TopLevelDeclCtx{ |
| 145 | .TopLevelExtern = TopLevelDeclCtx { | 132 | .decls = &root_node.decls, |
| 146 | .decls = &root_node.decls, | 133 | .visib_token = null, |
| 147 | .visib_token = null, | 134 | .extern_export_inline_token = null, |
| 148 | .extern_export_inline_token = null, | 135 | .lib_name = null, |
| 149 | .lib_name = null, | 136 | .comments = comments, |
| 150 | .comments = comments, | 137 | } }); |
| 151 | } | | |
| 152 | }); | | |
| 153 | continue; | 138 | continue; |
| 154 | }, | 139 | }, |
| 155 | } | 140 | } |
| ... | @@ -159,41 +144,38 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -159,41 +144,38 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 159 | const token_index = token.index; | 144 | const token_index = token.index; |
| 160 | const token_ptr = token.ptr; | 145 | const token_ptr = token.ptr; |
| 161 | switch (token_ptr.id) { | 146 | switch (token_ptr.id) { |
| 162 | Token.Id.Keyword_export, Token.Id.Keyword_inline => { | 147 | Token.Id.Keyword_export, |
| 163 | stack.append(State { | 148 | Token.Id.Keyword_inline => { |
| 164 | .TopLevelDecl = TopLevelDeclCtx { | 149 | stack.append(State{ .TopLevelDecl = TopLevelDeclCtx{ |
| 165 | .decls = ctx.decls, | 150 | .decls = ctx.decls, |
| 166 | .visib_token = ctx.visib_token, | 151 | .visib_token = ctx.visib_token, |
| 167 | .extern_export_inline_token = AnnotatedToken { | 152 | .extern_export_inline_token = AnnotatedToken{ |
| 168 | .index = token_index, | 153 | .index = token_index, |
| 169 | .ptr = token_ptr, | 154 | .ptr = token_ptr, |
| 170 | }, | | |
| 171 | .lib_name = null, | | |
| 172 | .comments = ctx.comments, | | |
| 173 | }, | 155 | }, |
| 174 | }) catch unreachable; | 156 | .lib_name = null, |
| | 157 | .comments = ctx.comments, |
| | 158 | } }) catch unreachable; |
| 175 | continue; | 159 | continue; |
| 176 | }, | 160 | }, |
| 177 | Token.Id.Keyword_extern => { | 161 | Token.Id.Keyword_extern => { |
| 178 | stack.append(State { | 162 | stack.append(State{ .TopLevelLibname = TopLevelDeclCtx{ |
| 179 | .TopLevelLibname = TopLevelDeclCtx { | 163 | .decls = ctx.decls, |
| 180 | .decls = ctx.decls, | 164 | .visib_token = ctx.visib_token, |
| 181 | .visib_token = ctx.visib_token, | 165 | .extern_export_inline_token = AnnotatedToken{ |
| 182 | .extern_export_inline_token = AnnotatedToken { | 166 | .index = token_index, |
| 183 | .index = token_index, | 167 | .ptr = token_ptr, |
| 184 | .ptr = token_ptr, | | |
| 185 | }, | | |
| 186 | .lib_name = null, | | |
| 187 | .comments = ctx.comments, | | |
| 188 | }, | 168 | }, |
| 189 | }) catch unreachable; | 169 | .lib_name = null, |
| | 170 | .comments = ctx.comments, |
| | 171 | } }) catch unreachable; |
| 190 | continue; | 172 | continue; |
| 191 | }, | 173 | }, |
| 192 | else => { | 174 | else => { |
| 193 | putBackToken(&tok_it, &tree); | 175 | putBackToken(&tok_it, &tree); |
| 194 | stack.append(State { .TopLevelDecl = ctx }) catch unreachable; | 176 | stack.append(State{ .TopLevelDecl = ctx }) catch unreachable; |
| 195 | continue; | 177 | continue; |
| 196 | } | 178 | }, |
| 197 | } | 179 | } |
| 198 | }, | 180 | }, |
| 199 | State.TopLevelLibname => |ctx| { | 181 | State.TopLevelLibname => |ctx| { |
| ... | @@ -207,15 +189,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -207,15 +189,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 207 | }; | 189 | }; |
| 208 | }; | 190 | }; |
| 209 | | 191 | |
| 210 | stack.append(State { | 192 | stack.append(State{ .TopLevelDecl = TopLevelDeclCtx{ |
| 211 | .TopLevelDecl = TopLevelDeclCtx { | 193 | .decls = ctx.decls, |
| 212 | .decls = ctx.decls, | 194 | .visib_token = ctx.visib_token, |
| 213 | .visib_token = ctx.visib_token, | 195 | .extern_export_inline_token = ctx.extern_export_inline_token, |
| 214 | .extern_export_inline_token = ctx.extern_export_inline_token, | 196 | .lib_name = lib_name, |
| 215 | .lib_name = lib_name, | 197 | .comments = ctx.comments, |
| 216 | .comments = ctx.comments, | 198 | } }) catch unreachable; |
| 217 | }, | | |
| 218 | }) catch unreachable; | | |
| 219 | continue; | 199 | continue; |
| 220 | }, | 200 | }, |
| 221 | State.TopLevelDecl => |ctx| { | 201 | State.TopLevelDecl => |ctx| { |
| ... | @@ -225,14 +205,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -225,14 +205,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 225 | switch (token_ptr.id) { | 205 | switch (token_ptr.id) { |
| 226 | Token.Id.Keyword_use => { | 206 | Token.Id.Keyword_use => { |
| 227 | if (ctx.extern_export_inline_token) |annotated_token| { | 207 | if (ctx.extern_export_inline_token) |annotated_token| { |
| 228 | *(try tree.errors.addOne()) = Error { | 208 | ((try tree.errors.addOne())).* = Error{ .InvalidToken = Error.InvalidToken{ .token = annotated_token.index } }; |
| 229 | .InvalidToken = Error.InvalidToken { .token = annotated_token.index }, | | |
| 230 | }; | | |
| 231 | return tree; | 209 | return tree; |
| 232 | } | 210 | } |
| 233 | | 211 | |
| 234 | const node = try arena.construct(ast.Node.Use { | 212 | const node = try arena.construct(ast.Node.Use{ |
| 235 | .base = ast.Node {.id = ast.Node.Id.Use }, | 213 | .base = ast.Node{ .id = ast.Node.Id.Use }, |
| 236 | .visib_token = ctx.visib_token, | 214 | .visib_token = ctx.visib_token, |
| 237 | .expr = undefined, | 215 | .expr = undefined, |
| 238 | .semicolon_token = undefined, | 216 | .semicolon_token = undefined, |
| ... | @@ -240,44 +218,39 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -240,44 +218,39 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 240 | }); | 218 | }); |
| 241 | try ctx.decls.push(&node.base); | 219 | try ctx.decls.push(&node.base); |
| 242 | | 220 | |
| 243 | stack.append(State { | 221 | stack.append(State{ .ExpectTokenSave = ExpectTokenSave{ |
| 244 | .ExpectTokenSave = ExpectTokenSave { | 222 | .id = Token.Id.Semicolon, |
| 245 | .id = Token.Id.Semicolon, | 223 | .ptr = &node.semicolon_token, |
| 246 | .ptr = &node.semicolon_token, | 224 | } }) catch unreachable; |
| 247 | } | 225 | try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.expr } }); |
| 248 | }) catch unreachable; | | |
| 249 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.expr } }); | | |
| 250 | continue; | 226 | continue; |
| 251 | }, | 227 | }, |
| 252 | Token.Id.Keyword_var, Token.Id.Keyword_const => { | 228 | Token.Id.Keyword_var, |
| | 229 | Token.Id.Keyword_const => { |
| 253 | if (ctx.extern_export_inline_token) |annotated_token| { | 230 | if (ctx.extern_export_inline_token) |annotated_token| { |
| 254 | if (annotated_token.ptr.id == Token.Id.Keyword_inline) { | 231 | if (annotated_token.ptr.id == Token.Id.Keyword_inline) { |
| 255 | *(try tree.errors.addOne()) = Error { | 232 | ((try tree.errors.addOne())).* = Error{ .InvalidToken = Error.InvalidToken{ .token = annotated_token.index } }; |
| 256 | .InvalidToken = Error.InvalidToken { .token = annotated_token.index }, | | |
| 257 | }; | | |
| 258 | return tree; | 233 | return tree; |
| 259 | } | 234 | } |
| 260 | } | 235 | } |
| 261 | | 236 | |
| 262 | try stack.append(State { | 237 | try stack.append(State{ .VarDecl = VarDeclCtx{ |
| 263 | .VarDecl = VarDeclCtx { | 238 | .comments = ctx.comments, |
| 264 | .comments = ctx.comments, | 239 | .visib_token = ctx.visib_token, |
| 265 | .visib_token = ctx.visib_token, | 240 | .lib_name = ctx.lib_name, |
| 266 | .lib_name = ctx.lib_name, | 241 | .comptime_token = null, |
| 267 | .comptime_token = null, | 242 | .extern_export_token = if (ctx.extern_export_inline_token) |at| at.index else null, |
| 268 | .extern_export_token = if (ctx.extern_export_inline_token) |at| at.index else null, | 243 | .mut_token = token_index, |
| 269 | .mut_token = token_index, | 244 | .list = ctx.decls, |
| 270 | .list = ctx.decls | 245 | } }); |
| 271 | } | 246 | continue; |
| 272 | }); | 247 | }, |
| 273 | continue; | 248 | Token.Id.Keyword_fn, |
| 274 | }, | 249 | Token.Id.Keyword_nakedcc, |
| 275 | Token.Id.Keyword_fn, Token.Id.Keyword_nakedcc, | 250 | Token.Id.Keyword_stdcallcc, |
| 276 | Token.Id.Keyword_stdcallcc, Token.Id.Keyword_async => { | 251 | Token.Id.Keyword_async => { |
| 277 | const fn_proto = try arena.construct(ast.Node.FnProto { | 252 | const fn_proto = try arena.construct(ast.Node.FnProto{ |
| 278 | .base = ast.Node { | 253 | .base = ast.Node{ .id = ast.Node.Id.FnProto }, |
| 279 | .id = ast.Node.Id.FnProto, | | |
| 280 | }, | | |
| 281 | .doc_comments = ctx.comments, | 254 | .doc_comments = ctx.comments, |
| 282 | .visib_token = ctx.visib_token, | 255 | .visib_token = ctx.visib_token, |
| 283 | .name_token = null, | 256 | .name_token = null, |
| ... | @@ -293,36 +266,33 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -293,36 +266,33 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 293 | .align_expr = null, | 266 | .align_expr = null, |
| 294 | }); | 267 | }); |
| 295 | try ctx.decls.push(&fn_proto.base); | 268 | try ctx.decls.push(&fn_proto.base); |
| 296 | stack.append(State { .FnDef = fn_proto }) catch unreachable; | 269 | stack.append(State{ .FnDef = fn_proto }) catch unreachable; |
| 297 | try stack.append(State { .FnProto = fn_proto }); | 270 | try stack.append(State{ .FnProto = fn_proto }); |
| 298 | | 271 | |
| 299 | switch (token_ptr.id) { | 272 | switch (token_ptr.id) { |
| 300 | Token.Id.Keyword_nakedcc, Token.Id.Keyword_stdcallcc => { | 273 | Token.Id.Keyword_nakedcc, |
| | 274 | Token.Id.Keyword_stdcallcc => { |
| 301 | fn_proto.cc_token = token_index; | 275 | fn_proto.cc_token = token_index; |
| 302 | try stack.append(State { | 276 | try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{ |
| 303 | .ExpectTokenSave = ExpectTokenSave { | 277 | .id = Token.Id.Keyword_fn, |
| 304 | .id = Token.Id.Keyword_fn, | 278 | .ptr = &fn_proto.fn_token, |
| 305 | .ptr = &fn_proto.fn_token, | 279 | } }); |
| 306 | } | | |
| 307 | }); | | |
| 308 | continue; | 280 | continue; |
| 309 | }, | 281 | }, |
| 310 | Token.Id.Keyword_async => { | 282 | Token.Id.Keyword_async => { |
| 311 | const async_node = try arena.construct(ast.Node.AsyncAttribute { | 283 | const async_node = try arena.construct(ast.Node.AsyncAttribute{ |
| 312 | .base = ast.Node {.id = ast.Node.Id.AsyncAttribute }, | 284 | .base = ast.Node{ .id = ast.Node.Id.AsyncAttribute }, |
| 313 | .async_token = token_index, | 285 | .async_token = token_index, |
| 314 | .allocator_type = null, | 286 | .allocator_type = null, |
| 315 | .rangle_bracket = null, | 287 | .rangle_bracket = null, |
| 316 | }); | 288 | }); |
| 317 | fn_proto.async_attr = async_node; | 289 | fn_proto.async_attr = async_node; |
| 318 | | 290 | |
| 319 | try stack.append(State { | 291 | try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{ |
| 320 | .ExpectTokenSave = ExpectTokenSave { | 292 | .id = Token.Id.Keyword_fn, |
| 321 | .id = Token.Id.Keyword_fn, | 293 | .ptr = &fn_proto.fn_token, |
| 322 | .ptr = &fn_proto.fn_token, | 294 | } }); |
| 323 | } | 295 | try stack.append(State{ .AsyncAllocator = async_node }); |
| 324 | }); | | |
| 325 | try stack.append(State { .AsyncAllocator = async_node }); | | |
| 326 | continue; | 296 | continue; |
| 327 | }, | 297 | }, |
| 328 | Token.Id.Keyword_fn => { | 298 | Token.Id.Keyword_fn => { |
| ... | @@ -333,9 +303,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -333,9 +303,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 333 | } | 303 | } |
| 334 | }, | 304 | }, |
| 335 | else => { | 305 | else => { |
| 336 | *(try tree.errors.addOne()) = Error { | 306 | ((try tree.errors.addOne())).* = Error{ .ExpectedVarDeclOrFn = Error.ExpectedVarDeclOrFn{ .token = token_index } }; |
| 337 | .ExpectedVarDeclOrFn = Error.ExpectedVarDeclOrFn { .token = token_index }, | | |
| 338 | }; | | |
| 339 | return tree; | 307 | return tree; |
| 340 | }, | 308 | }, |
| 341 | } | 309 | } |
| ... | @@ -343,34 +311,30 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -343,34 +311,30 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 343 | State.TopLevelExternOrField => |ctx| { | 311 | State.TopLevelExternOrField => |ctx| { |
| 344 | if (eatToken(&tok_it, &tree, Token.Id.Identifier)) |identifier| { | 312 | if (eatToken(&tok_it, &tree, Token.Id.Identifier)) |identifier| { |
| 345 | std.debug.assert(ctx.container_decl.kind == ast.Node.ContainerDecl.Kind.Struct); | 313 | std.debug.assert(ctx.container_decl.kind == ast.Node.ContainerDecl.Kind.Struct); |
| 346 | const node = try arena.construct(ast.Node.StructField { | 314 | const node = try arena.construct(ast.Node.StructField{ |
| 347 | .base = ast.Node { | 315 | .base = ast.Node{ .id = ast.Node.Id.StructField }, |
| 348 | .id = ast.Node.Id.StructField, | | |
| 349 | }, | | |
| 350 | .doc_comments = ctx.comments, | 316 | .doc_comments = ctx.comments, |
| 351 | .visib_token = ctx.visib_token, | 317 | .visib_token = ctx.visib_token, |
| 352 | .name_token = identifier, | 318 | .name_token = identifier, |
| 353 | .type_expr = undefined, | 319 | .type_expr = undefined, |
| 354 | }); | 320 | }); |
| 355 | const node_ptr = try ctx.container_decl.fields_and_decls.addOne(); | 321 | const node_ptr = try ctx.container_decl.fields_and_decls.addOne(); |
| 356 | *node_ptr = &node.base; | 322 | node_ptr.* = &node.base; |
| 357 | | 323 | |
| 358 | stack.append(State { .FieldListCommaOrEnd = ctx.container_decl }) catch unreachable; | 324 | stack.append(State{ .FieldListCommaOrEnd = ctx.container_decl }) catch unreachable; |
| 359 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.type_expr } }); | 325 | try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.type_expr } }); |
| 360 | try stack.append(State { .ExpectToken = Token.Id.Colon }); | 326 | try stack.append(State{ .ExpectToken = Token.Id.Colon }); |
| 361 | continue; | 327 | continue; |
| 362 | } | 328 | } |
| 363 | | 329 | |
| 364 | stack.append(State{ .ContainerDecl = ctx.container_decl }) catch unreachable; | 330 | stack.append(State{ .ContainerDecl = ctx.container_decl }) catch unreachable; |
| 365 | try stack.append(State { | 331 | try stack.append(State{ .TopLevelExtern = TopLevelDeclCtx{ |
| 366 | .TopLevelExtern = TopLevelDeclCtx { | 332 | .decls = &ctx.container_decl.fields_and_decls, |
| 367 | .decls = &ctx.container_decl.fields_and_decls, | 333 | .visib_token = ctx.visib_token, |
| 368 | .visib_token = ctx.visib_token, | 334 | .extern_export_inline_token = null, |
| 369 | .extern_export_inline_token = null, | 335 | .lib_name = null, |
| 370 | .lib_name = null, | 336 | .comments = ctx.comments, |
| 371 | .comments = ctx.comments, | 337 | } }); |
| 372 | } | | |
| 373 | }); | | |
| 374 | continue; | 338 | continue; |
| 375 | }, | 339 | }, |
| 376 | | 340 | |
| ... | @@ -382,7 +346,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -382,7 +346,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 382 | putBackToken(&tok_it, &tree); | 346 | putBackToken(&tok_it, &tree); |
| 383 | continue; | 347 | continue; |
| 384 | } | 348 | } |
| 385 | stack.append(State { .Expression = ctx }) catch unreachable; | 349 | stack.append(State{ .Expression = ctx }) catch unreachable; |
| 386 | continue; | 350 | continue; |
| 387 | }, | 351 | }, |
| 388 | | 352 | |
| ... | @@ -390,8 +354,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -390,8 +354,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 390 | const token = nextToken(&tok_it, &tree); | 354 | const token = nextToken(&tok_it, &tree); |
| 391 | const token_index = token.index; | 355 | const token_index = token.index; |
| 392 | const token_ptr = token.ptr; | 356 | const token_ptr = token.ptr; |
| 393 | const node = try arena.construct(ast.Node.ContainerDecl { | 357 | const node = try arena.construct(ast.Node.ContainerDecl{ |
| 394 | .base = ast.Node {.id = ast.Node.Id.ContainerDecl }, | 358 | .base = ast.Node{ .id = ast.Node.Id.ContainerDecl }, |
| 395 | .ltoken = ctx.ltoken, | 359 | .ltoken = ctx.ltoken, |
| 396 | .layout = ctx.layout, | 360 | .layout = ctx.layout, |
| 397 | .kind = switch (token_ptr.id) { | 361 | .kind = switch (token_ptr.id) { |
| ... | @@ -399,9 +363,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -399,9 +363,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 399 | Token.Id.Keyword_union => ast.Node.ContainerDecl.Kind.Union, | 363 | Token.Id.Keyword_union => ast.Node.ContainerDecl.Kind.Union, |
| 400 | Token.Id.Keyword_enum => ast.Node.ContainerDecl.Kind.Enum, | 364 | Token.Id.Keyword_enum => ast.Node.ContainerDecl.Kind.Enum, |
| 401 | else => { | 365 | else => { |
| 402 | *(try tree.errors.addOne()) = Error { | 366 | ((try tree.errors.addOne())).* = Error{ .ExpectedAggregateKw = Error.ExpectedAggregateKw{ .token = token_index } }; |
| 403 | .ExpectedAggregateKw = Error.ExpectedAggregateKw { .token = token_index }, | | |
| 404 | }; | | |
| 405 | return tree; | 367 | return tree; |
| 406 | }, | 368 | }, |
| 407 | }, | 369 | }, |
| ... | @@ -411,9 +373,9 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -411,9 +373,9 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 411 | }); | 373 | }); |
| 412 | ctx.opt_ctx.store(&node.base); | 374 | ctx.opt_ctx.store(&node.base); |
| 413 | | 375 | |
| 414 | stack.append(State { .ContainerDecl = node }) catch unreachable; | 376 | stack.append(State{ .ContainerDecl = node }) catch unreachable; |
| 415 | try stack.append(State { .ExpectToken = Token.Id.LBrace }); | 377 | try stack.append(State{ .ExpectToken = Token.Id.LBrace }); |
| 416 | try stack.append(State { .ContainerInitArgStart = node }); | 378 | try stack.append(State{ .ContainerInitArgStart = node }); |
| 417 | continue; | 379 | continue; |
| 418 | }, | 380 | }, |
| 419 | | 381 | |
| ... | @@ -422,8 +384,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -422,8 +384,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 422 | continue; | 384 | continue; |
| 423 | } | 385 | } |
| 424 | | 386 | |
| 425 | stack.append(State { .ExpectToken = Token.Id.RParen }) catch unreachable; | 387 | stack.append(State{ .ExpectToken = Token.Id.RParen }) catch unreachable; |
| 426 | try stack.append(State { .ContainerInitArg = container_decl }); | 388 | try stack.append(State{ .ContainerInitArg = container_decl }); |
| 427 | continue; | 389 | continue; |
| 428 | }, | 390 | }, |
| 429 | | 391 | |
| ... | @@ -433,23 +395,21 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -433,23 +395,21 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 433 | const init_arg_token_ptr = init_arg_token.ptr; | 395 | const init_arg_token_ptr = init_arg_token.ptr; |
| 434 | switch (init_arg_token_ptr.id) { | 396 | switch (init_arg_token_ptr.id) { |
| 435 | Token.Id.Keyword_enum => { | 397 | Token.Id.Keyword_enum => { |
| 436 | container_decl.init_arg_expr = ast.Node.ContainerDecl.InitArg {.Enum = null}; | 398 | container_decl.init_arg_expr = ast.Node.ContainerDecl.InitArg{ .Enum = null }; |
| 437 | const lparen_tok = nextToken(&tok_it, &tree); | 399 | const lparen_tok = nextToken(&tok_it, &tree); |
| 438 | const lparen_tok_index = lparen_tok.index; | 400 | const lparen_tok_index = lparen_tok.index; |
| 439 | const lparen_tok_ptr = lparen_tok.ptr; | 401 | const lparen_tok_ptr = lparen_tok.ptr; |
| 440 | if (lparen_tok_ptr.id == Token.Id.LParen) { | 402 | if (lparen_tok_ptr.id == Token.Id.LParen) { |
| 441 | try stack.append(State { .ExpectToken = Token.Id.RParen } ); | 403 | try stack.append(State{ .ExpectToken = Token.Id.RParen }); |
| 442 | try stack.append(State { .Expression = OptionalCtx { | 404 | try stack.append(State{ .Expression = OptionalCtx{ .RequiredNull = &container_decl.init_arg_expr.Enum } }); |
| 443 | .RequiredNull = &container_decl.init_arg_expr.Enum, | | |
| 444 | } }); | | |
| 445 | } else { | 405 | } else { |
| 446 | putBackToken(&tok_it, &tree); | 406 | putBackToken(&tok_it, &tree); |
| 447 | } | 407 | } |
| 448 | }, | 408 | }, |
| 449 | else => { | 409 | else => { |
| 450 | putBackToken(&tok_it, &tree); | 410 | putBackToken(&tok_it, &tree); |
| 451 | container_decl.init_arg_expr = ast.Node.ContainerDecl.InitArg { .Type = undefined }; | 411 | container_decl.init_arg_expr = ast.Node.ContainerDecl.InitArg{ .Type = undefined }; |
| 452 | stack.append(State { .Expression = OptionalCtx { .Required = &container_decl.init_arg_expr.Type } }) catch unreachable; | 412 | stack.append(State{ .Expression = OptionalCtx{ .Required = &container_decl.init_arg_expr.Type } }) catch unreachable; |
| 453 | }, | 413 | }, |
| 454 | } | 414 | } |
| 455 | continue; | 415 | continue; |
| ... | @@ -468,26 +428,24 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -468,26 +428,24 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 468 | Token.Id.Identifier => { | 428 | Token.Id.Identifier => { |
| 469 | switch (container_decl.kind) { | 429 | switch (container_decl.kind) { |
| 470 | ast.Node.ContainerDecl.Kind.Struct => { | 430 | ast.Node.ContainerDecl.Kind.Struct => { |
| 471 | const node = try arena.construct(ast.Node.StructField { | 431 | const node = try arena.construct(ast.Node.StructField{ |
| 472 | .base = ast.Node { | 432 | .base = ast.Node{ .id = ast.Node.Id.StructField }, |
| 473 | .id = ast.Node.Id.StructField, | | |
| 474 | }, | | |
| 475 | .doc_comments = comments, | 433 | .doc_comments = comments, |
| 476 | .visib_token = null, | 434 | .visib_token = null, |
| 477 | .name_token = token_index, | 435 | .name_token = token_index, |
| 478 | .type_expr = undefined, | 436 | .type_expr = undefined, |
| 479 | }); | 437 | }); |
| 480 | const node_ptr = try container_decl.fields_and_decls.addOne(); | 438 | const node_ptr = try container_decl.fields_and_decls.addOne(); |
| 481 | *node_ptr = &node.base; | 439 | node_ptr.* = &node.base; |
| 482 | | 440 | |
| 483 | try stack.append(State { .FieldListCommaOrEnd = container_decl }); | 441 | try stack.append(State{ .FieldListCommaOrEnd = container_decl }); |
| 484 | try stack.append(State { .TypeExprBegin = OptionalCtx { .Required = &node.type_expr } }); | 442 | try stack.append(State{ .TypeExprBegin = OptionalCtx{ .Required = &node.type_expr } }); |
| 485 | try stack.append(State { .ExpectToken = Token.Id.Colon }); | 443 | try stack.append(State{ .ExpectToken = Token.Id.Colon }); |
| 486 | continue; | 444 | continue; |
| 487 | }, | 445 | }, |
| 488 | ast.Node.ContainerDecl.Kind.Union => { | 446 | ast.Node.ContainerDecl.Kind.Union => { |
| 489 | const node = try arena.construct(ast.Node.UnionTag { | 447 | const node = try arena.construct(ast.Node.UnionTag{ |
| 490 | .base = ast.Node {.id = ast.Node.Id.UnionTag }, | 448 | .base = ast.Node{ .id = ast.Node.Id.UnionTag }, |
| 491 | .name_token = token_index, | 449 | .name_token = token_index, |
| 492 | .type_expr = null, | 450 | .type_expr = null, |
| 493 | .value_expr = null, | 451 | .value_expr = null, |
| ... | @@ -495,24 +453,24 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -495,24 +453,24 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 495 | }); | 453 | }); |
| 496 | try container_decl.fields_and_decls.push(&node.base); | 454 | try container_decl.fields_and_decls.push(&node.base); |
| 497 | | 455 | |
| 498 | stack.append(State { .FieldListCommaOrEnd = container_decl }) catch unreachable; | 456 | stack.append(State{ .FieldListCommaOrEnd = container_decl }) catch unreachable; |
| 499 | try stack.append(State { .FieldInitValue = OptionalCtx { .RequiredNull = &node.value_expr } }); | 457 | try stack.append(State{ .FieldInitValue = OptionalCtx{ .RequiredNull = &node.value_expr } }); |
| 500 | try stack.append(State { .TypeExprBegin = OptionalCtx { .RequiredNull = &node.type_expr } }); | 458 | try stack.append(State{ .TypeExprBegin = OptionalCtx{ .RequiredNull = &node.type_expr } }); |
| 501 | try stack.append(State { .IfToken = Token.Id.Colon }); | 459 | try stack.append(State{ .IfToken = Token.Id.Colon }); |
| 502 | continue; | 460 | continue; |
| 503 | }, | 461 | }, |
| 504 | ast.Node.ContainerDecl.Kind.Enum => { | 462 | ast.Node.ContainerDecl.Kind.Enum => { |
| 505 | const node = try arena.construct(ast.Node.EnumTag { | 463 | const node = try arena.construct(ast.Node.EnumTag{ |
| 506 | .base = ast.Node { .id = ast.Node.Id.EnumTag }, | 464 | .base = ast.Node{ .id = ast.Node.Id.EnumTag }, |
| 507 | .name_token = token_index, | 465 | .name_token = token_index, |
| 508 | .value = null, | 466 | .value = null, |
| 509 | .doc_comments = comments, | 467 | .doc_comments = comments, |
| 510 | }); | 468 | }); |
| 511 | try container_decl.fields_and_decls.push(&node.base); | 469 | try container_decl.fields_and_decls.push(&node.base); |
| 512 | | 470 | |
| 513 | stack.append(State { .FieldListCommaOrEnd = container_decl }) catch unreachable; | 471 | stack.append(State{ .FieldListCommaOrEnd = container_decl }) catch unreachable; |
| 514 | try stack.append(State { .Expression = OptionalCtx { .RequiredNull = &node.value } }); | 472 | try stack.append(State{ .Expression = OptionalCtx{ .RequiredNull = &node.value } }); |
| 515 | try stack.append(State { .IfToken = Token.Id.Equal }); | 473 | try stack.append(State{ .IfToken = Token.Id.Equal }); |
| 516 | continue; | 474 | continue; |
| 517 | }, | 475 | }, |
| 518 | } | 476 | } |
| ... | @@ -520,48 +478,40 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -520,48 +478,40 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 520 | Token.Id.Keyword_pub => { | 478 | Token.Id.Keyword_pub => { |
| 521 | switch (container_decl.kind) { | 479 | switch (container_decl.kind) { |
| 522 | ast.Node.ContainerDecl.Kind.Struct => { | 480 | ast.Node.ContainerDecl.Kind.Struct => { |
| 523 | try stack.append(State { | 481 | try stack.append(State{ .TopLevelExternOrField = TopLevelExternOrFieldCtx{ |
| 524 | .TopLevelExternOrField = TopLevelExternOrFieldCtx { | 482 | .visib_token = token_index, |
| 525 | .visib_token = token_index, | 483 | .container_decl = container_decl, |
| 526 | .container_decl = container_decl, | 484 | .comments = comments, |
| 527 | .comments = comments, | 485 | } }); |
| 528 | } | | |
| 529 | }); | | |
| 530 | continue; | 486 | continue; |
| 531 | }, | 487 | }, |
| 532 | else => { | 488 | else => { |
| 533 | stack.append(State{ .ContainerDecl = container_decl }) catch unreachable; | 489 | stack.append(State{ .ContainerDecl = container_decl }) catch unreachable; |
| 534 | try stack.append(State { | 490 | try stack.append(State{ .TopLevelExtern = TopLevelDeclCtx{ |
| 535 | .TopLevelExtern = TopLevelDeclCtx { | 491 | .decls = &container_decl.fields_and_decls, |
| 536 | .decls = &container_decl.fields_and_decls, | 492 | .visib_token = token_index, |
| 537 | .visib_token = token_index, | 493 | .extern_export_inline_token = null, |
| 538 | .extern_export_inline_token = null, | 494 | .lib_name = null, |
| 539 | .lib_name = null, | 495 | .comments = comments, |
| 540 | .comments = comments, | 496 | } }); |
| 541 | } | | |
| 542 | }); | | |
| 543 | continue; | 497 | continue; |
| 544 | } | 498 | }, |
| 545 | } | 499 | } |
| 546 | }, | 500 | }, |
| 547 | Token.Id.Keyword_export => { | 501 | Token.Id.Keyword_export => { |
| 548 | stack.append(State{ .ContainerDecl = container_decl }) catch unreachable; | 502 | stack.append(State{ .ContainerDecl = container_decl }) catch unreachable; |
| 549 | try stack.append(State { | 503 | try stack.append(State{ .TopLevelExtern = TopLevelDeclCtx{ |
| 550 | .TopLevelExtern = TopLevelDeclCtx { | 504 | .decls = &container_decl.fields_and_decls, |
| 551 | .decls = &container_decl.fields_and_decls, | 505 | .visib_token = token_index, |
| 552 | .visib_token = token_index, | 506 | .extern_export_inline_token = null, |
| 553 | .extern_export_inline_token = null, | 507 | .lib_name = null, |
| 554 | .lib_name = null, | 508 | .comments = comments, |
| 555 | .comments = comments, | 509 | } }); |
| 556 | } | | |
| 557 | }); | | |
| 558 | continue; | 510 | continue; |
| 559 | }, | 511 | }, |
| 560 | Token.Id.RBrace => { | 512 | Token.Id.RBrace => { |
| 561 | if (comments != null) { | 513 | if (comments != null) { |
| 562 | *(try tree.errors.addOne()) = Error { | 514 | ((try tree.errors.addOne())).* = Error{ .UnattachedDocComment = Error.UnattachedDocComment{ .token = token_index } }; |
| 563 | .UnattachedDocComment = Error.UnattachedDocComment { .token = token_index }, | | |
| 564 | }; | | |
| 565 | return tree; | 515 | return tree; |
| 566 | } | 516 | } |
| 567 | container_decl.rbrace_token = token_index; | 517 | container_decl.rbrace_token = token_index; |
| ... | @@ -570,26 +520,21 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -570,26 +520,21 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 570 | else => { | 520 | else => { |
| 571 | putBackToken(&tok_it, &tree); | 521 | putBackToken(&tok_it, &tree); |
| 572 | stack.append(State{ .ContainerDecl = container_decl }) catch unreachable; | 522 | stack.append(State{ .ContainerDecl = container_decl }) catch unreachable; |
| 573 | try stack.append(State { | 523 | try stack.append(State{ .TopLevelExtern = TopLevelDeclCtx{ |
| 574 | .TopLevelExtern = TopLevelDeclCtx { | 524 | .decls = &container_decl.fields_and_decls, |
| 575 | .decls = &container_decl.fields_and_decls, | 525 | .visib_token = null, |
| 576 | .visib_token = null, | 526 | .extern_export_inline_token = null, |
| 577 | .extern_export_inline_token = null, | 527 | .lib_name = null, |
| 578 | .lib_name = null, | 528 | .comments = comments, |
| 579 | .comments = comments, | 529 | } }); |
| 580 | } | | |
| 581 | }); | | |
| 582 | continue; | 530 | continue; |
| 583 | } | 531 | }, |
| 584 | } | 532 | } |
| 585 | }, | 533 | }, |
| 586 | | 534 | |
| 587 | | | |
| 588 | State.VarDecl => |ctx| { | 535 | State.VarDecl => |ctx| { |
| 589 | const var_decl = try arena.construct(ast.Node.VarDecl { | 536 | const var_decl = try arena.construct(ast.Node.VarDecl{ |
| 590 | .base = ast.Node { | 537 | .base = ast.Node{ .id = ast.Node.Id.VarDecl }, |
| 591 | .id = ast.Node.Id.VarDecl, | | |
| 592 | }, | | |
| 593 | .doc_comments = ctx.comments, | 538 | .doc_comments = ctx.comments, |
| 594 | .visib_token = ctx.visib_token, | 539 | .visib_token = ctx.visib_token, |
| 595 | .mut_token = ctx.mut_token, | 540 | .mut_token = ctx.mut_token, |
| ... | @@ -606,27 +551,25 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -606,27 +551,25 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 606 | }); | 551 | }); |
| 607 | try ctx.list.push(&var_decl.base); | 552 | try ctx.list.push(&var_decl.base); |
| 608 | | 553 | |
| 609 | try stack.append(State { .VarDeclAlign = var_decl }); | 554 | try stack.append(State{ .VarDeclAlign = var_decl }); |
| 610 | try stack.append(State { .TypeExprBegin = OptionalCtx { .RequiredNull = &var_decl.type_node} }); | 555 | try stack.append(State{ .TypeExprBegin = OptionalCtx{ .RequiredNull = &var_decl.type_node } }); |
| 611 | try stack.append(State { .IfToken = Token.Id.Colon }); | 556 | try stack.append(State{ .IfToken = Token.Id.Colon }); |
| 612 | try stack.append(State { | 557 | try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{ |
| 613 | .ExpectTokenSave = ExpectTokenSave { | 558 | .id = Token.Id.Identifier, |
| 614 | .id = Token.Id.Identifier, | 559 | .ptr = &var_decl.name_token, |
| 615 | .ptr = &var_decl.name_token, | 560 | } }); |
| 616 | } | | |
| 617 | }); | | |
| 618 | continue; | 561 | continue; |
| 619 | }, | 562 | }, |
| 620 | State.VarDeclAlign => |var_decl| { | 563 | State.VarDeclAlign => |var_decl| { |
| 621 | try stack.append(State { .VarDeclEq = var_decl }); | 564 | try stack.append(State{ .VarDeclEq = var_decl }); |
| 622 | | 565 | |
| 623 | const next_token = nextToken(&tok_it, &tree); | 566 | const next_token = nextToken(&tok_it, &tree); |
| 624 | const next_token_index = next_token.index; | 567 | const next_token_index = next_token.index; |
| 625 | const next_token_ptr = next_token.ptr; | 568 | const next_token_ptr = next_token.ptr; |
| 626 | if (next_token_ptr.id == Token.Id.Keyword_align) { | 569 | if (next_token_ptr.id == Token.Id.Keyword_align) { |
| 627 | try stack.append(State { .ExpectToken = Token.Id.RParen }); | 570 | try stack.append(State{ .ExpectToken = Token.Id.RParen }); |
| 628 | try stack.append(State { .Expression = OptionalCtx { .RequiredNull = &var_decl.align_node} }); | 571 | try stack.append(State{ .Expression = OptionalCtx{ .RequiredNull = &var_decl.align_node } }); |
| 629 | try stack.append(State { .ExpectToken = Token.Id.LParen }); | 572 | try stack.append(State{ .ExpectToken = Token.Id.LParen }); |
| 630 | continue; | 573 | continue; |
| 631 | } | 574 | } |
| 632 | | 575 | |
| ... | @@ -640,8 +583,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -640,8 +583,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 640 | switch (token_ptr.id) { | 583 | switch (token_ptr.id) { |
| 641 | Token.Id.Equal => { | 584 | Token.Id.Equal => { |
| 642 | var_decl.eq_token = token_index; | 585 | var_decl.eq_token = token_index; |
| 643 | stack.append(State { .VarDeclSemiColon = var_decl }) catch unreachable; | 586 | stack.append(State{ .VarDeclSemiColon = var_decl }) catch unreachable; |
| 644 | try stack.append(State { .Expression = OptionalCtx { .RequiredNull = &var_decl.init_node } }); | 587 | try stack.append(State{ .Expression = OptionalCtx{ .RequiredNull = &var_decl.init_node } }); |
| 645 | continue; | 588 | continue; |
| 646 | }, | 589 | }, |
| 647 | Token.Id.Semicolon => { | 590 | Token.Id.Semicolon => { |
| ... | @@ -649,11 +592,9 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -649,11 +592,9 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 649 | continue; | 592 | continue; |
| 650 | }, | 593 | }, |
| 651 | else => { | 594 | else => { |
| 652 | *(try tree.errors.addOne()) = Error { | 595 | ((try tree.errors.addOne())).* = Error{ .ExpectedEqOrSemi = Error.ExpectedEqOrSemi{ .token = token_index } }; |
| 653 | .ExpectedEqOrSemi = Error.ExpectedEqOrSemi { .token = token_index }, | | |
| 654 | }; | | |
| 655 | return tree; | 596 | return tree; |
| 656 | } | 597 | }, |
| 657 | } | 598 | } |
| 658 | }, | 599 | }, |
| 659 | | 600 | |
| ... | @@ -661,12 +602,10 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -661,12 +602,10 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 661 | const semicolon_token = nextToken(&tok_it, &tree); | 602 | const semicolon_token = nextToken(&tok_it, &tree); |
| 662 | | 603 | |
| 663 | if (semicolon_token.ptr.id != Token.Id.Semicolon) { | 604 | if (semicolon_token.ptr.id != Token.Id.Semicolon) { |
| 664 | *(try tree.errors.addOne()) = Error { | 605 | ((try tree.errors.addOne())).* = Error{ .ExpectedToken = Error.ExpectedToken{ |
| 665 | .ExpectedToken = Error.ExpectedToken { | 606 | .token = semicolon_token.index, |
| 666 | .token = semicolon_token.index, | 607 | .expected_id = Token.Id.Semicolon, |
| 667 | .expected_id = Token.Id.Semicolon, | 608 | } }; |
| 668 | }, | | |
| 669 | }; | | |
| 670 | return tree; | 609 | return tree; |
| 671 | } | 610 | } |
| 672 | | 611 | |
| ... | @@ -686,32 +625,30 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -686,32 +625,30 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 686 | const token = nextToken(&tok_it, &tree); | 625 | const token = nextToken(&tok_it, &tree); |
| 687 | const token_index = token.index; | 626 | const token_index = token.index; |
| 688 | const token_ptr = token.ptr; | 627 | const token_ptr = token.ptr; |
| 689 | switch(token_ptr.id) { | 628 | switch (token_ptr.id) { |
| 690 | Token.Id.LBrace => { | 629 | Token.Id.LBrace => { |
| 691 | const block = try arena.construct(ast.Node.Block { | 630 | const block = try arena.construct(ast.Node.Block{ |
| 692 | .base = ast.Node { .id = ast.Node.Id.Block }, | 631 | .base = ast.Node{ .id = ast.Node.Id.Block }, |
| 693 | .label = null, | 632 | .label = null, |
| 694 | .lbrace = token_index, | 633 | .lbrace = token_index, |
| 695 | .statements = ast.Node.Block.StatementList.init(arena), | 634 | .statements = ast.Node.Block.StatementList.init(arena), |
| 696 | .rbrace = undefined, | 635 | .rbrace = undefined, |
| 697 | }); | 636 | }); |
| 698 | fn_proto.body_node = &block.base; | 637 | fn_proto.body_node = &block.base; |
| 699 | stack.append(State { .Block = block }) catch unreachable; | 638 | stack.append(State{ .Block = block }) catch unreachable; |
| 700 | continue; | 639 | continue; |
| 701 | }, | 640 | }, |
| 702 | Token.Id.Semicolon => continue, | 641 | Token.Id.Semicolon => continue, |
| 703 | else => { | 642 | else => { |
| 704 | *(try tree.errors.addOne()) = Error { | 643 | ((try tree.errors.addOne())).* = Error{ .ExpectedSemiOrLBrace = Error.ExpectedSemiOrLBrace{ .token = token_index } }; |
| 705 | .ExpectedSemiOrLBrace = Error.ExpectedSemiOrLBrace { .token = token_index }, | | |
| 706 | }; | | |
| 707 | return tree; | 644 | return tree; |
| 708 | }, | 645 | }, |
| 709 | } | 646 | } |
| 710 | }, | 647 | }, |
| 711 | State.FnProto => |fn_proto| { | 648 | State.FnProto => |fn_proto| { |
| 712 | stack.append(State { .FnProtoAlign = fn_proto }) catch unreachable; | 649 | stack.append(State{ .FnProtoAlign = fn_proto }) catch unreachable; |
| 713 | try stack.append(State { .ParamDecl = fn_proto }); | 650 | try stack.append(State{ .ParamDecl = fn_proto }); |
| 714 | try stack.append(State { .ExpectToken = Token.Id.LParen }); | 651 | try stack.append(State{ .ExpectToken = Token.Id.LParen }); |
| 715 | | 652 | |
| 716 | if (eatToken(&tok_it, &tree, Token.Id.Identifier)) |name_token| { | 653 | if (eatToken(&tok_it, &tree, Token.Id.Identifier)) |name_token| { |
| 717 | fn_proto.name_token = name_token; | 654 | fn_proto.name_token = name_token; |
| ... | @@ -719,12 +656,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -719,12 +656,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 719 | continue; | 656 | continue; |
| 720 | }, | 657 | }, |
| 721 | State.FnProtoAlign => |fn_proto| { | 658 | State.FnProtoAlign => |fn_proto| { |
| 722 | stack.append(State { .FnProtoReturnType = fn_proto }) catch unreachable; | 659 | stack.append(State{ .FnProtoReturnType = fn_proto }) catch unreachable; |
| 723 | | 660 | |
| 724 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_align)) |align_token| { | 661 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_align)) |align_token| { |
| 725 | try stack.append(State { .ExpectToken = Token.Id.RParen }); | 662 | try stack.append(State{ .ExpectToken = Token.Id.RParen }); |
| 726 | try stack.append(State { .Expression = OptionalCtx { .RequiredNull = &fn_proto.align_expr } }); | 663 | try stack.append(State{ .Expression = OptionalCtx{ .RequiredNull = &fn_proto.align_expr } }); |
| 727 | try stack.append(State { .ExpectToken = Token.Id.LParen }); | 664 | try stack.append(State{ .ExpectToken = Token.Id.LParen }); |
| 728 | } | 665 | } |
| 729 | continue; | 666 | continue; |
| 730 | }, | 667 | }, |
| ... | @@ -734,42 +671,37 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -734,42 +671,37 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 734 | const token_ptr = token.ptr; | 671 | const token_ptr = token.ptr; |
| 735 | switch (token_ptr.id) { | 672 | switch (token_ptr.id) { |
| 736 | Token.Id.Bang => { | 673 | Token.Id.Bang => { |
| 737 | fn_proto.return_type = ast.Node.FnProto.ReturnType { .InferErrorSet = undefined }; | 674 | fn_proto.return_type = ast.Node.FnProto.ReturnType{ .InferErrorSet = undefined }; |
| 738 | stack.append(State { | 675 | stack.append(State{ .TypeExprBegin = OptionalCtx{ .Required = &fn_proto.return_type.InferErrorSet } }) catch unreachable; |
| 739 | .TypeExprBegin = OptionalCtx { .Required = &fn_proto.return_type.InferErrorSet }, | | |
| 740 | }) catch unreachable; | | |
| 741 | continue; | 676 | continue; |
| 742 | }, | 677 | }, |
| 743 | else => { | 678 | else => { |
| 744 | // TODO: this is a special case. Remove this when #760 is fixed | 679 | // TODO: this is a special case. Remove this when #760 is fixed |
| 745 | if (token_ptr.id == Token.Id.Keyword_error) { | 680 | if (token_ptr.id == Token.Id.Keyword_error) { |
| 746 | if ((??tok_it.peek()).id == Token.Id.LBrace) { | 681 | if ((??tok_it.peek()).id == Token.Id.LBrace) { |
| 747 | const error_type_node = try arena.construct(ast.Node.ErrorType { | 682 | const error_type_node = try arena.construct(ast.Node.ErrorType{ |
| 748 | .base = ast.Node { .id = ast.Node.Id.ErrorType }, | 683 | .base = ast.Node{ .id = ast.Node.Id.ErrorType }, |
| 749 | .token = token_index, | 684 | .token = token_index, |
| 750 | }); | 685 | }); |
| 751 | fn_proto.return_type = ast.Node.FnProto.ReturnType { | 686 | fn_proto.return_type = ast.Node.FnProto.ReturnType{ .Explicit = &error_type_node.base }; |
| 752 | .Explicit = &error_type_node.base, | | |
| 753 | }; | | |
| 754 | continue; | 687 | continue; |
| 755 | } | 688 | } |
| 756 | } | 689 | } |
| 757 | | 690 | |
| 758 | putBackToken(&tok_it, &tree); | 691 | putBackToken(&tok_it, &tree); |
| 759 | fn_proto.return_type = ast.Node.FnProto.ReturnType { .Explicit = undefined }; | 692 | fn_proto.return_type = ast.Node.FnProto.ReturnType{ .Explicit = undefined }; |
| 760 | stack.append(State { .TypeExprBegin = OptionalCtx { .Required = &fn_proto.return_type.Explicit }, }) catch unreachable; | 693 | stack.append(State{ .TypeExprBegin = OptionalCtx{ .Required = &fn_proto.return_type.Explicit } }) catch unreachable; |
| 761 | continue; | 694 | continue; |
| 762 | }, | 695 | }, |
| 763 | } | 696 | } |
| 764 | }, | 697 | }, |
| 765 | | 698 | |
| 766 | | | |
| 767 | State.ParamDecl => |fn_proto| { | 699 | State.ParamDecl => |fn_proto| { |
| 768 | if (eatToken(&tok_it, &tree, Token.Id.RParen)) |_| { | 700 | if (eatToken(&tok_it, &tree, Token.Id.RParen)) |_| { |
| 769 | continue; | 701 | continue; |
| 770 | } | 702 | } |
| 771 | const param_decl = try arena.construct(ast.Node.ParamDecl { | 703 | const param_decl = try arena.construct(ast.Node.ParamDecl{ |
| 772 | .base = ast.Node {.id = ast.Node.Id.ParamDecl }, | 704 | .base = ast.Node{ .id = ast.Node.Id.ParamDecl }, |
| 773 | .comptime_token = null, | 705 | .comptime_token = null, |
| 774 | .noalias_token = null, | 706 | .noalias_token = null, |
| 775 | .name_token = null, | 707 | .name_token = null, |
| ... | @@ -778,14 +710,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -778,14 +710,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 778 | }); | 710 | }); |
| 779 | try fn_proto.params.push(&param_decl.base); | 711 | try fn_proto.params.push(&param_decl.base); |
| 780 | | 712 | |
| 781 | stack.append(State { | 713 | stack.append(State{ .ParamDeclEnd = ParamDeclEndCtx{ |
| 782 | .ParamDeclEnd = ParamDeclEndCtx { | 714 | .param_decl = param_decl, |
| 783 | .param_decl = param_decl, | 715 | .fn_proto = fn_proto, |
| 784 | .fn_proto = fn_proto, | 716 | } }) catch unreachable; |
| 785 | } | 717 | try stack.append(State{ .ParamDeclName = param_decl }); |
| 786 | }) catch unreachable; | 718 | try stack.append(State{ .ParamDeclAliasOrComptime = param_decl }); |
| 787 | try stack.append(State { .ParamDeclName = param_decl }); | | |
| 788 | try stack.append(State { .ParamDeclAliasOrComptime = param_decl }); | | |
| 789 | continue; | 719 | continue; |
| 790 | }, | 720 | }, |
| 791 | State.ParamDeclAliasOrComptime => |param_decl| { | 721 | State.ParamDeclAliasOrComptime => |param_decl| { |
| ... | @@ -811,21 +741,19 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -811,21 +741,19 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 811 | State.ParamDeclEnd => |ctx| { | 741 | State.ParamDeclEnd => |ctx| { |
| 812 | if (eatToken(&tok_it, &tree, Token.Id.Ellipsis3)) |ellipsis3| { | 742 | if (eatToken(&tok_it, &tree, Token.Id.Ellipsis3)) |ellipsis3| { |
| 813 | ctx.param_decl.var_args_token = ellipsis3; | 743 | ctx.param_decl.var_args_token = ellipsis3; |
| 814 | stack.append(State { .ExpectToken = Token.Id.RParen }) catch unreachable; | 744 | stack.append(State{ .ExpectToken = Token.Id.RParen }) catch unreachable; |
| 815 | continue; | 745 | continue; |
| 816 | } | 746 | } |
| 817 | | 747 | |
| 818 | try stack.append(State { .ParamDeclComma = ctx.fn_proto }); | 748 | try stack.append(State{ .ParamDeclComma = ctx.fn_proto }); |
| 819 | try stack.append(State { | 749 | try stack.append(State{ .TypeExprBegin = OptionalCtx{ .Required = &ctx.param_decl.type_node } }); |
| 820 | .TypeExprBegin = OptionalCtx { .Required = &ctx.param_decl.type_node } | | |
| 821 | }); | | |
| 822 | continue; | 750 | continue; |
| 823 | }, | 751 | }, |
| 824 | State.ParamDeclComma => |fn_proto| { | 752 | State.ParamDeclComma => |fn_proto| { |
| 825 | switch (expectCommaOrEnd(&tok_it, &tree, Token.Id.RParen)) { | 753 | switch (expectCommaOrEnd(&tok_it, &tree, Token.Id.RParen)) { |
| 826 | ExpectCommaOrEndResult.end_token => |t| { | 754 | ExpectCommaOrEndResult.end_token => |t| { |
| 827 | if (t == null) { | 755 | if (t == null) { |
| 828 | stack.append(State { .ParamDecl = fn_proto }) catch unreachable; | 756 | stack.append(State{ .ParamDecl = fn_proto }) catch unreachable; |
| 829 | } | 757 | } |
| 830 | continue; | 758 | continue; |
| 831 | }, | 759 | }, |
| ... | @@ -838,12 +766,10 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -838,12 +766,10 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 838 | | 766 | |
| 839 | State.MaybeLabeledExpression => |ctx| { | 767 | State.MaybeLabeledExpression => |ctx| { |
| 840 | if (eatToken(&tok_it, &tree, Token.Id.Colon)) |_| { | 768 | if (eatToken(&tok_it, &tree, Token.Id.Colon)) |_| { |
| 841 | stack.append(State { | 769 | stack.append(State{ .LabeledExpression = LabelCtx{ |
| 842 | .LabeledExpression = LabelCtx { | 770 | .label = ctx.label, |
| 843 | .label = ctx.label, | 771 | .opt_ctx = ctx.opt_ctx, |
| 844 | .opt_ctx = ctx.opt_ctx, | 772 | } }) catch unreachable; |
| 845 | } | | |
| 846 | }) catch unreachable; | | |
| 847 | continue; | 773 | continue; |
| 848 | } | 774 | } |
| 849 | | 775 | |
| ... | @@ -856,69 +782,59 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -856,69 +782,59 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 856 | const token_ptr = token.ptr; | 782 | const token_ptr = token.ptr; |
| 857 | switch (token_ptr.id) { | 783 | switch (token_ptr.id) { |
| 858 | Token.Id.LBrace => { | 784 | Token.Id.LBrace => { |
| 859 | const block = try arena.construct(ast.Node.Block { | 785 | const block = try arena.construct(ast.Node.Block{ |
| 860 | .base = ast.Node {.id = ast.Node.Id.Block}, | 786 | .base = ast.Node{ .id = ast.Node.Id.Block }, |
| 861 | .label = ctx.label, | 787 | .label = ctx.label, |
| 862 | .lbrace = token_index, | 788 | .lbrace = token_index, |
| 863 | .statements = ast.Node.Block.StatementList.init(arena), | 789 | .statements = ast.Node.Block.StatementList.init(arena), |
| 864 | .rbrace = undefined, | 790 | .rbrace = undefined, |
| 865 | }); | 791 | }); |
| 866 | ctx.opt_ctx.store(&block.base); | 792 | ctx.opt_ctx.store(&block.base); |
| 867 | stack.append(State { .Block = block }) catch unreachable; | 793 | stack.append(State{ .Block = block }) catch unreachable; |
| 868 | continue; | 794 | continue; |
| 869 | }, | 795 | }, |
| 870 | Token.Id.Keyword_while => { | 796 | Token.Id.Keyword_while => { |
| 871 | stack.append(State { | 797 | stack.append(State{ .While = LoopCtx{ |
| 872 | .While = LoopCtx { | 798 | .label = ctx.label, |
| 873 | .label = ctx.label, | 799 | .inline_token = null, |
| 874 | .inline_token = null, | 800 | .loop_token = token_index, |
| 875 | .loop_token = token_index, | 801 | .opt_ctx = ctx.opt_ctx.toRequired(), |
| 876 | .opt_ctx = ctx.opt_ctx.toRequired(), | 802 | } }) catch unreachable; |
| 877 | } | | |
| 878 | }) catch unreachable; | | |
| 879 | continue; | 803 | continue; |
| 880 | }, | 804 | }, |
| 881 | Token.Id.Keyword_for => { | 805 | Token.Id.Keyword_for => { |
| 882 | stack.append(State { | 806 | stack.append(State{ .For = LoopCtx{ |
| 883 | .For = LoopCtx { | 807 | .label = ctx.label, |
| 884 | .label = ctx.label, | 808 | .inline_token = null, |
| 885 | .inline_token = null, | 809 | .loop_token = token_index, |
| 886 | .loop_token = token_index, | 810 | .opt_ctx = ctx.opt_ctx.toRequired(), |
| 887 | .opt_ctx = ctx.opt_ctx.toRequired(), | 811 | } }) catch unreachable; |
| 888 | } | | |
| 889 | }) catch unreachable; | | |
| 890 | continue; | 812 | continue; |
| 891 | }, | 813 | }, |
| 892 | Token.Id.Keyword_suspend => { | 814 | Token.Id.Keyword_suspend => { |
| 893 | const node = try arena.construct(ast.Node.Suspend { | 815 | const node = try arena.construct(ast.Node.Suspend{ |
| 894 | .base = ast.Node { | 816 | .base = ast.Node{ .id = ast.Node.Id.Suspend }, |
| 895 | .id = ast.Node.Id.Suspend, | | |
| 896 | }, | | |
| 897 | .label = ctx.label, | 817 | .label = ctx.label, |
| 898 | .suspend_token = token_index, | 818 | .suspend_token = token_index, |
| 899 | .payload = null, | 819 | .payload = null, |
| 900 | .body = null, | 820 | .body = null, |
| 901 | }); | 821 | }); |
| 902 | ctx.opt_ctx.store(&node.base); | 822 | ctx.opt_ctx.store(&node.base); |
| 903 | stack.append(State { .SuspendBody = node }) catch unreachable; | 823 | stack.append(State{ .SuspendBody = node }) catch unreachable; |
| 904 | try stack.append(State { .Payload = OptionalCtx { .Optional = &node.payload } }); | 824 | try stack.append(State{ .Payload = OptionalCtx{ .Optional = &node.payload } }); |
| 905 | continue; | 825 | continue; |
| 906 | }, | 826 | }, |
| 907 | Token.Id.Keyword_inline => { | 827 | Token.Id.Keyword_inline => { |
| 908 | stack.append(State { | 828 | stack.append(State{ .Inline = InlineCtx{ |
| 909 | .Inline = InlineCtx { | 829 | .label = ctx.label, |
| 910 | .label = ctx.label, | 830 | .inline_token = token_index, |
| 911 | .inline_token = token_index, | 831 | .opt_ctx = ctx.opt_ctx.toRequired(), |
| 912 | .opt_ctx = ctx.opt_ctx.toRequired(), | 832 | } }) catch unreachable; |
| 913 | } | | |
| 914 | }) catch unreachable; | | |
| 915 | continue; | 833 | continue; |
| 916 | }, | 834 | }, |
| 917 | else => { | 835 | else => { |
| 918 | if (ctx.opt_ctx != OptionalCtx.Optional) { | 836 | if (ctx.opt_ctx != OptionalCtx.Optional) { |
| 919 | *(try tree.errors.addOne()) = Error { | 837 | ((try tree.errors.addOne())).* = Error{ .ExpectedLabelable = Error.ExpectedLabelable{ .token = token_index } }; |
| 920 | .ExpectedLabelable = Error.ExpectedLabelable { .token = token_index }, | | |
| 921 | }; | | |
| 922 | return tree; | 838 | return tree; |
| 923 | } | 839 | } |
| 924 | | 840 | |
| ... | @@ -933,32 +849,26 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -933,32 +849,26 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 933 | const token_ptr = token.ptr; | 849 | const token_ptr = token.ptr; |
| 934 | switch (token_ptr.id) { | 850 | switch (token_ptr.id) { |
| 935 | Token.Id.Keyword_while => { | 851 | Token.Id.Keyword_while => { |
| 936 | stack.append(State { | 852 | stack.append(State{ .While = LoopCtx{ |
| 937 | .While = LoopCtx { | 853 | .inline_token = ctx.inline_token, |
| 938 | .inline_token = ctx.inline_token, | 854 | .label = ctx.label, |
| 939 | .label = ctx.label, | 855 | .loop_token = token_index, |
| 940 | .loop_token = token_index, | 856 | .opt_ctx = ctx.opt_ctx.toRequired(), |
| 941 | .opt_ctx = ctx.opt_ctx.toRequired(), | 857 | } }) catch unreachable; |
| 942 | } | | |
| 943 | }) catch unreachable; | | |
| 944 | continue; | 858 | continue; |
| 945 | }, | 859 | }, |
| 946 | Token.Id.Keyword_for => { | 860 | Token.Id.Keyword_for => { |
| 947 | stack.append(State { | 861 | stack.append(State{ .For = LoopCtx{ |
| 948 | .For = LoopCtx { | 862 | .inline_token = ctx.inline_token, |
| 949 | .inline_token = ctx.inline_token, | 863 | .label = ctx.label, |
| 950 | .label = ctx.label, | 864 | .loop_token = token_index, |
| 951 | .loop_token = token_index, | 865 | .opt_ctx = ctx.opt_ctx.toRequired(), |
| 952 | .opt_ctx = ctx.opt_ctx.toRequired(), | 866 | } }) catch unreachable; |
| 953 | } | | |
| 954 | }) catch unreachable; | | |
| 955 | continue; | 867 | continue; |
| 956 | }, | 868 | }, |
| 957 | else => { | 869 | else => { |
| 958 | if (ctx.opt_ctx != OptionalCtx.Optional) { | 870 | if (ctx.opt_ctx != OptionalCtx.Optional) { |
| 959 | *(try tree.errors.addOne()) = Error { | 871 | ((try tree.errors.addOne())).* = Error{ .ExpectedInlinable = Error.ExpectedInlinable{ .token = token_index } }; |
| 960 | .ExpectedInlinable = Error.ExpectedInlinable { .token = token_index }, | | |
| 961 | }; | | |
| 962 | return tree; | 872 | return tree; |
| 963 | } | 873 | } |
| 964 | | 874 | |
| ... | @@ -968,8 +878,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -968,8 +878,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 968 | } | 878 | } |
| 969 | }, | 879 | }, |
| 970 | State.While => |ctx| { | 880 | State.While => |ctx| { |
| 971 | const node = try arena.construct(ast.Node.While { | 881 | const node = try arena.construct(ast.Node.While{ |
| 972 | .base = ast.Node {.id = ast.Node.Id.While }, | 882 | .base = ast.Node{ .id = ast.Node.Id.While }, |
| 973 | .label = ctx.label, | 883 | .label = ctx.label, |
| 974 | .inline_token = ctx.inline_token, | 884 | .inline_token = ctx.inline_token, |
| 975 | .while_token = ctx.loop_token, | 885 | .while_token = ctx.loop_token, |
| ... | @@ -980,25 +890,25 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -980,25 +890,25 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 980 | .@"else" = null, | 890 | .@"else" = null, |
| 981 | }); | 891 | }); |
| 982 | ctx.opt_ctx.store(&node.base); | 892 | ctx.opt_ctx.store(&node.base); |
| 983 | stack.append(State { .Else = &node.@"else" }) catch unreachable; | 893 | stack.append(State{ .Else = &node.@"else" }) catch unreachable; |
| 984 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.body } }); | 894 | try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.body } }); |
| 985 | try stack.append(State { .WhileContinueExpr = &node.continue_expr }); | 895 | try stack.append(State{ .WhileContinueExpr = &node.continue_expr }); |
| 986 | try stack.append(State { .IfToken = Token.Id.Colon }); | 896 | try stack.append(State{ .IfToken = Token.Id.Colon }); |
| 987 | try stack.append(State { .PointerPayload = OptionalCtx { .Optional = &node.payload } }); | 897 | try stack.append(State{ .PointerPayload = OptionalCtx{ .Optional = &node.payload } }); |
| 988 | try stack.append(State { .ExpectToken = Token.Id.RParen }); | 898 | try stack.append(State{ .ExpectToken = Token.Id.RParen }); |
| 989 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.condition } }); | 899 | try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.condition } }); |
| 990 | try stack.append(State { .ExpectToken = Token.Id.LParen }); | 900 | try stack.append(State{ .ExpectToken = Token.Id.LParen }); |
| 991 | continue; | 901 | continue; |
| 992 | }, | 902 | }, |
| 993 | State.WhileContinueExpr => |dest| { | 903 | State.WhileContinueExpr => |dest| { |
| 994 | stack.append(State { .ExpectToken = Token.Id.RParen }) catch unreachable; | 904 | stack.append(State{ .ExpectToken = Token.Id.RParen }) catch unreachable; |
| 995 | try stack.append(State { .AssignmentExpressionBegin = OptionalCtx { .RequiredNull = dest } }); | 905 | try stack.append(State{ .AssignmentExpressionBegin = OptionalCtx{ .RequiredNull = dest } }); |
| 996 | try stack.append(State { .ExpectToken = Token.Id.LParen }); | 906 | try stack.append(State{ .ExpectToken = Token.Id.LParen }); |
| 997 | continue; | 907 | continue; |
| 998 | }, | 908 | }, |
| 999 | State.For => |ctx| { | 909 | State.For => |ctx| { |
| 1000 | const node = try arena.construct(ast.Node.For { | 910 | const node = try arena.construct(ast.Node.For{ |
| 1001 | .base = ast.Node {.id = ast.Node.Id.For }, | 911 | .base = ast.Node{ .id = ast.Node.Id.For }, |
| 1002 | .label = ctx.label, | 912 | .label = ctx.label, |
| 1003 | .inline_token = ctx.inline_token, | 913 | .inline_token = ctx.inline_token, |
| 1004 | .for_token = ctx.loop_token, | 914 | .for_token = ctx.loop_token, |
| ... | @@ -1008,33 +918,32 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1008,33 +918,32 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1008 | .@"else" = null, | 918 | .@"else" = null, |
| 1009 | }); | 919 | }); |
| 1010 | ctx.opt_ctx.store(&node.base); | 920 | ctx.opt_ctx.store(&node.base); |
| 1011 | stack.append(State { .Else = &node.@"else" }) catch unreachable; | 921 | stack.append(State{ .Else = &node.@"else" }) catch unreachable; |
| 1012 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.body } }); | 922 | try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.body } }); |
| 1013 | try stack.append(State { .PointerIndexPayload = OptionalCtx { .Optional = &node.payload } }); | 923 | try stack.append(State{ .PointerIndexPayload = OptionalCtx{ .Optional = &node.payload } }); |
| 1014 | try stack.append(State { .ExpectToken = Token.Id.RParen }); | 924 | try stack.append(State{ .ExpectToken = Token.Id.RParen }); |
| 1015 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.array_expr } }); | 925 | try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.array_expr } }); |
| 1016 | try stack.append(State { .ExpectToken = Token.Id.LParen }); | 926 | try stack.append(State{ .ExpectToken = Token.Id.LParen }); |
| 1017 | continue; | 927 | continue; |
| 1018 | }, | 928 | }, |
| 1019 | State.Else => |dest| { | 929 | State.Else => |dest| { |
| 1020 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_else)) |else_token| { | 930 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_else)) |else_token| { |
| 1021 | const node = try arena.construct(ast.Node.Else { | 931 | const node = try arena.construct(ast.Node.Else{ |
| 1022 | .base = ast.Node {.id = ast.Node.Id.Else }, | 932 | .base = ast.Node{ .id = ast.Node.Id.Else }, |
| 1023 | .else_token = else_token, | 933 | .else_token = else_token, |
| 1024 | .payload = null, | 934 | .payload = null, |
| 1025 | .body = undefined, | 935 | .body = undefined, |
| 1026 | }); | 936 | }); |
| 1027 | *dest = node; | 937 | dest.* = node; |
| 1028 | | 938 | |
| 1029 | stack.append(State { .Expression = OptionalCtx { .Required = &node.body } }) catch unreachable; | 939 | stack.append(State{ .Expression = OptionalCtx{ .Required = &node.body } }) catch unreachable; |
| 1030 | try stack.append(State { .Payload = OptionalCtx { .Optional = &node.payload } }); | 940 | try stack.append(State{ .Payload = OptionalCtx{ .Optional = &node.payload } }); |
| 1031 | continue; | 941 | continue; |
| 1032 | } else { | 942 | } else { |
| 1033 | continue; | 943 | continue; |
| 1034 | } | 944 | } |
| 1035 | }, | 945 | }, |
| 1036 | | 946 | |
| 1037 | | | |
| 1038 | State.Block => |block| { | 947 | State.Block => |block| { |
| 1039 | const token = nextToken(&tok_it, &tree); | 948 | const token = nextToken(&tok_it, &tree); |
| 1040 | const token_index = token.index; | 949 | const token_index = token.index; |
| ... | @@ -1046,7 +955,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1046,7 +955,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1046 | }, | 955 | }, |
| 1047 | else => { | 956 | else => { |
| 1048 | putBackToken(&tok_it, &tree); | 957 | putBackToken(&tok_it, &tree); |
| 1049 | stack.append(State { .Block = block }) catch unreachable; | 958 | stack.append(State{ .Block = block }) catch unreachable; |
| 1050 | | 959 | |
| 1051 | var any_comments = false; | 960 | var any_comments = false; |
| 1052 | while (try eatLineComment(arena, &tok_it, &tree)) |line_comment| { | 961 | while (try eatLineComment(arena, &tok_it, &tree)) |line_comment| { |
| ... | @@ -1055,7 +964,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1055,7 +964,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1055 | } | 964 | } |
| 1056 | if (any_comments) continue; | 965 | if (any_comments) continue; |
| 1057 | | 966 | |
| 1058 | try stack.append(State { .Statement = block }); | 967 | try stack.append(State{ .Statement = block }); |
| 1059 | continue; | 968 | continue; |
| 1060 | }, | 969 | }, |
| 1061 | } | 970 | } |
| ... | @@ -1066,33 +975,29 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1066,33 +975,29 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1066 | const token_ptr = token.ptr; | 975 | const token_ptr = token.ptr; |
| 1067 | switch (token_ptr.id) { | 976 | switch (token_ptr.id) { |
| 1068 | Token.Id.Keyword_comptime => { | 977 | Token.Id.Keyword_comptime => { |
| 1069 | stack.append(State { | 978 | stack.append(State{ .ComptimeStatement = ComptimeStatementCtx{ |
| 1070 | .ComptimeStatement = ComptimeStatementCtx { | 979 | .comptime_token = token_index, |
| 1071 | .comptime_token = token_index, | 980 | .block = block, |
| 1072 | .block = block, | 981 | } }) catch unreachable; |
| 1073 | } | | |
| 1074 | }) catch unreachable; | | |
| 1075 | continue; | | |
| 1076 | }, | | |
| 1077 | Token.Id.Keyword_var, Token.Id.Keyword_const => { | | |
| 1078 | stack.append(State { | | |
| 1079 | .VarDecl = VarDeclCtx { | | |
| 1080 | .comments = null, | | |
| 1081 | .visib_token = null, | | |
| 1082 | .comptime_token = null, | | |
| 1083 | .extern_export_token = null, | | |
| 1084 | .lib_name = null, | | |
| 1085 | .mut_token = token_index, | | |
| 1086 | .list = &block.statements, | | |
| 1087 | } | | |
| 1088 | }) catch unreachable; | | |
| 1089 | continue; | 982 | continue; |
| 1090 | }, | 983 | }, |
| 1091 | Token.Id.Keyword_defer, Token.Id.Keyword_errdefer => { | 984 | Token.Id.Keyword_var, |
| 1092 | const node = try arena.construct(ast.Node.Defer { | 985 | Token.Id.Keyword_const => { |
| 1093 | .base = ast.Node { | 986 | stack.append(State{ .VarDecl = VarDeclCtx{ |
| 1094 | .id = ast.Node.Id.Defer, | 987 | .comments = null, |
| 1095 | }, | 988 | .visib_token = null, |
| | 989 | .comptime_token = null, |
| | 990 | .extern_export_token = null, |
| | 991 | .lib_name = null, |
| | 992 | .mut_token = token_index, |
| | 993 | .list = &block.statements, |
| | 994 | } }) catch unreachable; |
| | 995 | continue; |
| | 996 | }, |
| | 997 | Token.Id.Keyword_defer, |
| | 998 | Token.Id.Keyword_errdefer => { |
| | 999 | const node = try arena.construct(ast.Node.Defer{ |
| | 1000 | .base = ast.Node{ .id = ast.Node.Id.Defer }, |
| 1096 | .defer_token = token_index, | 1001 | .defer_token = token_index, |
| 1097 | .kind = switch (token_ptr.id) { | 1002 | .kind = switch (token_ptr.id) { |
| 1098 | Token.Id.Keyword_defer => ast.Node.Defer.Kind.Unconditional, | 1003 | Token.Id.Keyword_defer => ast.Node.Defer.Kind.Unconditional, |
| ... | @@ -1102,15 +1007,15 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1102,15 +1007,15 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1102 | .expr = undefined, | 1007 | .expr = undefined, |
| 1103 | }); | 1008 | }); |
| 1104 | const node_ptr = try block.statements.addOne(); | 1009 | const node_ptr = try block.statements.addOne(); |
| 1105 | *node_ptr = &node.base; | 1010 | node_ptr.* = &node.base; |
| 1106 | | 1011 | |
| 1107 | stack.append(State { .Semicolon = node_ptr }) catch unreachable; | 1012 | stack.append(State{ .Semicolon = node_ptr }) catch unreachable; |
| 1108 | try stack.append(State { .AssignmentExpressionBegin = OptionalCtx{ .Required = &node.expr } }); | 1013 | try stack.append(State{ .AssignmentExpressionBegin = OptionalCtx{ .Required = &node.expr } }); |
| 1109 | continue; | 1014 | continue; |
| 1110 | }, | 1015 | }, |
| 1111 | Token.Id.LBrace => { | 1016 | Token.Id.LBrace => { |
| 1112 | const inner_block = try arena.construct(ast.Node.Block { | 1017 | const inner_block = try arena.construct(ast.Node.Block{ |
| 1113 | .base = ast.Node { .id = ast.Node.Id.Block }, | 1018 | .base = ast.Node{ .id = ast.Node.Id.Block }, |
| 1114 | .label = null, | 1019 | .label = null, |
| 1115 | .lbrace = token_index, | 1020 | .lbrace = token_index, |
| 1116 | .statements = ast.Node.Block.StatementList.init(arena), | 1021 | .statements = ast.Node.Block.StatementList.init(arena), |
| ... | @@ -1118,16 +1023,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1118,16 +1023,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1118 | }); | 1023 | }); |
| 1119 | try block.statements.push(&inner_block.base); | 1024 | try block.statements.push(&inner_block.base); |
| 1120 | | 1025 | |
| 1121 | stack.append(State { .Block = inner_block }) catch unreachable; | 1026 | stack.append(State{ .Block = inner_block }) catch unreachable; |
| 1122 | continue; | 1027 | continue; |
| 1123 | }, | 1028 | }, |
| 1124 | else => { | 1029 | else => { |
| 1125 | putBackToken(&tok_it, &tree); | 1030 | putBackToken(&tok_it, &tree); |
| 1126 | const statement = try block.statements.addOne(); | 1031 | const statement = try block.statements.addOne(); |
| 1127 | try stack.append(State { .Semicolon = statement }); | 1032 | try stack.append(State{ .Semicolon = statement }); |
| 1128 | try stack.append(State { .AssignmentExpressionBegin = OptionalCtx{ .Required = statement } }); | 1033 | try stack.append(State{ .AssignmentExpressionBegin = OptionalCtx{ .Required = statement } }); |
| 1129 | continue; | 1034 | continue; |
| 1130 | } | 1035 | }, |
| 1131 | } | 1036 | } |
| 1132 | }, | 1037 | }, |
| 1133 | State.ComptimeStatement => |ctx| { | 1038 | State.ComptimeStatement => |ctx| { |
| ... | @@ -1135,34 +1040,33 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1135,34 +1040,33 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1135 | const token_index = token.index; | 1040 | const token_index = token.index; |
| 1136 | const token_ptr = token.ptr; | 1041 | const token_ptr = token.ptr; |
| 1137 | switch (token_ptr.id) { | 1042 | switch (token_ptr.id) { |
| 1138 | Token.Id.Keyword_var, Token.Id.Keyword_const => { | 1043 | Token.Id.Keyword_var, |
| 1139 | stack.append(State { | 1044 | Token.Id.Keyword_const => { |
| 1140 | .VarDecl = VarDeclCtx { | 1045 | stack.append(State{ .VarDecl = VarDeclCtx{ |
| 1141 | .comments = null, | 1046 | .comments = null, |
| 1142 | .visib_token = null, | 1047 | .visib_token = null, |
| 1143 | .comptime_token = ctx.comptime_token, | 1048 | .comptime_token = ctx.comptime_token, |
| 1144 | .extern_export_token = null, | 1049 | .extern_export_token = null, |
| 1145 | .lib_name = null, | 1050 | .lib_name = null, |
| 1146 | .mut_token = token_index, | 1051 | .mut_token = token_index, |
| 1147 | .list = &ctx.block.statements, | 1052 | .list = &ctx.block.statements, |
| 1148 | } | 1053 | } }) catch unreachable; |
| 1149 | }) catch unreachable; | | |
| 1150 | continue; | 1054 | continue; |
| 1151 | }, | 1055 | }, |
| 1152 | else => { | 1056 | else => { |
| 1153 | putBackToken(&tok_it, &tree); | 1057 | putBackToken(&tok_it, &tree); |
| 1154 | putBackToken(&tok_it, &tree); | 1058 | putBackToken(&tok_it, &tree); |
| 1155 | const statement = try ctx.block.statements.addOne(); | 1059 | const statement = try ctx.block.statements.addOne(); |
| 1156 | try stack.append(State { .Semicolon = statement }); | 1060 | try stack.append(State{ .Semicolon = statement }); |
| 1157 | try stack.append(State { .Expression = OptionalCtx { .Required = statement } }); | 1061 | try stack.append(State{ .Expression = OptionalCtx{ .Required = statement } }); |
| 1158 | continue; | 1062 | continue; |
| 1159 | } | 1063 | }, |
| 1160 | } | 1064 | } |
| 1161 | }, | 1065 | }, |
| 1162 | State.Semicolon => |node_ptr| { | 1066 | State.Semicolon => |node_ptr| { |
| 1163 | const node = *node_ptr; | 1067 | const node = node_ptr.*; |
| 1164 | if (node.requireSemiColon()) { | 1068 | if (node.requireSemiColon()) { |
| 1165 | stack.append(State { .ExpectToken = Token.Id.Semicolon }) catch unreachable; | 1069 | stack.append(State{ .ExpectToken = Token.Id.Semicolon }) catch unreachable; |
| 1166 | continue; | 1070 | continue; |
| 1167 | } | 1071 | } |
| 1168 | continue; | 1072 | continue; |
| ... | @@ -1177,22 +1081,22 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1177,22 +1081,22 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1177 | continue; | 1081 | continue; |
| 1178 | } | 1082 | } |
| 1179 | | 1083 | |
| 1180 | const node = try arena.construct(ast.Node.AsmOutput { | 1084 | const node = try arena.construct(ast.Node.AsmOutput{ |
| 1181 | .base = ast.Node {.id = ast.Node.Id.AsmOutput }, | 1085 | .base = ast.Node{ .id = ast.Node.Id.AsmOutput }, |
| 1182 | .symbolic_name = undefined, | 1086 | .symbolic_name = undefined, |
| 1183 | .constraint = undefined, | 1087 | .constraint = undefined, |
| 1184 | .kind = undefined, | 1088 | .kind = undefined, |
| 1185 | }); | 1089 | }); |
| 1186 | try items.push(node); | 1090 | try items.push(node); |
| 1187 | | 1091 | |
| 1188 | stack.append(State { .AsmOutputItems = items }) catch unreachable; | 1092 | stack.append(State{ .AsmOutputItems = items }) catch unreachable; |
| 1189 | try stack.append(State { .IfToken = Token.Id.Comma }); | 1093 | try stack.append(State{ .IfToken = Token.Id.Comma }); |
| 1190 | try stack.append(State { .ExpectToken = Token.Id.RParen }); | 1094 | try stack.append(State{ .ExpectToken = Token.Id.RParen }); |
| 1191 | try stack.append(State { .AsmOutputReturnOrType = node }); | 1095 | try stack.append(State{ .AsmOutputReturnOrType = node }); |
| 1192 | try stack.append(State { .ExpectToken = Token.Id.LParen }); | 1096 | try stack.append(State{ .ExpectToken = Token.Id.LParen }); |
| 1193 | try stack.append(State { .StringLiteral = OptionalCtx { .Required = &node.constraint } }); | 1097 | try stack.append(State{ .StringLiteral = OptionalCtx{ .Required = &node.constraint } }); |
| 1194 | try stack.append(State { .ExpectToken = Token.Id.RBracket }); | 1098 | try stack.append(State{ .ExpectToken = Token.Id.RBracket }); |
| 1195 | try stack.append(State { .Identifier = OptionalCtx { .Required = &node.symbolic_name } }); | 1099 | try stack.append(State{ .Identifier = OptionalCtx{ .Required = &node.symbolic_name } }); |
| 1196 | continue; | 1100 | continue; |
| 1197 | }, | 1101 | }, |
| 1198 | State.AsmOutputReturnOrType => |node| { | 1102 | State.AsmOutputReturnOrType => |node| { |
| ... | @@ -1201,20 +1105,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1201,20 +1105,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1201 | const token_ptr = token.ptr; | 1105 | const token_ptr = token.ptr; |
| 1202 | switch (token_ptr.id) { | 1106 | switch (token_ptr.id) { |
| 1203 | Token.Id.Identifier => { | 1107 | Token.Id.Identifier => { |
| 1204 | node.kind = ast.Node.AsmOutput.Kind { .Variable = try createLiteral(arena, ast.Node.Identifier, token_index) }; | 1108 | node.kind = ast.Node.AsmOutput.Kind{ .Variable = try createLiteral(arena, ast.Node.Identifier, token_index) }; |
| 1205 | continue; | 1109 | continue; |
| 1206 | }, | 1110 | }, |
| 1207 | Token.Id.Arrow => { | 1111 | Token.Id.Arrow => { |
| 1208 | node.kind = ast.Node.AsmOutput.Kind { .Return = undefined }; | 1112 | node.kind = ast.Node.AsmOutput.Kind{ .Return = undefined }; |
| 1209 | try stack.append(State { .TypeExprBegin = OptionalCtx { .Required = &node.kind.Return } }); | 1113 | try stack.append(State{ .TypeExprBegin = OptionalCtx{ .Required = &node.kind.Return } }); |
| 1210 | continue; | 1114 | continue; |
| 1211 | }, | 1115 | }, |
| 1212 | else => { | 1116 | else => { |
| 1213 | *(try tree.errors.addOne()) = Error { | 1117 | ((try tree.errors.addOne())).* = Error{ .ExpectedAsmOutputReturnOrType = Error.ExpectedAsmOutputReturnOrType{ .token = token_index } }; |
| 1214 | .ExpectedAsmOutputReturnOrType = Error.ExpectedAsmOutputReturnOrType { | | |
| 1215 | .token = token_index, | | |
| 1216 | }, | | |
| 1217 | }; | | |
| 1218 | return tree; | 1118 | return tree; |
| 1219 | }, | 1119 | }, |
| 1220 | } | 1120 | } |
| ... | @@ -1228,49 +1128,48 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1228,49 +1128,48 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1228 | continue; | 1128 | continue; |
| 1229 | } | 1129 | } |
| 1230 | | 1130 | |
| 1231 | const node = try arena.construct(ast.Node.AsmInput { | 1131 | const node = try arena.construct(ast.Node.AsmInput{ |
| 1232 | .base = ast.Node {.id = ast.Node.Id.AsmInput }, | 1132 | .base = ast.Node{ .id = ast.Node.Id.AsmInput }, |
| 1233 | .symbolic_name = undefined, | 1133 | .symbolic_name = undefined, |
| 1234 | .constraint = undefined, | 1134 | .constraint = undefined, |
| 1235 | .expr = undefined, | 1135 | .expr = undefined, |
| 1236 | }); | 1136 | }); |
| 1237 | try items.push(node); | 1137 | try items.push(node); |
| 1238 | | 1138 | |
| 1239 | stack.append(State { .AsmInputItems = items }) catch unreachable; | 1139 | stack.append(State{ .AsmInputItems = items }) catch unreachable; |
| 1240 | try stack.append(State { .IfToken = Token.Id.Comma }); | 1140 | try stack.append(State{ .IfToken = Token.Id.Comma }); |
| 1241 | try stack.append(State { .ExpectToken = Token.Id.RParen }); | 1141 | try stack.append(State{ .ExpectToken = Token.Id.RParen }); |
| 1242 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.expr } }); | 1142 | try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.expr } }); |
| 1243 | try stack.append(State { .ExpectToken = Token.Id.LParen }); | 1143 | try stack.append(State{ .ExpectToken = Token.Id.LParen }); |
| 1244 | try stack.append(State { .StringLiteral = OptionalCtx { .Required = &node.constraint } }); | 1144 | try stack.append(State{ .StringLiteral = OptionalCtx{ .Required = &node.constraint } }); |
| 1245 | try stack.append(State { .ExpectToken = Token.Id.RBracket }); | 1145 | try stack.append(State{ .ExpectToken = Token.Id.RBracket }); |
| 1246 | try stack.append(State { .Identifier = OptionalCtx { .Required = &node.symbolic_name } }); | 1146 | try stack.append(State{ .Identifier = OptionalCtx{ .Required = &node.symbolic_name } }); |
| 1247 | continue; | 1147 | continue; |
| 1248 | }, | 1148 | }, |
| 1249 | State.AsmClobberItems => |items| { | 1149 | State.AsmClobberItems => |items| { |
| 1250 | stack.append(State { .AsmClobberItems = items }) catch unreachable; | 1150 | stack.append(State{ .AsmClobberItems = items }) catch unreachable; |
| 1251 | try stack.append(State { .IfToken = Token.Id.Comma }); | 1151 | try stack.append(State{ .IfToken = Token.Id.Comma }); |
| 1252 | try stack.append(State { .StringLiteral = OptionalCtx { .Required = try items.addOne() } }); | 1152 | try stack.append(State{ .StringLiteral = OptionalCtx{ .Required = try items.addOne() } }); |
| 1253 | continue; | 1153 | continue; |
| 1254 | }, | 1154 | }, |
| 1255 | | 1155 | |
| 1256 | | | |
| 1257 | State.ExprListItemOrEnd => |list_state| { | 1156 | State.ExprListItemOrEnd => |list_state| { |
| 1258 | if (eatToken(&tok_it, &tree, list_state.end)) |token_index| { | 1157 | if (eatToken(&tok_it, &tree, list_state.end)) |token_index| { |
| 1259 | *list_state.ptr = token_index; | 1158 | (list_state.ptr).* = token_index; |
| 1260 | continue; | 1159 | continue; |
| 1261 | } | 1160 | } |
| 1262 | | 1161 | |
| 1263 | stack.append(State { .ExprListCommaOrEnd = list_state }) catch unreachable; | 1162 | stack.append(State{ .ExprListCommaOrEnd = list_state }) catch unreachable; |
| 1264 | try stack.append(State { .Expression = OptionalCtx { .Required = try list_state.list.addOne() } }); | 1163 | try stack.append(State{ .Expression = OptionalCtx{ .Required = try list_state.list.addOne() } }); |
| 1265 | continue; | 1164 | continue; |
| 1266 | }, | 1165 | }, |
| 1267 | State.ExprListCommaOrEnd => |list_state| { | 1166 | State.ExprListCommaOrEnd => |list_state| { |
| 1268 | switch (expectCommaOrEnd(&tok_it, &tree, list_state.end)) { | 1167 | switch (expectCommaOrEnd(&tok_it, &tree, list_state.end)) { |
| 1269 | ExpectCommaOrEndResult.end_token => |maybe_end| if (maybe_end) |end| { | 1168 | ExpectCommaOrEndResult.end_token => |maybe_end| if (maybe_end) |end| { |
| 1270 | *list_state.ptr = end; | 1169 | (list_state.ptr).* = end; |
| 1271 | continue; | 1170 | continue; |
| 1272 | } else { | 1171 | } else { |
| 1273 | stack.append(State { .ExprListItemOrEnd = list_state }) catch unreachable; | 1172 | stack.append(State{ .ExprListItemOrEnd = list_state }) catch unreachable; |
| 1274 | continue; | 1173 | continue; |
| 1275 | }, | 1174 | }, |
| 1276 | ExpectCommaOrEndResult.parse_error => |e| { | 1175 | ExpectCommaOrEndResult.parse_error => |e| { |
| ... | @@ -1285,44 +1184,38 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1285,44 +1184,38 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1285 | } | 1184 | } |
| 1286 | | 1185 | |
| 1287 | if (eatToken(&tok_it, &tree, Token.Id.RBrace)) |rbrace| { | 1186 | if (eatToken(&tok_it, &tree, Token.Id.RBrace)) |rbrace| { |
| 1288 | *list_state.ptr = rbrace; | 1187 | (list_state.ptr).* = rbrace; |
| 1289 | continue; | 1188 | continue; |
| 1290 | } | 1189 | } |
| 1291 | | 1190 | |
| 1292 | const node = try arena.construct(ast.Node.FieldInitializer { | 1191 | const node = try arena.construct(ast.Node.FieldInitializer{ |
| 1293 | .base = ast.Node { | 1192 | .base = ast.Node{ .id = ast.Node.Id.FieldInitializer }, |
| 1294 | .id = ast.Node.Id.FieldInitializer, | | |
| 1295 | }, | | |
| 1296 | .period_token = undefined, | 1193 | .period_token = undefined, |
| 1297 | .name_token = undefined, | 1194 | .name_token = undefined, |
| 1298 | .expr = undefined, | 1195 | .expr = undefined, |
| 1299 | }); | 1196 | }); |
| 1300 | try list_state.list.push(&node.base); | 1197 | try list_state.list.push(&node.base); |
| 1301 | | 1198 | |
| 1302 | stack.append(State { .FieldInitListCommaOrEnd = list_state }) catch unreachable; | 1199 | stack.append(State{ .FieldInitListCommaOrEnd = list_state }) catch unreachable; |
| 1303 | try stack.append(State { .Expression = OptionalCtx{ .Required = &node.expr } }); | 1200 | try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.expr } }); |
| 1304 | try stack.append(State { .ExpectToken = Token.Id.Equal }); | 1201 | try stack.append(State{ .ExpectToken = Token.Id.Equal }); |
| 1305 | try stack.append(State { | 1202 | try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{ |
| 1306 | .ExpectTokenSave = ExpectTokenSave { | 1203 | .id = Token.Id.Identifier, |
| 1307 | .id = Token.Id.Identifier, | 1204 | .ptr = &node.name_token, |
| 1308 | .ptr = &node.name_token, | 1205 | } }); |
| 1309 | } | 1206 | try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{ |
| 1310 | }); | 1207 | .id = Token.Id.Period, |
| 1311 | try stack.append(State { | 1208 | .ptr = &node.period_token, |
| 1312 | .ExpectTokenSave = ExpectTokenSave { | 1209 | } }); |
| 1313 | .id = Token.Id.Period, | | |
| 1314 | .ptr = &node.period_token, | | |
| 1315 | } | | |
| 1316 | }); | | |
| 1317 | continue; | 1210 | continue; |
| 1318 | }, | 1211 | }, |
| 1319 | State.FieldInitListCommaOrEnd => |list_state| { | 1212 | State.FieldInitListCommaOrEnd => |list_state| { |
| 1320 | switch (expectCommaOrEnd(&tok_it, &tree, Token.Id.RBrace)) { | 1213 | switch (expectCommaOrEnd(&tok_it, &tree, Token.Id.RBrace)) { |
| 1321 | ExpectCommaOrEndResult.end_token => |maybe_end| if (maybe_end) |end| { | 1214 | ExpectCommaOrEndResult.end_token => |maybe_end| if (maybe_end) |end| { |
| 1322 | *list_state.ptr = end; | 1215 | (list_state.ptr).* = end; |
| 1323 | continue; | 1216 | continue; |
| 1324 | } else { | 1217 | } else { |
| 1325 | stack.append(State { .FieldInitListItemOrEnd = list_state }) catch unreachable; | 1218 | stack.append(State{ .FieldInitListItemOrEnd = list_state }) catch unreachable; |
| 1326 | continue; | 1219 | continue; |
| 1327 | }, | 1220 | }, |
| 1328 | ExpectCommaOrEndResult.parse_error => |e| { | 1221 | ExpectCommaOrEndResult.parse_error => |e| { |
| ... | @@ -1337,7 +1230,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1337,7 +1230,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1337 | container_decl.rbrace_token = end; | 1230 | container_decl.rbrace_token = end; |
| 1338 | continue; | 1231 | continue; |
| 1339 | } else { | 1232 | } else { |
| 1340 | try stack.append(State { .ContainerDecl = container_decl }); | 1233 | try stack.append(State{ .ContainerDecl = container_decl }); |
| 1341 | continue; | 1234 | continue; |
| 1342 | }, | 1235 | }, |
| 1343 | ExpectCommaOrEndResult.parse_error => |e| { | 1236 | ExpectCommaOrEndResult.parse_error => |e| { |
| ... | @@ -1352,23 +1245,23 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1352,23 +1245,23 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1352 | } | 1245 | } |
| 1353 | | 1246 | |
| 1354 | if (eatToken(&tok_it, &tree, Token.Id.RBrace)) |rbrace| { | 1247 | if (eatToken(&tok_it, &tree, Token.Id.RBrace)) |rbrace| { |
| 1355 | *list_state.ptr = rbrace; | 1248 | (list_state.ptr).* = rbrace; |
| 1356 | continue; | 1249 | continue; |
| 1357 | } | 1250 | } |
| 1358 | | 1251 | |
| 1359 | const node_ptr = try list_state.list.addOne(); | 1252 | const node_ptr = try list_state.list.addOne(); |
| 1360 | | 1253 | |
| 1361 | try stack.append(State { .ErrorTagListCommaOrEnd = list_state }); | 1254 | try stack.append(State{ .ErrorTagListCommaOrEnd = list_state }); |
| 1362 | try stack.append(State { .ErrorTag = node_ptr }); | 1255 | try stack.append(State{ .ErrorTag = node_ptr }); |
| 1363 | continue; | 1256 | continue; |
| 1364 | }, | 1257 | }, |
| 1365 | State.ErrorTagListCommaOrEnd => |list_state| { | 1258 | State.ErrorTagListCommaOrEnd => |list_state| { |
| 1366 | switch (expectCommaOrEnd(&tok_it, &tree, Token.Id.RBrace)) { | 1259 | switch (expectCommaOrEnd(&tok_it, &tree, Token.Id.RBrace)) { |
| 1367 | ExpectCommaOrEndResult.end_token => |maybe_end| if (maybe_end) |end| { | 1260 | ExpectCommaOrEndResult.end_token => |maybe_end| if (maybe_end) |end| { |
| 1368 | *list_state.ptr = end; | 1261 | (list_state.ptr).* = end; |
| 1369 | continue; | 1262 | continue; |
| 1370 | } else { | 1263 | } else { |
| 1371 | stack.append(State { .ErrorTagListItemOrEnd = list_state }) catch unreachable; | 1264 | stack.append(State{ .ErrorTagListItemOrEnd = list_state }) catch unreachable; |
| 1372 | continue; | 1265 | continue; |
| 1373 | }, | 1266 | }, |
| 1374 | ExpectCommaOrEndResult.parse_error => |e| { | 1267 | ExpectCommaOrEndResult.parse_error => |e| { |
| ... | @@ -1383,24 +1276,22 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1383,24 +1276,22 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1383 | } | 1276 | } |
| 1384 | | 1277 | |
| 1385 | if (eatToken(&tok_it, &tree, Token.Id.RBrace)) |rbrace| { | 1278 | if (eatToken(&tok_it, &tree, Token.Id.RBrace)) |rbrace| { |
| 1386 | *list_state.ptr = rbrace; | 1279 | (list_state.ptr).* = rbrace; |
| 1387 | continue; | 1280 | continue; |
| 1388 | } | 1281 | } |
| 1389 | | 1282 | |
| 1390 | const comments = try eatDocComments(arena, &tok_it, &tree); | 1283 | const comments = try eatDocComments(arena, &tok_it, &tree); |
| 1391 | const node = try arena.construct(ast.Node.SwitchCase { | 1284 | const node = try arena.construct(ast.Node.SwitchCase{ |
| 1392 | .base = ast.Node { | 1285 | .base = ast.Node{ .id = ast.Node.Id.SwitchCase }, |
| 1393 | .id = ast.Node.Id.SwitchCase, | | |
| 1394 | }, | | |
| 1395 | .items = ast.Node.SwitchCase.ItemList.init(arena), | 1286 | .items = ast.Node.SwitchCase.ItemList.init(arena), |
| 1396 | .payload = null, | 1287 | .payload = null, |
| 1397 | .expr = undefined, | 1288 | .expr = undefined, |
| 1398 | }); | 1289 | }); |
| 1399 | try list_state.list.push(&node.base); | 1290 | try list_state.list.push(&node.base); |
| 1400 | try stack.append(State { .SwitchCaseCommaOrEnd = list_state }); | 1291 | try stack.append(State{ .SwitchCaseCommaOrEnd = list_state }); |
| 1401 | try stack.append(State { .AssignmentExpressionBegin = OptionalCtx { .Required = &node.expr } }); | 1292 | try stack.append(State{ .AssignmentExpressionBegin = OptionalCtx{ .Required = &node.expr } }); |
| 1402 | try stack.append(State { .PointerPayload = OptionalCtx { .Optional = &node.payload } }); | 1293 | try stack.append(State{ .PointerPayload = OptionalCtx{ .Optional = &node.payload } }); |
| 1403 | try stack.append(State { .SwitchCaseFirstItem = &node.items }); | 1294 | try stack.append(State{ .SwitchCaseFirstItem = &node.items }); |
| 1404 | | 1295 | |
| 1405 | continue; | 1296 | continue; |
| 1406 | }, | 1297 | }, |
| ... | @@ -1408,10 +1299,10 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1408,10 +1299,10 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1408 | State.SwitchCaseCommaOrEnd => |list_state| { | 1299 | State.SwitchCaseCommaOrEnd => |list_state| { |
| 1409 | switch (expectCommaOrEnd(&tok_it, &tree, Token.Id.RParen)) { | 1300 | switch (expectCommaOrEnd(&tok_it, &tree, Token.Id.RParen)) { |
| 1410 | ExpectCommaOrEndResult.end_token => |maybe_end| if (maybe_end) |end| { | 1301 | ExpectCommaOrEndResult.end_token => |maybe_end| if (maybe_end) |end| { |
| 1411 | *list_state.ptr = end; | 1302 | (list_state.ptr).* = end; |
| 1412 | continue; | 1303 | continue; |
| 1413 | } else { | 1304 | } else { |
| 1414 | try stack.append(State { .SwitchCaseOrEnd = list_state }); | 1305 | try stack.append(State{ .SwitchCaseOrEnd = list_state }); |
| 1415 | continue; | 1306 | continue; |
| 1416 | }, | 1307 | }, |
| 1417 | ExpectCommaOrEndResult.parse_error => |e| { | 1308 | ExpectCommaOrEndResult.parse_error => |e| { |
| ... | @@ -1426,29 +1317,29 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1426,29 +1317,29 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1426 | const token_index = token.index; | 1317 | const token_index = token.index; |
| 1427 | const token_ptr = token.ptr; | 1318 | const token_ptr = token.ptr; |
| 1428 | if (token_ptr.id == Token.Id.Keyword_else) { | 1319 | if (token_ptr.id == Token.Id.Keyword_else) { |
| 1429 | const else_node = try arena.construct(ast.Node.SwitchElse { | 1320 | const else_node = try arena.construct(ast.Node.SwitchElse{ |
| 1430 | .base = ast.Node{ .id = ast.Node.Id.SwitchElse}, | 1321 | .base = ast.Node{ .id = ast.Node.Id.SwitchElse }, |
| 1431 | .token = token_index, | 1322 | .token = token_index, |
| 1432 | }); | 1323 | }); |
| 1433 | try case_items.push(&else_node.base); | 1324 | try case_items.push(&else_node.base); |
| 1434 | | 1325 | |
| 1435 | try stack.append(State { .ExpectToken = Token.Id.EqualAngleBracketRight }); | 1326 | try stack.append(State{ .ExpectToken = Token.Id.EqualAngleBracketRight }); |
| 1436 | continue; | 1327 | continue; |
| 1437 | } else { | 1328 | } else { |
| 1438 | putBackToken(&tok_it, &tree); | 1329 | putBackToken(&tok_it, &tree); |
| 1439 | try stack.append(State { .SwitchCaseItem = case_items }); | 1330 | try stack.append(State{ .SwitchCaseItem = case_items }); |
| 1440 | continue; | 1331 | continue; |
| 1441 | } | 1332 | } |
| 1442 | }, | 1333 | }, |
| 1443 | State.SwitchCaseItem => |case_items| { | 1334 | State.SwitchCaseItem => |case_items| { |
| 1444 | stack.append(State { .SwitchCaseItemCommaOrEnd = case_items }) catch unreachable; | 1335 | stack.append(State{ .SwitchCaseItemCommaOrEnd = case_items }) catch unreachable; |
| 1445 | try stack.append(State { .RangeExpressionBegin = OptionalCtx { .Required = try case_items.addOne() } }); | 1336 | try stack.append(State{ .RangeExpressionBegin = OptionalCtx{ .Required = try case_items.addOne() } }); |
| 1446 | }, | 1337 | }, |
| 1447 | State.SwitchCaseItemCommaOrEnd => |case_items| { | 1338 | State.SwitchCaseItemCommaOrEnd => |case_items| { |
| 1448 | switch (expectCommaOrEnd(&tok_it, &tree, Token.Id.EqualAngleBracketRight)) { | 1339 | switch (expectCommaOrEnd(&tok_it, &tree, Token.Id.EqualAngleBracketRight)) { |
| 1449 | ExpectCommaOrEndResult.end_token => |t| { | 1340 | ExpectCommaOrEndResult.end_token => |t| { |
| 1450 | if (t == null) { | 1341 | if (t == null) { |
| 1451 | stack.append(State { .SwitchCaseItem = case_items }) catch unreachable; | 1342 | stack.append(State{ .SwitchCaseItem = case_items }) catch unreachable; |
| 1452 | } | 1343 | } |
| 1453 | continue; | 1344 | continue; |
| 1454 | }, | 1345 | }, |
| ... | @@ -1460,10 +1351,9 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1460,10 +1351,9 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1460 | continue; | 1351 | continue; |
| 1461 | }, | 1352 | }, |
| 1462 | | 1353 | |
| 1463 | | | |
| 1464 | State.SuspendBody => |suspend_node| { | 1354 | State.SuspendBody => |suspend_node| { |
| 1465 | if (suspend_node.payload != null) { | 1355 | if (suspend_node.payload != null) { |
| 1466 | try stack.append(State { .AssignmentExpressionBegin = OptionalCtx { .RequiredNull = &suspend_node.body } }); | 1356 | try stack.append(State{ .AssignmentExpressionBegin = OptionalCtx{ .RequiredNull = &suspend_node.body } }); |
| 1467 | } | 1357 | } |
| 1468 | continue; | 1358 | continue; |
| 1469 | }, | 1359 | }, |
| ... | @@ -1473,13 +1363,11 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1473,13 +1363,11 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1473 | } | 1363 | } |
| 1474 | | 1364 | |
| 1475 | async_node.rangle_bracket = TokenIndex(0); | 1365 | async_node.rangle_bracket = TokenIndex(0); |
| 1476 | try stack.append(State { | 1366 | try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{ |
| 1477 | .ExpectTokenSave = ExpectTokenSave { | 1367 | .id = Token.Id.AngleBracketRight, |
| 1478 | .id = Token.Id.AngleBracketRight, | 1368 | .ptr = &??async_node.rangle_bracket, |
| 1479 | .ptr = &??async_node.rangle_bracket, | 1369 | } }); |
| 1480 | } | 1370 | try stack.append(State{ .TypeExprBegin = OptionalCtx{ .RequiredNull = &async_node.allocator_type } }); |
| 1481 | }); | | |
| 1482 | try stack.append(State { .TypeExprBegin = OptionalCtx { .RequiredNull = &async_node.allocator_type } }); | | |
| 1483 | continue; | 1371 | continue; |
| 1484 | }, | 1372 | }, |
| 1485 | State.AsyncEnd => |ctx| { | 1373 | State.AsyncEnd => |ctx| { |
| ... | @@ -1498,27 +1386,20 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1498,27 +1386,20 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1498 | continue; | 1386 | continue; |
| 1499 | } | 1387 | } |
| 1500 | | 1388 | |
| 1501 | *(try tree.errors.addOne()) = Error { | 1389 | ((try tree.errors.addOne())).* = Error{ .ExpectedCall = Error.ExpectedCall{ .node = node } }; |
| 1502 | .ExpectedCall = Error.ExpectedCall { .node = node }, | | |
| 1503 | }; | | |
| 1504 | return tree; | 1390 | return tree; |
| 1505 | }, | 1391 | }, |
| 1506 | else => { | 1392 | else => { |
| 1507 | *(try tree.errors.addOne()) = Error { | 1393 | ((try tree.errors.addOne())).* = Error{ .ExpectedCallOrFnProto = Error.ExpectedCallOrFnProto{ .node = node } }; |
| 1508 | .ExpectedCallOrFnProto = Error.ExpectedCallOrFnProto { .node = node }, | | |
| 1509 | }; | | |
| 1510 | return tree; | 1394 | return tree; |
| 1511 | } | 1395 | }, |
| 1512 | } | 1396 | } |
| 1513 | }, | 1397 | }, |
| 1514 | | 1398 | |
| 1515 | | | |
| 1516 | State.ExternType => |ctx| { | 1399 | State.ExternType => |ctx| { |
| 1517 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_fn)) |fn_token| { | 1400 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_fn)) |fn_token| { |
| 1518 | const fn_proto = try arena.construct(ast.Node.FnProto { | 1401 | const fn_proto = try arena.construct(ast.Node.FnProto{ |
| 1519 | .base = ast.Node { | 1402 | .base = ast.Node{ .id = ast.Node.Id.FnProto }, |
| 1520 | .id = ast.Node.Id.FnProto, | | |
| 1521 | }, | | |
| 1522 | .doc_comments = ctx.comments, | 1403 | .doc_comments = ctx.comments, |
| 1523 | .visib_token = null, | 1404 | .visib_token = null, |
| 1524 | .name_token = null, | 1405 | .name_token = null, |
| ... | @@ -1534,17 +1415,15 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1534,17 +1415,15 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1534 | .align_expr = null, | 1415 | .align_expr = null, |
| 1535 | }); | 1416 | }); |
| 1536 | ctx.opt_ctx.store(&fn_proto.base); | 1417 | ctx.opt_ctx.store(&fn_proto.base); |
| 1537 | stack.append(State { .FnProto = fn_proto }) catch unreachable; | 1418 | stack.append(State{ .FnProto = fn_proto }) catch unreachable; |
| 1538 | continue; | 1419 | continue; |
| 1539 | } | 1420 | } |
| 1540 | | 1421 | |
| 1541 | stack.append(State { | 1422 | stack.append(State{ .ContainerKind = ContainerKindCtx{ |
| 1542 | .ContainerKind = ContainerKindCtx { | 1423 | .opt_ctx = ctx.opt_ctx, |
| 1543 | .opt_ctx = ctx.opt_ctx, | 1424 | .ltoken = ctx.extern_token, |
| 1544 | .ltoken = ctx.extern_token, | 1425 | .layout = ast.Node.ContainerDecl.Layout.Extern, |
| 1545 | .layout = ast.Node.ContainerDecl.Layout.Extern, | 1426 | } }) catch unreachable; |
| 1546 | }, | | |
| 1547 | }) catch unreachable; | | |
| 1548 | continue; | 1427 | continue; |
| 1549 | }, | 1428 | }, |
| 1550 | State.SliceOrArrayAccess => |node| { | 1429 | State.SliceOrArrayAccess => |node| { |
| ... | @@ -1554,20 +1433,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1554,20 +1433,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1554 | switch (token_ptr.id) { | 1433 | switch (token_ptr.id) { |
| 1555 | Token.Id.Ellipsis2 => { | 1434 | Token.Id.Ellipsis2 => { |
| 1556 | const start = node.op.ArrayAccess; | 1435 | const start = node.op.ArrayAccess; |
| 1557 | node.op = ast.Node.SuffixOp.Op { | 1436 | node.op = ast.Node.SuffixOp.Op{ .Slice = ast.Node.SuffixOp.Op.Slice{ |
| 1558 | .Slice = ast.Node.SuffixOp.Op.Slice { | 1437 | .start = start, |
| 1559 | .start = start, | 1438 | .end = null, |
| 1560 | .end = null, | 1439 | } }; |
| 1561 | } | | |
| 1562 | }; | | |
| 1563 | | 1440 | |
| 1564 | stack.append(State { | 1441 | stack.append(State{ .ExpectTokenSave = ExpectTokenSave{ |
| 1565 | .ExpectTokenSave = ExpectTokenSave { | 1442 | .id = Token.Id.RBracket, |
| 1566 | .id = Token.Id.RBracket, | 1443 | .ptr = &node.rtoken, |
| 1567 | .ptr = &node.rtoken, | 1444 | } }) catch unreachable; |
| 1568 | } | 1445 | try stack.append(State{ .Expression = OptionalCtx{ .Optional = &node.op.Slice.end } }); |
| 1569 | }) catch unreachable; | | |
| 1570 | try stack.append(State { .Expression = OptionalCtx { .Optional = &node.op.Slice.end } }); | | |
| 1571 | continue; | 1446 | continue; |
| 1572 | }, | 1447 | }, |
| 1573 | Token.Id.RBracket => { | 1448 | Token.Id.RBracket => { |
| ... | @@ -1575,33 +1450,29 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1575,33 +1450,29 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1575 | continue; | 1450 | continue; |
| 1576 | }, | 1451 | }, |
| 1577 | else => { | 1452 | else => { |
| 1578 | *(try tree.errors.addOne()) = Error { | 1453 | ((try tree.errors.addOne())).* = Error{ .ExpectedSliceOrRBracket = Error.ExpectedSliceOrRBracket{ .token = token_index } }; |
| 1579 | .ExpectedSliceOrRBracket = Error.ExpectedSliceOrRBracket { .token = token_index }, | | |
| 1580 | }; | | |
| 1581 | return tree; | 1454 | return tree; |
| 1582 | } | 1455 | }, |
| 1583 | } | 1456 | } |
| 1584 | }, | 1457 | }, |
| 1585 | State.SliceOrArrayType => |node| { | 1458 | State.SliceOrArrayType => |node| { |
| 1586 | if (eatToken(&tok_it, &tree, Token.Id.RBracket)) |_| { | 1459 | if (eatToken(&tok_it, &tree, Token.Id.RBracket)) |_| { |
| 1587 | node.op = ast.Node.PrefixOp.Op { | 1460 | node.op = ast.Node.PrefixOp.Op{ .SliceType = ast.Node.PrefixOp.AddrOfInfo{ |
| 1588 | .SliceType = ast.Node.PrefixOp.AddrOfInfo { | 1461 | .align_expr = null, |
| 1589 | .align_expr = null, | 1462 | .bit_offset_start_token = null, |
| 1590 | .bit_offset_start_token = null, | 1463 | .bit_offset_end_token = null, |
| 1591 | .bit_offset_end_token = null, | 1464 | .const_token = null, |
| 1592 | .const_token = null, | 1465 | .volatile_token = null, |
| 1593 | .volatile_token = null, | 1466 | } }; |
| 1594 | } | 1467 | stack.append(State{ .TypeExprBegin = OptionalCtx{ .Required = &node.rhs } }) catch unreachable; |
| 1595 | }; | 1468 | try stack.append(State{ .AddrOfModifiers = &node.op.SliceType }); |
| 1596 | stack.append(State { .TypeExprBegin = OptionalCtx { .Required = &node.rhs } }) catch unreachable; | | |
| 1597 | try stack.append(State { .AddrOfModifiers = &node.op.SliceType }); | | |
| 1598 | continue; | 1469 | continue; |
| 1599 | } | 1470 | } |
| 1600 | | 1471 | |
| 1601 | node.op = ast.Node.PrefixOp.Op { .ArrayType = undefined }; | 1472 | node.op = ast.Node.PrefixOp.Op{ .ArrayType = undefined }; |
| 1602 | stack.append(State { .TypeExprBegin = OptionalCtx { .Required = &node.rhs } }) catch unreachable; | 1473 | stack.append(State{ .TypeExprBegin = OptionalCtx{ .Required = &node.rhs } }) catch unreachable; |
| 1603 | try stack.append(State { .ExpectToken = Token.Id.RBracket }); | 1474 | try stack.append(State{ .ExpectToken = Token.Id.RBracket }); |
| 1604 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.op.ArrayType } }); | 1475 | try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.op.ArrayType } }); |
| 1605 | continue; | 1476 | continue; |
| 1606 | }, | 1477 | }, |
| 1607 | State.AddrOfModifiers => |addr_of_info| { | 1478 | State.AddrOfModifiers => |addr_of_info| { |
| ... | @@ -1612,22 +1483,18 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1612,22 +1483,18 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1612 | Token.Id.Keyword_align => { | 1483 | Token.Id.Keyword_align => { |
| 1613 | stack.append(state) catch unreachable; | 1484 | stack.append(state) catch unreachable; |
| 1614 | if (addr_of_info.align_expr != null) { | 1485 | if (addr_of_info.align_expr != null) { |
| 1615 | *(try tree.errors.addOne()) = Error { | 1486 | ((try tree.errors.addOne())).* = Error{ .ExtraAlignQualifier = Error.ExtraAlignQualifier{ .token = token_index } }; |
| 1616 | .ExtraAlignQualifier = Error.ExtraAlignQualifier { .token = token_index }, | | |
| 1617 | }; | | |
| 1618 | return tree; | 1487 | return tree; |
| 1619 | } | 1488 | } |
| 1620 | try stack.append(State { .ExpectToken = Token.Id.RParen }); | 1489 | try stack.append(State{ .ExpectToken = Token.Id.RParen }); |
| 1621 | try stack.append(State { .Expression = OptionalCtx { .RequiredNull = &addr_of_info.align_expr} }); | 1490 | try stack.append(State{ .Expression = OptionalCtx{ .RequiredNull = &addr_of_info.align_expr } }); |
| 1622 | try stack.append(State { .ExpectToken = Token.Id.LParen }); | 1491 | try stack.append(State{ .ExpectToken = Token.Id.LParen }); |
| 1623 | continue; | 1492 | continue; |
| 1624 | }, | 1493 | }, |
| 1625 | Token.Id.Keyword_const => { | 1494 | Token.Id.Keyword_const => { |
| 1626 | stack.append(state) catch unreachable; | 1495 | stack.append(state) catch unreachable; |
| 1627 | if (addr_of_info.const_token != null) { | 1496 | if (addr_of_info.const_token != null) { |
| 1628 | *(try tree.errors.addOne()) = Error { | 1497 | ((try tree.errors.addOne())).* = Error{ .ExtraConstQualifier = Error.ExtraConstQualifier{ .token = token_index } }; |
| 1629 | .ExtraConstQualifier = Error.ExtraConstQualifier { .token = token_index }, | | |
| 1630 | }; | | |
| 1631 | return tree; | 1498 | return tree; |
| 1632 | } | 1499 | } |
| 1633 | addr_of_info.const_token = token_index; | 1500 | addr_of_info.const_token = token_index; |
| ... | @@ -1636,9 +1503,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1636,9 +1503,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1636 | Token.Id.Keyword_volatile => { | 1503 | Token.Id.Keyword_volatile => { |
| 1637 | stack.append(state) catch unreachable; | 1504 | stack.append(state) catch unreachable; |
| 1638 | if (addr_of_info.volatile_token != null) { | 1505 | if (addr_of_info.volatile_token != null) { |
| 1639 | *(try tree.errors.addOne()) = Error { | 1506 | ((try tree.errors.addOne())).* = Error{ .ExtraVolatileQualifier = Error.ExtraVolatileQualifier{ .token = token_index } }; |
| 1640 | .ExtraVolatileQualifier = Error.ExtraVolatileQualifier { .token = token_index }, | | |
| 1641 | }; | | |
| 1642 | return tree; | 1507 | return tree; |
| 1643 | } | 1508 | } |
| 1644 | addr_of_info.volatile_token = token_index; | 1509 | addr_of_info.volatile_token = token_index; |
| ... | @@ -1651,19 +1516,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1651,19 +1516,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1651 | } | 1516 | } |
| 1652 | }, | 1517 | }, |
| 1653 | | 1518 | |
| 1654 | | | |
| 1655 | State.Payload => |opt_ctx| { | 1519 | State.Payload => |opt_ctx| { |
| 1656 | const token = nextToken(&tok_it, &tree); | 1520 | const token = nextToken(&tok_it, &tree); |
| 1657 | const token_index = token.index; | 1521 | const token_index = token.index; |
| 1658 | const token_ptr = token.ptr; | 1522 | const token_ptr = token.ptr; |
| 1659 | if (token_ptr.id != Token.Id.Pipe) { | 1523 | if (token_ptr.id != Token.Id.Pipe) { |
| 1660 | if (opt_ctx != OptionalCtx.Optional) { | 1524 | if (opt_ctx != OptionalCtx.Optional) { |
| 1661 | *(try tree.errors.addOne()) = Error { | 1525 | ((try tree.errors.addOne())).* = Error{ .ExpectedToken = Error.ExpectedToken{ |
| 1662 | .ExpectedToken = Error.ExpectedToken { | 1526 | .token = token_index, |
| 1663 | .token = token_index, | 1527 | .expected_id = Token.Id.Pipe, |
| 1664 | .expected_id = Token.Id.Pipe, | 1528 | } }; |
| 1665 | }, | | |
| 1666 | }; | | |
| 1667 | return tree; | 1529 | return tree; |
| 1668 | } | 1530 | } |
| 1669 | | 1531 | |
| ... | @@ -1671,21 +1533,19 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1671,21 +1533,19 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1671 | continue; | 1533 | continue; |
| 1672 | } | 1534 | } |
| 1673 | | 1535 | |
| 1674 | const node = try arena.construct(ast.Node.Payload { | 1536 | const node = try arena.construct(ast.Node.Payload{ |
| 1675 | .base = ast.Node {.id = ast.Node.Id.Payload }, | 1537 | .base = ast.Node{ .id = ast.Node.Id.Payload }, |
| 1676 | .lpipe = token_index, | 1538 | .lpipe = token_index, |
| 1677 | .error_symbol = undefined, | 1539 | .error_symbol = undefined, |
| 1678 | .rpipe = undefined | 1540 | .rpipe = undefined, |
| 1679 | }); | 1541 | }); |
| 1680 | opt_ctx.store(&node.base); | 1542 | opt_ctx.store(&node.base); |
| 1681 | | 1543 | |
| 1682 | stack.append(State { | 1544 | stack.append(State{ .ExpectTokenSave = ExpectTokenSave{ |
| 1683 | .ExpectTokenSave = ExpectTokenSave { | 1545 | .id = Token.Id.Pipe, |
| 1684 | .id = Token.Id.Pipe, | 1546 | .ptr = &node.rpipe, |
| 1685 | .ptr = &node.rpipe, | 1547 | } }) catch unreachable; |
| 1686 | } | 1548 | try stack.append(State{ .Identifier = OptionalCtx{ .Required = &node.error_symbol } }); |
| 1687 | }) catch unreachable; | | |
| 1688 | try stack.append(State { .Identifier = OptionalCtx { .Required = &node.error_symbol } }); | | |
| 1689 | continue; | 1549 | continue; |
| 1690 | }, | 1550 | }, |
| 1691 | State.PointerPayload => |opt_ctx| { | 1551 | State.PointerPayload => |opt_ctx| { |
| ... | @@ -1694,12 +1554,10 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1694,12 +1554,10 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1694 | const token_ptr = token.ptr; | 1554 | const token_ptr = token.ptr; |
| 1695 | if (token_ptr.id != Token.Id.Pipe) { | 1555 | if (token_ptr.id != Token.Id.Pipe) { |
| 1696 | if (opt_ctx != OptionalCtx.Optional) { | 1556 | if (opt_ctx != OptionalCtx.Optional) { |
| 1697 | *(try tree.errors.addOne()) = Error { | 1557 | ((try tree.errors.addOne())).* = Error{ .ExpectedToken = Error.ExpectedToken{ |
| 1698 | .ExpectedToken = Error.ExpectedToken { | 1558 | .token = token_index, |
| 1699 | .token = token_index, | 1559 | .expected_id = Token.Id.Pipe, |
| 1700 | .expected_id = Token.Id.Pipe, | 1560 | } }; |
| 1701 | }, | | |
| 1702 | }; | | |
| 1703 | return tree; | 1561 | return tree; |
| 1704 | } | 1562 | } |
| 1705 | | 1563 | |
| ... | @@ -1707,28 +1565,24 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1707,28 +1565,24 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1707 | continue; | 1565 | continue; |
| 1708 | } | 1566 | } |
| 1709 | | 1567 | |
| 1710 | const node = try arena.construct(ast.Node.PointerPayload { | 1568 | const node = try arena.construct(ast.Node.PointerPayload{ |
| 1711 | .base = ast.Node {.id = ast.Node.Id.PointerPayload }, | 1569 | .base = ast.Node{ .id = ast.Node.Id.PointerPayload }, |
| 1712 | .lpipe = token_index, | 1570 | .lpipe = token_index, |
| 1713 | .ptr_token = null, | 1571 | .ptr_token = null, |
| 1714 | .value_symbol = undefined, | 1572 | .value_symbol = undefined, |
| 1715 | .rpipe = undefined | 1573 | .rpipe = undefined, |
| 1716 | }); | 1574 | }); |
| 1717 | opt_ctx.store(&node.base); | 1575 | opt_ctx.store(&node.base); |
| 1718 | | 1576 | |
| 1719 | try stack.append(State { | 1577 | try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{ |
| 1720 | .ExpectTokenSave = ExpectTokenSave { | 1578 | .id = Token.Id.Pipe, |
| 1721 | .id = Token.Id.Pipe, | 1579 | .ptr = &node.rpipe, |
| 1722 | .ptr = &node.rpipe, | 1580 | } }); |
| 1723 | } | 1581 | try stack.append(State{ .Identifier = OptionalCtx{ .Required = &node.value_symbol } }); |
| 1724 | }); | 1582 | try stack.append(State{ .OptionalTokenSave = OptionalTokenSave{ |
| 1725 | try stack.append(State { .Identifier = OptionalCtx { .Required = &node.value_symbol } }); | 1583 | .id = Token.Id.Asterisk, |
| 1726 | try stack.append(State { | 1584 | .ptr = &node.ptr_token, |
| 1727 | .OptionalTokenSave = OptionalTokenSave { | 1585 | } }); |
| 1728 | .id = Token.Id.Asterisk, | | |
| 1729 | .ptr = &node.ptr_token, | | |
| 1730 | } | | |
| 1731 | }); | | |
| 1732 | continue; | 1586 | continue; |
| 1733 | }, | 1587 | }, |
| 1734 | State.PointerIndexPayload => |opt_ctx| { | 1588 | State.PointerIndexPayload => |opt_ctx| { |
| ... | @@ -1737,12 +1591,10 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1737,12 +1591,10 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1737 | const token_ptr = token.ptr; | 1591 | const token_ptr = token.ptr; |
| 1738 | if (token_ptr.id != Token.Id.Pipe) { | 1592 | if (token_ptr.id != Token.Id.Pipe) { |
| 1739 | if (opt_ctx != OptionalCtx.Optional) { | 1593 | if (opt_ctx != OptionalCtx.Optional) { |
| 1740 | *(try tree.errors.addOne()) = Error { | 1594 | ((try tree.errors.addOne())).* = Error{ .ExpectedToken = Error.ExpectedToken{ |
| 1741 | .ExpectedToken = Error.ExpectedToken { | 1595 | .token = token_index, |
| 1742 | .token = token_index, | 1596 | .expected_id = Token.Id.Pipe, |
| 1743 | .expected_id = Token.Id.Pipe, | 1597 | } }; |
| 1744 | }, | | |
| 1745 | }; | | |
| 1746 | return tree; | 1598 | return tree; |
| 1747 | } | 1599 | } |
| 1748 | | 1600 | |
| ... | @@ -1750,61 +1602,58 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1750,61 +1602,58 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1750 | continue; | 1602 | continue; |
| 1751 | } | 1603 | } |
| 1752 | | 1604 | |
| 1753 | const node = try arena.construct(ast.Node.PointerIndexPayload { | 1605 | const node = try arena.construct(ast.Node.PointerIndexPayload{ |
| 1754 | .base = ast.Node {.id = ast.Node.Id.PointerIndexPayload }, | 1606 | .base = ast.Node{ .id = ast.Node.Id.PointerIndexPayload }, |
| 1755 | .lpipe = token_index, | 1607 | .lpipe = token_index, |
| 1756 | .ptr_token = null, | 1608 | .ptr_token = null, |
| 1757 | .value_symbol = undefined, | 1609 | .value_symbol = undefined, |
| 1758 | .index_symbol = null, | 1610 | .index_symbol = null, |
| 1759 | .rpipe = undefined | 1611 | .rpipe = undefined, |
| 1760 | }); | 1612 | }); |
| 1761 | opt_ctx.store(&node.base); | 1613 | opt_ctx.store(&node.base); |
| 1762 | | 1614 | |
| 1763 | stack.append(State { | 1615 | stack.append(State{ .ExpectTokenSave = ExpectTokenSave{ |
| 1764 | .ExpectTokenSave = ExpectTokenSave { | 1616 | .id = Token.Id.Pipe, |
| 1765 | .id = Token.Id.Pipe, | 1617 | .ptr = &node.rpipe, |
| 1766 | .ptr = &node.rpipe, | 1618 | } }) catch unreachable; |
| 1767 | } | 1619 | try stack.append(State{ .Identifier = OptionalCtx{ .RequiredNull = &node.index_symbol } }); |
| 1768 | }) catch unreachable; | 1620 | try stack.append(State{ .IfToken = Token.Id.Comma }); |
| 1769 | try stack.append(State { .Identifier = OptionalCtx { .RequiredNull = &node.index_symbol } }); | 1621 | try stack.append(State{ .Identifier = OptionalCtx{ .Required = &node.value_symbol } }); |
| 1770 | try stack.append(State { .IfToken = Token.Id.Comma }); | 1622 | try stack.append(State{ .OptionalTokenSave = OptionalTokenSave{ |
| 1771 | try stack.append(State { .Identifier = OptionalCtx { .Required = &node.value_symbol } }); | 1623 | .id = Token.Id.Asterisk, |
| 1772 | try stack.append(State { | 1624 | .ptr = &node.ptr_token, |
| 1773 | .OptionalTokenSave = OptionalTokenSave { | 1625 | } }); |
| 1774 | .id = Token.Id.Asterisk, | | |
| 1775 | .ptr = &node.ptr_token, | | |
| 1776 | } | | |
| 1777 | }); | | |
| 1778 | continue; | 1626 | continue; |
| 1779 | }, | 1627 | }, |
| 1780 | | 1628 | |
| 1781 | | | |
| 1782 | State.Expression => |opt_ctx| { | 1629 | State.Expression => |opt_ctx| { |
| 1783 | const token = nextToken(&tok_it, &tree); | 1630 | const token = nextToken(&tok_it, &tree); |
| 1784 | const token_index = token.index; | 1631 | const token_index = token.index; |
| 1785 | const token_ptr = token.ptr; | 1632 | const token_ptr = token.ptr; |
| 1786 | switch (token_ptr.id) { | 1633 | switch (token_ptr.id) { |
| 1787 | Token.Id.Keyword_return, Token.Id.Keyword_break, Token.Id.Keyword_continue => { | 1634 | Token.Id.Keyword_return, |
| 1788 | const node = try arena.construct(ast.Node.ControlFlowExpression { | 1635 | Token.Id.Keyword_break, |
| 1789 | .base = ast.Node {.id = ast.Node.Id.ControlFlowExpression }, | 1636 | Token.Id.Keyword_continue => { |
| | 1637 | const node = try arena.construct(ast.Node.ControlFlowExpression{ |
| | 1638 | .base = ast.Node{ .id = ast.Node.Id.ControlFlowExpression }, |
| 1790 | .ltoken = token_index, | 1639 | .ltoken = token_index, |
| 1791 | .kind = undefined, | 1640 | .kind = undefined, |
| 1792 | .rhs = null, | 1641 | .rhs = null, |
| 1793 | }); | 1642 | }); |
| 1794 | opt_ctx.store(&node.base); | 1643 | opt_ctx.store(&node.base); |
| 1795 | | 1644 | |
| 1796 | stack.append(State { .Expression = OptionalCtx { .Optional = &node.rhs } }) catch unreachable; | 1645 | stack.append(State{ .Expression = OptionalCtx{ .Optional = &node.rhs } }) catch unreachable; |
| 1797 | | 1646 | |
| 1798 | switch (token_ptr.id) { | 1647 | switch (token_ptr.id) { |
| 1799 | Token.Id.Keyword_break => { | 1648 | Token.Id.Keyword_break => { |
| 1800 | node.kind = ast.Node.ControlFlowExpression.Kind { .Break = null }; | 1649 | node.kind = ast.Node.ControlFlowExpression.Kind{ .Break = null }; |
| 1801 | try stack.append(State { .Identifier = OptionalCtx { .RequiredNull = &node.kind.Break } }); | 1650 | try stack.append(State{ .Identifier = OptionalCtx{ .RequiredNull = &node.kind.Break } }); |
| 1802 | try stack.append(State { .IfToken = Token.Id.Colon }); | 1651 | try stack.append(State{ .IfToken = Token.Id.Colon }); |
| 1803 | }, | 1652 | }, |
| 1804 | Token.Id.Keyword_continue => { | 1653 | Token.Id.Keyword_continue => { |
| 1805 | node.kind = ast.Node.ControlFlowExpression.Kind { .Continue = null }; | 1654 | node.kind = ast.Node.ControlFlowExpression.Kind{ .Continue = null }; |
| 1806 | try stack.append(State { .Identifier = OptionalCtx { .RequiredNull = &node.kind.Continue } }); | 1655 | try stack.append(State{ .Identifier = OptionalCtx{ .RequiredNull = &node.kind.Continue } }); |
| 1807 | try stack.append(State { .IfToken = Token.Id.Colon }); | 1656 | try stack.append(State{ .IfToken = Token.Id.Colon }); |
| 1808 | }, | 1657 | }, |
| 1809 | Token.Id.Keyword_return => { | 1658 | Token.Id.Keyword_return => { |
| 1810 | node.kind = ast.Node.ControlFlowExpression.Kind.Return; | 1659 | node.kind = ast.Node.ControlFlowExpression.Kind.Return; |
| ... | @@ -1813,56 +1662,58 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1813,56 +1662,58 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1813 | } | 1662 | } |
| 1814 | continue; | 1663 | continue; |
| 1815 | }, | 1664 | }, |
| 1816 | Token.Id.Keyword_try, Token.Id.Keyword_cancel, Token.Id.Keyword_resume => { | 1665 | Token.Id.Keyword_try, |
| 1817 | const node = try arena.construct(ast.Node.PrefixOp { | 1666 | Token.Id.Keyword_cancel, |
| 1818 | .base = ast.Node {.id = ast.Node.Id.PrefixOp }, | 1667 | Token.Id.Keyword_resume => { |
| | 1668 | const node = try arena.construct(ast.Node.PrefixOp{ |
| | 1669 | .base = ast.Node{ .id = ast.Node.Id.PrefixOp }, |
| 1819 | .op_token = token_index, | 1670 | .op_token = token_index, |
| 1820 | .op = switch (token_ptr.id) { | 1671 | .op = switch (token_ptr.id) { |
| 1821 | Token.Id.Keyword_try => ast.Node.PrefixOp.Op { .Try = void{} }, | 1672 | Token.Id.Keyword_try => ast.Node.PrefixOp.Op{ .Try = void{} }, |
| 1822 | Token.Id.Keyword_cancel => ast.Node.PrefixOp.Op { .Cancel = void{} }, | 1673 | Token.Id.Keyword_cancel => ast.Node.PrefixOp.Op{ .Cancel = void{} }, |
| 1823 | Token.Id.Keyword_resume => ast.Node.PrefixOp.Op { .Resume = void{} }, | 1674 | Token.Id.Keyword_resume => ast.Node.PrefixOp.Op{ .Resume = void{} }, |
| 1824 | else => unreachable, | 1675 | else => unreachable, |
| 1825 | }, | 1676 | }, |
| 1826 | .rhs = undefined, | 1677 | .rhs = undefined, |
| 1827 | }); | 1678 | }); |
| 1828 | opt_ctx.store(&node.base); | 1679 | opt_ctx.store(&node.base); |
| 1829 | | 1680 | |
| 1830 | stack.append(State { .Expression = OptionalCtx { .Required = &node.rhs } }) catch unreachable; | 1681 | stack.append(State{ .Expression = OptionalCtx{ .Required = &node.rhs } }) catch unreachable; |
| 1831 | continue; | 1682 | continue; |
| 1832 | }, | 1683 | }, |
| 1833 | else => { | 1684 | else => { |
| 1834 | if (!try parseBlockExpr(&stack, arena, opt_ctx, token_ptr, token_index)) { | 1685 | if (!try parseBlockExpr(&stack, arena, opt_ctx, token_ptr, token_index)) { |
| 1835 | putBackToken(&tok_it, &tree); | 1686 | putBackToken(&tok_it, &tree); |
| 1836 | stack.append(State { .UnwrapExpressionBegin = opt_ctx }) catch unreachable; | 1687 | stack.append(State{ .UnwrapExpressionBegin = opt_ctx }) catch unreachable; |
| 1837 | } | 1688 | } |
| 1838 | continue; | 1689 | continue; |
| 1839 | } | 1690 | }, |
| 1840 | } | 1691 | } |
| 1841 | }, | 1692 | }, |
| 1842 | State.RangeExpressionBegin => |opt_ctx| { | 1693 | State.RangeExpressionBegin => |opt_ctx| { |
| 1843 | stack.append(State { .RangeExpressionEnd = opt_ctx }) catch unreachable; | 1694 | stack.append(State{ .RangeExpressionEnd = opt_ctx }) catch unreachable; |
| 1844 | try stack.append(State { .Expression = opt_ctx }); | 1695 | try stack.append(State{ .Expression = opt_ctx }); |
| 1845 | continue; | 1696 | continue; |
| 1846 | }, | 1697 | }, |
| 1847 | State.RangeExpressionEnd => |opt_ctx| { | 1698 | State.RangeExpressionEnd => |opt_ctx| { |
| 1848 | const lhs = opt_ctx.get() ?? continue; | 1699 | const lhs = opt_ctx.get() ?? continue; |
| 1849 | | 1700 | |
| 1850 | if (eatToken(&tok_it, &tree, Token.Id.Ellipsis3)) |ellipsis3| { | 1701 | if (eatToken(&tok_it, &tree, Token.Id.Ellipsis3)) |ellipsis3| { |
| 1851 | const node = try arena.construct(ast.Node.InfixOp { | 1702 | const node = try arena.construct(ast.Node.InfixOp{ |
| 1852 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, | 1703 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 1853 | .lhs = lhs, | 1704 | .lhs = lhs, |
| 1854 | .op_token = ellipsis3, | 1705 | .op_token = ellipsis3, |
| 1855 | .op = ast.Node.InfixOp.Op.Range, | 1706 | .op = ast.Node.InfixOp.Op.Range, |
| 1856 | .rhs = undefined, | 1707 | .rhs = undefined, |
| 1857 | }); | 1708 | }); |
| 1858 | opt_ctx.store(&node.base); | 1709 | opt_ctx.store(&node.base); |
| 1859 | stack.append(State { .Expression = OptionalCtx { .Required = &node.rhs } }) catch unreachable; | 1710 | stack.append(State{ .Expression = OptionalCtx{ .Required = &node.rhs } }) catch unreachable; |
| 1860 | continue; | 1711 | continue; |
| 1861 | } | 1712 | } |
| 1862 | }, | 1713 | }, |
| 1863 | State.AssignmentExpressionBegin => |opt_ctx| { | 1714 | State.AssignmentExpressionBegin => |opt_ctx| { |
| 1864 | stack.append(State { .AssignmentExpressionEnd = opt_ctx }) catch unreachable; | 1715 | stack.append(State{ .AssignmentExpressionEnd = opt_ctx }) catch unreachable; |
| 1865 | try stack.append(State { .Expression = opt_ctx }); | 1716 | try stack.append(State{ .Expression = opt_ctx }); |
| 1866 | continue; | 1717 | continue; |
| 1867 | }, | 1718 | }, |
| 1868 | | 1719 | |
| ... | @@ -1873,16 +1724,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1873,16 +1724,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1873 | const token_index = token.index; | 1724 | const token_index = token.index; |
| 1874 | const token_ptr = token.ptr; | 1725 | const token_ptr = token.ptr; |
| 1875 | if (tokenIdToAssignment(token_ptr.id)) |ass_id| { | 1726 | if (tokenIdToAssignment(token_ptr.id)) |ass_id| { |
| 1876 | const node = try arena.construct(ast.Node.InfixOp { | 1727 | const node = try arena.construct(ast.Node.InfixOp{ |
| 1877 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, | 1728 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 1878 | .lhs = lhs, | 1729 | .lhs = lhs, |
| 1879 | .op_token = token_index, | 1730 | .op_token = token_index, |
| 1880 | .op = ass_id, | 1731 | .op = ass_id, |
| 1881 | .rhs = undefined, | 1732 | .rhs = undefined, |
| 1882 | }); | 1733 | }); |
| 1883 | opt_ctx.store(&node.base); | 1734 | opt_ctx.store(&node.base); |
| 1884 | stack.append(State { .AssignmentExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 1735 | stack.append(State{ .AssignmentExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 1885 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.rhs } }); | 1736 | try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.rhs } }); |
| 1886 | continue; | 1737 | continue; |
| 1887 | } else { | 1738 | } else { |
| 1888 | putBackToken(&tok_it, &tree); | 1739 | putBackToken(&tok_it, &tree); |
| ... | @@ -1891,8 +1742,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1891,8 +1742,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1891 | }, | 1742 | }, |
| 1892 | | 1743 | |
| 1893 | State.UnwrapExpressionBegin => |opt_ctx| { | 1744 | State.UnwrapExpressionBegin => |opt_ctx| { |
| 1894 | stack.append(State { .UnwrapExpressionEnd = opt_ctx }) catch unreachable; | 1745 | stack.append(State{ .UnwrapExpressionEnd = opt_ctx }) catch unreachable; |
| 1895 | try stack.append(State { .BoolOrExpressionBegin = opt_ctx }); | 1746 | try stack.append(State{ .BoolOrExpressionBegin = opt_ctx }); |
| 1896 | continue; | 1747 | continue; |
| 1897 | }, | 1748 | }, |
| 1898 | | 1749 | |
| ... | @@ -1903,8 +1754,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1903,8 +1754,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1903 | const token_index = token.index; | 1754 | const token_index = token.index; |
| 1904 | const token_ptr = token.ptr; | 1755 | const token_ptr = token.ptr; |
| 1905 | if (tokenIdToUnwrapExpr(token_ptr.id)) |unwrap_id| { | 1756 | if (tokenIdToUnwrapExpr(token_ptr.id)) |unwrap_id| { |
| 1906 | const node = try arena.construct(ast.Node.InfixOp { | 1757 | const node = try arena.construct(ast.Node.InfixOp{ |
| 1907 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, | 1758 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 1908 | .lhs = lhs, | 1759 | .lhs = lhs, |
| 1909 | .op_token = token_index, | 1760 | .op_token = token_index, |
| 1910 | .op = unwrap_id, | 1761 | .op = unwrap_id, |
| ... | @@ -1912,11 +1763,11 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1912,11 +1763,11 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1912 | }); | 1763 | }); |
| 1913 | opt_ctx.store(&node.base); | 1764 | opt_ctx.store(&node.base); |
| 1914 | | 1765 | |
| 1915 | stack.append(State { .UnwrapExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 1766 | stack.append(State{ .UnwrapExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 1916 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.rhs } }); | 1767 | try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.rhs } }); |
| 1917 | | 1768 | |
| 1918 | if (node.op == ast.Node.InfixOp.Op.Catch) { | 1769 | if (node.op == ast.Node.InfixOp.Op.Catch) { |
| 1919 | try stack.append(State { .Payload = OptionalCtx { .Optional = &node.op.Catch } }); | 1770 | try stack.append(State{ .Payload = OptionalCtx{ .Optional = &node.op.Catch } }); |
| 1920 | } | 1771 | } |
| 1921 | continue; | 1772 | continue; |
| 1922 | } else { | 1773 | } else { |
| ... | @@ -1926,8 +1777,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1926,8 +1777,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1926 | }, | 1777 | }, |
| 1927 | | 1778 | |
| 1928 | State.BoolOrExpressionBegin => |opt_ctx| { | 1779 | State.BoolOrExpressionBegin => |opt_ctx| { |
| 1929 | stack.append(State { .BoolOrExpressionEnd = opt_ctx }) catch unreachable; | 1780 | stack.append(State{ .BoolOrExpressionEnd = opt_ctx }) catch unreachable; |
| 1930 | try stack.append(State { .BoolAndExpressionBegin = opt_ctx }); | 1781 | try stack.append(State{ .BoolAndExpressionBegin = opt_ctx }); |
| 1931 | continue; | 1782 | continue; |
| 1932 | }, | 1783 | }, |
| 1933 | | 1784 | |
| ... | @@ -1935,23 +1786,23 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1935,23 +1786,23 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1935 | const lhs = opt_ctx.get() ?? continue; | 1786 | const lhs = opt_ctx.get() ?? continue; |
| 1936 | | 1787 | |
| 1937 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_or)) |or_token| { | 1788 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_or)) |or_token| { |
| 1938 | const node = try arena.construct(ast.Node.InfixOp { | 1789 | const node = try arena.construct(ast.Node.InfixOp{ |
| 1939 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, | 1790 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 1940 | .lhs = lhs, | 1791 | .lhs = lhs, |
| 1941 | .op_token = or_token, | 1792 | .op_token = or_token, |
| 1942 | .op = ast.Node.InfixOp.Op.BoolOr, | 1793 | .op = ast.Node.InfixOp.Op.BoolOr, |
| 1943 | .rhs = undefined, | 1794 | .rhs = undefined, |
| 1944 | }); | 1795 | }); |
| 1945 | opt_ctx.store(&node.base); | 1796 | opt_ctx.store(&node.base); |
| 1946 | stack.append(State { .BoolOrExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 1797 | stack.append(State{ .BoolOrExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 1947 | try stack.append(State { .BoolAndExpressionBegin = OptionalCtx { .Required = &node.rhs } }); | 1798 | try stack.append(State{ .BoolAndExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); |
| 1948 | continue; | 1799 | continue; |
| 1949 | } | 1800 | } |
| 1950 | }, | 1801 | }, |
| 1951 | | 1802 | |
| 1952 | State.BoolAndExpressionBegin => |opt_ctx| { | 1803 | State.BoolAndExpressionBegin => |opt_ctx| { |
| 1953 | stack.append(State { .BoolAndExpressionEnd = opt_ctx }) catch unreachable; | 1804 | stack.append(State{ .BoolAndExpressionEnd = opt_ctx }) catch unreachable; |
| 1954 | try stack.append(State { .ComparisonExpressionBegin = opt_ctx }); | 1805 | try stack.append(State{ .ComparisonExpressionBegin = opt_ctx }); |
| 1955 | continue; | 1806 | continue; |
| 1956 | }, | 1807 | }, |
| 1957 | | 1808 | |
| ... | @@ -1959,23 +1810,23 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1959,23 +1810,23 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1959 | const lhs = opt_ctx.get() ?? continue; | 1810 | const lhs = opt_ctx.get() ?? continue; |
| 1960 | | 1811 | |
| 1961 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_and)) |and_token| { | 1812 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_and)) |and_token| { |
| 1962 | const node = try arena.construct(ast.Node.InfixOp { | 1813 | const node = try arena.construct(ast.Node.InfixOp{ |
| 1963 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, | 1814 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 1964 | .lhs = lhs, | 1815 | .lhs = lhs, |
| 1965 | .op_token = and_token, | 1816 | .op_token = and_token, |
| 1966 | .op = ast.Node.InfixOp.Op.BoolAnd, | 1817 | .op = ast.Node.InfixOp.Op.BoolAnd, |
| 1967 | .rhs = undefined, | 1818 | .rhs = undefined, |
| 1968 | }); | 1819 | }); |
| 1969 | opt_ctx.store(&node.base); | 1820 | opt_ctx.store(&node.base); |
| 1970 | stack.append(State { .BoolAndExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 1821 | stack.append(State{ .BoolAndExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 1971 | try stack.append(State { .ComparisonExpressionBegin = OptionalCtx { .Required = &node.rhs } }); | 1822 | try stack.append(State{ .ComparisonExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); |
| 1972 | continue; | 1823 | continue; |
| 1973 | } | 1824 | } |
| 1974 | }, | 1825 | }, |
| 1975 | | 1826 | |
| 1976 | State.ComparisonExpressionBegin => |opt_ctx| { | 1827 | State.ComparisonExpressionBegin => |opt_ctx| { |
| 1977 | stack.append(State { .ComparisonExpressionEnd = opt_ctx }) catch unreachable; | 1828 | stack.append(State{ .ComparisonExpressionEnd = opt_ctx }) catch unreachable; |
| 1978 | try stack.append(State { .BinaryOrExpressionBegin = opt_ctx }); | 1829 | try stack.append(State{ .BinaryOrExpressionBegin = opt_ctx }); |
| 1979 | continue; | 1830 | continue; |
| 1980 | }, | 1831 | }, |
| 1981 | | 1832 | |
| ... | @@ -1986,16 +1837,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -1986,16 +1837,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 1986 | const token_index = token.index; | 1837 | const token_index = token.index; |
| 1987 | const token_ptr = token.ptr; | 1838 | const token_ptr = token.ptr; |
| 1988 | if (tokenIdToComparison(token_ptr.id)) |comp_id| { | 1839 | if (tokenIdToComparison(token_ptr.id)) |comp_id| { |
| 1989 | const node = try arena.construct(ast.Node.InfixOp { | 1840 | const node = try arena.construct(ast.Node.InfixOp{ |
| 1990 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, | 1841 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 1991 | .lhs = lhs, | 1842 | .lhs = lhs, |
| 1992 | .op_token = token_index, | 1843 | .op_token = token_index, |
| 1993 | .op = comp_id, | 1844 | .op = comp_id, |
| 1994 | .rhs = undefined, | 1845 | .rhs = undefined, |
| 1995 | }); | 1846 | }); |
| 1996 | opt_ctx.store(&node.base); | 1847 | opt_ctx.store(&node.base); |
| 1997 | stack.append(State { .ComparisonExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 1848 | stack.append(State{ .ComparisonExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 1998 | try stack.append(State { .BinaryOrExpressionBegin = OptionalCtx { .Required = &node.rhs } }); | 1849 | try stack.append(State{ .BinaryOrExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); |
| 1999 | continue; | 1850 | continue; |
| 2000 | } else { | 1851 | } else { |
| 2001 | putBackToken(&tok_it, &tree); | 1852 | putBackToken(&tok_it, &tree); |
| ... | @@ -2004,8 +1855,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2004,8 +1855,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2004 | }, | 1855 | }, |
| 2005 | | 1856 | |
| 2006 | State.BinaryOrExpressionBegin => |opt_ctx| { | 1857 | State.BinaryOrExpressionBegin => |opt_ctx| { |
| 2007 | stack.append(State { .BinaryOrExpressionEnd = opt_ctx }) catch unreachable; | 1858 | stack.append(State{ .BinaryOrExpressionEnd = opt_ctx }) catch unreachable; |
| 2008 | try stack.append(State { .BinaryXorExpressionBegin = opt_ctx }); | 1859 | try stack.append(State{ .BinaryXorExpressionBegin = opt_ctx }); |
| 2009 | continue; | 1860 | continue; |
| 2010 | }, | 1861 | }, |
| 2011 | | 1862 | |
| ... | @@ -2013,23 +1864,23 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2013,23 +1864,23 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2013 | const lhs = opt_ctx.get() ?? continue; | 1864 | const lhs = opt_ctx.get() ?? continue; |
| 2014 | | 1865 | |
| 2015 | if (eatToken(&tok_it, &tree, Token.Id.Pipe)) |pipe| { | 1866 | if (eatToken(&tok_it, &tree, Token.Id.Pipe)) |pipe| { |
| 2016 | const node = try arena.construct(ast.Node.InfixOp { | 1867 | const node = try arena.construct(ast.Node.InfixOp{ |
| 2017 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, | 1868 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2018 | .lhs = lhs, | 1869 | .lhs = lhs, |
| 2019 | .op_token = pipe, | 1870 | .op_token = pipe, |
| 2020 | .op = ast.Node.InfixOp.Op.BitOr, | 1871 | .op = ast.Node.InfixOp.Op.BitOr, |
| 2021 | .rhs = undefined, | 1872 | .rhs = undefined, |
| 2022 | }); | 1873 | }); |
| 2023 | opt_ctx.store(&node.base); | 1874 | opt_ctx.store(&node.base); |
| 2024 | stack.append(State { .BinaryOrExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 1875 | stack.append(State{ .BinaryOrExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2025 | try stack.append(State { .BinaryXorExpressionBegin = OptionalCtx { .Required = &node.rhs } }); | 1876 | try stack.append(State{ .BinaryXorExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); |
| 2026 | continue; | 1877 | continue; |
| 2027 | } | 1878 | } |
| 2028 | }, | 1879 | }, |
| 2029 | | 1880 | |
| 2030 | State.BinaryXorExpressionBegin => |opt_ctx| { | 1881 | State.BinaryXorExpressionBegin => |opt_ctx| { |
| 2031 | stack.append(State { .BinaryXorExpressionEnd = opt_ctx }) catch unreachable; | 1882 | stack.append(State{ .BinaryXorExpressionEnd = opt_ctx }) catch unreachable; |
| 2032 | try stack.append(State { .BinaryAndExpressionBegin = opt_ctx }); | 1883 | try stack.append(State{ .BinaryAndExpressionBegin = opt_ctx }); |
| 2033 | continue; | 1884 | continue; |
| 2034 | }, | 1885 | }, |
| 2035 | | 1886 | |
| ... | @@ -2037,23 +1888,23 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2037,23 +1888,23 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2037 | const lhs = opt_ctx.get() ?? continue; | 1888 | const lhs = opt_ctx.get() ?? continue; |
| 2038 | | 1889 | |
| 2039 | if (eatToken(&tok_it, &tree, Token.Id.Caret)) |caret| { | 1890 | if (eatToken(&tok_it, &tree, Token.Id.Caret)) |caret| { |
| 2040 | const node = try arena.construct(ast.Node.InfixOp { | 1891 | const node = try arena.construct(ast.Node.InfixOp{ |
| 2041 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, | 1892 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2042 | .lhs = lhs, | 1893 | .lhs = lhs, |
| 2043 | .op_token = caret, | 1894 | .op_token = caret, |
| 2044 | .op = ast.Node.InfixOp.Op.BitXor, | 1895 | .op = ast.Node.InfixOp.Op.BitXor, |
| 2045 | .rhs = undefined, | 1896 | .rhs = undefined, |
| 2046 | }); | 1897 | }); |
| 2047 | opt_ctx.store(&node.base); | 1898 | opt_ctx.store(&node.base); |
| 2048 | stack.append(State { .BinaryXorExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 1899 | stack.append(State{ .BinaryXorExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2049 | try stack.append(State { .BinaryAndExpressionBegin = OptionalCtx { .Required = &node.rhs } }); | 1900 | try stack.append(State{ .BinaryAndExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); |
| 2050 | continue; | 1901 | continue; |
| 2051 | } | 1902 | } |
| 2052 | }, | 1903 | }, |
| 2053 | | 1904 | |
| 2054 | State.BinaryAndExpressionBegin => |opt_ctx| { | 1905 | State.BinaryAndExpressionBegin => |opt_ctx| { |
| 2055 | stack.append(State { .BinaryAndExpressionEnd = opt_ctx }) catch unreachable; | 1906 | stack.append(State{ .BinaryAndExpressionEnd = opt_ctx }) catch unreachable; |
| 2056 | try stack.append(State { .BitShiftExpressionBegin = opt_ctx }); | 1907 | try stack.append(State{ .BitShiftExpressionBegin = opt_ctx }); |
| 2057 | continue; | 1908 | continue; |
| 2058 | }, | 1909 | }, |
| 2059 | | 1910 | |
| ... | @@ -2061,23 +1912,23 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2061,23 +1912,23 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2061 | const lhs = opt_ctx.get() ?? continue; | 1912 | const lhs = opt_ctx.get() ?? continue; |
| 2062 | | 1913 | |
| 2063 | if (eatToken(&tok_it, &tree, Token.Id.Ampersand)) |ampersand| { | 1914 | if (eatToken(&tok_it, &tree, Token.Id.Ampersand)) |ampersand| { |
| 2064 | const node = try arena.construct(ast.Node.InfixOp { | 1915 | const node = try arena.construct(ast.Node.InfixOp{ |
| 2065 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, | 1916 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2066 | .lhs = lhs, | 1917 | .lhs = lhs, |
| 2067 | .op_token = ampersand, | 1918 | .op_token = ampersand, |
| 2068 | .op = ast.Node.InfixOp.Op.BitAnd, | 1919 | .op = ast.Node.InfixOp.Op.BitAnd, |
| 2069 | .rhs = undefined, | 1920 | .rhs = undefined, |
| 2070 | }); | 1921 | }); |
| 2071 | opt_ctx.store(&node.base); | 1922 | opt_ctx.store(&node.base); |
| 2072 | stack.append(State { .BinaryAndExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 1923 | stack.append(State{ .BinaryAndExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2073 | try stack.append(State { .BitShiftExpressionBegin = OptionalCtx { .Required = &node.rhs } }); | 1924 | try stack.append(State{ .BitShiftExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); |
| 2074 | continue; | 1925 | continue; |
| 2075 | } | 1926 | } |
| 2076 | }, | 1927 | }, |
| 2077 | | 1928 | |
| 2078 | State.BitShiftExpressionBegin => |opt_ctx| { | 1929 | State.BitShiftExpressionBegin => |opt_ctx| { |
| 2079 | stack.append(State { .BitShiftExpressionEnd = opt_ctx }) catch unreachable; | 1930 | stack.append(State{ .BitShiftExpressionEnd = opt_ctx }) catch unreachable; |
| 2080 | try stack.append(State { .AdditionExpressionBegin = opt_ctx }); | 1931 | try stack.append(State{ .AdditionExpressionBegin = opt_ctx }); |
| 2081 | continue; | 1932 | continue; |
| 2082 | }, | 1933 | }, |
| 2083 | | 1934 | |
| ... | @@ -2088,16 +1939,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2088,16 +1939,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2088 | const token_index = token.index; | 1939 | const token_index = token.index; |
| 2089 | const token_ptr = token.ptr; | 1940 | const token_ptr = token.ptr; |
| 2090 | if (tokenIdToBitShift(token_ptr.id)) |bitshift_id| { | 1941 | if (tokenIdToBitShift(token_ptr.id)) |bitshift_id| { |
| 2091 | const node = try arena.construct(ast.Node.InfixOp { | 1942 | const node = try arena.construct(ast.Node.InfixOp{ |
| 2092 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, | 1943 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2093 | .lhs = lhs, | 1944 | .lhs = lhs, |
| 2094 | .op_token = token_index, | 1945 | .op_token = token_index, |
| 2095 | .op = bitshift_id, | 1946 | .op = bitshift_id, |
| 2096 | .rhs = undefined, | 1947 | .rhs = undefined, |
| 2097 | }); | 1948 | }); |
| 2098 | opt_ctx.store(&node.base); | 1949 | opt_ctx.store(&node.base); |
| 2099 | stack.append(State { .BitShiftExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 1950 | stack.append(State{ .BitShiftExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2100 | try stack.append(State { .AdditionExpressionBegin = OptionalCtx { .Required = &node.rhs } }); | 1951 | try stack.append(State{ .AdditionExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); |
| 2101 | continue; | 1952 | continue; |
| 2102 | } else { | 1953 | } else { |
| 2103 | putBackToken(&tok_it, &tree); | 1954 | putBackToken(&tok_it, &tree); |
| ... | @@ -2106,8 +1957,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2106,8 +1957,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2106 | }, | 1957 | }, |
| 2107 | | 1958 | |
| 2108 | State.AdditionExpressionBegin => |opt_ctx| { | 1959 | State.AdditionExpressionBegin => |opt_ctx| { |
| 2109 | stack.append(State { .AdditionExpressionEnd = opt_ctx }) catch unreachable; | 1960 | stack.append(State{ .AdditionExpressionEnd = opt_ctx }) catch unreachable; |
| 2110 | try stack.append(State { .MultiplyExpressionBegin = opt_ctx }); | 1961 | try stack.append(State{ .MultiplyExpressionBegin = opt_ctx }); |
| 2111 | continue; | 1962 | continue; |
| 2112 | }, | 1963 | }, |
| 2113 | | 1964 | |
| ... | @@ -2118,16 +1969,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2118,16 +1969,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2118 | const token_index = token.index; | 1969 | const token_index = token.index; |
| 2119 | const token_ptr = token.ptr; | 1970 | const token_ptr = token.ptr; |
| 2120 | if (tokenIdToAddition(token_ptr.id)) |add_id| { | 1971 | if (tokenIdToAddition(token_ptr.id)) |add_id| { |
| 2121 | const node = try arena.construct(ast.Node.InfixOp { | 1972 | const node = try arena.construct(ast.Node.InfixOp{ |
| 2122 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, | 1973 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2123 | .lhs = lhs, | 1974 | .lhs = lhs, |
| 2124 | .op_token = token_index, | 1975 | .op_token = token_index, |
| 2125 | .op = add_id, | 1976 | .op = add_id, |
| 2126 | .rhs = undefined, | 1977 | .rhs = undefined, |
| 2127 | }); | 1978 | }); |
| 2128 | opt_ctx.store(&node.base); | 1979 | opt_ctx.store(&node.base); |
| 2129 | stack.append(State { .AdditionExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 1980 | stack.append(State{ .AdditionExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2130 | try stack.append(State { .MultiplyExpressionBegin = OptionalCtx { .Required = &node.rhs } }); | 1981 | try stack.append(State{ .MultiplyExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); |
| 2131 | continue; | 1982 | continue; |
| 2132 | } else { | 1983 | } else { |
| 2133 | putBackToken(&tok_it, &tree); | 1984 | putBackToken(&tok_it, &tree); |
| ... | @@ -2136,8 +1987,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2136,8 +1987,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2136 | }, | 1987 | }, |
| 2137 | | 1988 | |
| 2138 | State.MultiplyExpressionBegin => |opt_ctx| { | 1989 | State.MultiplyExpressionBegin => |opt_ctx| { |
| 2139 | stack.append(State { .MultiplyExpressionEnd = opt_ctx }) catch unreachable; | 1990 | stack.append(State{ .MultiplyExpressionEnd = opt_ctx }) catch unreachable; |
| 2140 | try stack.append(State { .CurlySuffixExpressionBegin = opt_ctx }); | 1991 | try stack.append(State{ .CurlySuffixExpressionBegin = opt_ctx }); |
| 2141 | continue; | 1992 | continue; |
| 2142 | }, | 1993 | }, |
| 2143 | | 1994 | |
| ... | @@ -2148,16 +1999,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2148,16 +1999,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2148 | const token_index = token.index; | 1999 | const token_index = token.index; |
| 2149 | const token_ptr = token.ptr; | 2000 | const token_ptr = token.ptr; |
| 2150 | if (tokenIdToMultiply(token_ptr.id)) |mult_id| { | 2001 | if (tokenIdToMultiply(token_ptr.id)) |mult_id| { |
| 2151 | const node = try arena.construct(ast.Node.InfixOp { | 2002 | const node = try arena.construct(ast.Node.InfixOp{ |
| 2152 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, | 2003 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2153 | .lhs = lhs, | 2004 | .lhs = lhs, |
| 2154 | .op_token = token_index, | 2005 | .op_token = token_index, |
| 2155 | .op = mult_id, | 2006 | .op = mult_id, |
| 2156 | .rhs = undefined, | 2007 | .rhs = undefined, |
| 2157 | }); | 2008 | }); |
| 2158 | opt_ctx.store(&node.base); | 2009 | opt_ctx.store(&node.base); |
| 2159 | stack.append(State { .MultiplyExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2010 | stack.append(State{ .MultiplyExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2160 | try stack.append(State { .CurlySuffixExpressionBegin = OptionalCtx { .Required = &node.rhs } }); | 2011 | try stack.append(State{ .CurlySuffixExpressionBegin = OptionalCtx{ .Required = &node.rhs } }); |
| 2161 | continue; | 2012 | continue; |
| 2162 | } else { | 2013 | } else { |
| 2163 | putBackToken(&tok_it, &tree); | 2014 | putBackToken(&tok_it, &tree); |
| ... | @@ -2166,9 +2017,9 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2166,9 +2017,9 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2166 | }, | 2017 | }, |
| 2167 | | 2018 | |
| 2168 | State.CurlySuffixExpressionBegin => |opt_ctx| { | 2019 | State.CurlySuffixExpressionBegin => |opt_ctx| { |
| 2169 | stack.append(State { .CurlySuffixExpressionEnd = opt_ctx }) catch unreachable; | 2020 | stack.append(State{ .CurlySuffixExpressionEnd = opt_ctx }) catch unreachable; |
| 2170 | try stack.append(State { .IfToken = Token.Id.LBrace }); | 2021 | try stack.append(State{ .IfToken = Token.Id.LBrace }); |
| 2171 | try stack.append(State { .TypeExprBegin = opt_ctx }); | 2022 | try stack.append(State{ .TypeExprBegin = opt_ctx }); |
| 2172 | continue; | 2023 | continue; |
| 2173 | }, | 2024 | }, |
| 2174 | | 2025 | |
| ... | @@ -2176,51 +2027,43 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2176,51 +2027,43 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2176 | const lhs = opt_ctx.get() ?? continue; | 2027 | const lhs = opt_ctx.get() ?? continue; |
| 2177 | | 2028 | |
| 2178 | if ((??tok_it.peek()).id == Token.Id.Period) { | 2029 | if ((??tok_it.peek()).id == Token.Id.Period) { |
| 2179 | const node = try arena.construct(ast.Node.SuffixOp { | 2030 | const node = try arena.construct(ast.Node.SuffixOp{ |
| 2180 | .base = ast.Node { .id = ast.Node.Id.SuffixOp }, | 2031 | .base = ast.Node{ .id = ast.Node.Id.SuffixOp }, |
| 2181 | .lhs = lhs, | 2032 | .lhs = lhs, |
| 2182 | .op = ast.Node.SuffixOp.Op { | 2033 | .op = ast.Node.SuffixOp.Op{ .StructInitializer = ast.Node.SuffixOp.Op.InitList.init(arena) }, |
| 2183 | .StructInitializer = ast.Node.SuffixOp.Op.InitList.init(arena), | | |
| 2184 | }, | | |
| 2185 | .rtoken = undefined, | 2034 | .rtoken = undefined, |
| 2186 | }); | 2035 | }); |
| 2187 | opt_ctx.store(&node.base); | 2036 | opt_ctx.store(&node.base); |
| 2188 | | 2037 | |
| 2189 | stack.append(State { .CurlySuffixExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2038 | stack.append(State{ .CurlySuffixExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2190 | try stack.append(State { .IfToken = Token.Id.LBrace }); | 2039 | try stack.append(State{ .IfToken = Token.Id.LBrace }); |
| 2191 | try stack.append(State { | 2040 | try stack.append(State{ .FieldInitListItemOrEnd = ListSave(@typeOf(node.op.StructInitializer)){ |
| 2192 | .FieldInitListItemOrEnd = ListSave(@typeOf(node.op.StructInitializer)) { | 2041 | .list = &node.op.StructInitializer, |
| 2193 | .list = &node.op.StructInitializer, | 2042 | .ptr = &node.rtoken, |
| 2194 | .ptr = &node.rtoken, | 2043 | } }); |
| 2195 | } | | |
| 2196 | }); | | |
| 2197 | continue; | 2044 | continue; |
| 2198 | } | 2045 | } |
| 2199 | | 2046 | |
| 2200 | const node = try arena.construct(ast.Node.SuffixOp { | 2047 | const node = try arena.construct(ast.Node.SuffixOp{ |
| 2201 | .base = ast.Node {.id = ast.Node.Id.SuffixOp }, | 2048 | .base = ast.Node{ .id = ast.Node.Id.SuffixOp }, |
| 2202 | .lhs = lhs, | 2049 | .lhs = lhs, |
| 2203 | .op = ast.Node.SuffixOp.Op { | 2050 | .op = ast.Node.SuffixOp.Op{ .ArrayInitializer = ast.Node.SuffixOp.Op.InitList.init(arena) }, |
| 2204 | .ArrayInitializer = ast.Node.SuffixOp.Op.InitList.init(arena), | | |
| 2205 | }, | | |
| 2206 | .rtoken = undefined, | 2051 | .rtoken = undefined, |
| 2207 | }); | 2052 | }); |
| 2208 | opt_ctx.store(&node.base); | 2053 | opt_ctx.store(&node.base); |
| 2209 | stack.append(State { .CurlySuffixExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2054 | stack.append(State{ .CurlySuffixExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2210 | try stack.append(State { .IfToken = Token.Id.LBrace }); | 2055 | try stack.append(State{ .IfToken = Token.Id.LBrace }); |
| 2211 | try stack.append(State { | 2056 | try stack.append(State{ .ExprListItemOrEnd = ExprListCtx{ |
| 2212 | .ExprListItemOrEnd = ExprListCtx { | 2057 | .list = &node.op.ArrayInitializer, |
| 2213 | .list = &node.op.ArrayInitializer, | 2058 | .end = Token.Id.RBrace, |
| 2214 | .end = Token.Id.RBrace, | 2059 | .ptr = &node.rtoken, |
| 2215 | .ptr = &node.rtoken, | 2060 | } }); |
| 2216 | } | | |
| 2217 | }); | | |
| 2218 | continue; | 2061 | continue; |
| 2219 | }, | 2062 | }, |
| 2220 | | 2063 | |
| 2221 | State.TypeExprBegin => |opt_ctx| { | 2064 | State.TypeExprBegin => |opt_ctx| { |
| 2222 | stack.append(State { .TypeExprEnd = opt_ctx }) catch unreachable; | 2065 | stack.append(State{ .TypeExprEnd = opt_ctx }) catch unreachable; |
| 2223 | try stack.append(State { .PrefixOpExpression = opt_ctx }); | 2066 | try stack.append(State{ .PrefixOpExpression = opt_ctx }); |
| 2224 | continue; | 2067 | continue; |
| 2225 | }, | 2068 | }, |
| 2226 | | 2069 | |
| ... | @@ -2228,16 +2071,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2228,16 +2071,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2228 | const lhs = opt_ctx.get() ?? continue; | 2071 | const lhs = opt_ctx.get() ?? continue; |
| 2229 | | 2072 | |
| 2230 | if (eatToken(&tok_it, &tree, Token.Id.Bang)) |bang| { | 2073 | if (eatToken(&tok_it, &tree, Token.Id.Bang)) |bang| { |
| 2231 | const node = try arena.construct(ast.Node.InfixOp { | 2074 | const node = try arena.construct(ast.Node.InfixOp{ |
| 2232 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, | 2075 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2233 | .lhs = lhs, | 2076 | .lhs = lhs, |
| 2234 | .op_token = bang, | 2077 | .op_token = bang, |
| 2235 | .op = ast.Node.InfixOp.Op.ErrorUnion, | 2078 | .op = ast.Node.InfixOp.Op.ErrorUnion, |
| 2236 | .rhs = undefined, | 2079 | .rhs = undefined, |
| 2237 | }); | 2080 | }); |
| 2238 | opt_ctx.store(&node.base); | 2081 | opt_ctx.store(&node.base); |
| 2239 | stack.append(State { .TypeExprEnd = opt_ctx.toRequired() }) catch unreachable; | 2082 | stack.append(State{ .TypeExprEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2240 | try stack.append(State { .PrefixOpExpression = OptionalCtx { .Required = &node.rhs } }); | 2083 | try stack.append(State{ .PrefixOpExpression = OptionalCtx{ .Required = &node.rhs } }); |
| 2241 | continue; | 2084 | continue; |
| 2242 | } | 2085 | } |
| 2243 | }, | 2086 | }, |
| ... | @@ -2247,8 +2090,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2247,8 +2090,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2247 | const token_index = token.index; | 2090 | const token_index = token.index; |
| 2248 | const token_ptr = token.ptr; | 2091 | const token_ptr = token.ptr; |
| 2249 | if (tokenIdToPrefixOp(token_ptr.id)) |prefix_id| { | 2092 | if (tokenIdToPrefixOp(token_ptr.id)) |prefix_id| { |
| 2250 | var node = try arena.construct(ast.Node.PrefixOp { | 2093 | var node = try arena.construct(ast.Node.PrefixOp{ |
| 2251 | .base = ast.Node {.id = ast.Node.Id.PrefixOp }, | 2094 | .base = ast.Node{ .id = ast.Node.Id.PrefixOp }, |
| 2252 | .op_token = token_index, | 2095 | .op_token = token_index, |
| 2253 | .op = prefix_id, | 2096 | .op = prefix_id, |
| 2254 | .rhs = undefined, | 2097 | .rhs = undefined, |
| ... | @@ -2257,8 +2100,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2257,8 +2100,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2257 | | 2100 | |
| 2258 | // Treat '**' token as two derefs | 2101 | // Treat '**' token as two derefs |
| 2259 | if (token_ptr.id == Token.Id.AsteriskAsterisk) { | 2102 | if (token_ptr.id == Token.Id.AsteriskAsterisk) { |
| 2260 | const child = try arena.construct(ast.Node.PrefixOp { | 2103 | const child = try arena.construct(ast.Node.PrefixOp{ |
| 2261 | .base = ast.Node {.id = ast.Node.Id.PrefixOp}, | 2104 | .base = ast.Node{ .id = ast.Node.Id.PrefixOp }, |
| 2262 | .op_token = token_index, | 2105 | .op_token = token_index, |
| 2263 | .op = prefix_id, | 2106 | .op = prefix_id, |
| 2264 | .rhs = undefined, | 2107 | .rhs = undefined, |
| ... | @@ -2267,40 +2110,38 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2267,40 +2110,38 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2267 | node = child; | 2110 | node = child; |
| 2268 | } | 2111 | } |
| 2269 | | 2112 | |
| 2270 | stack.append(State { .TypeExprBegin = OptionalCtx { .Required = &node.rhs } }) catch unreachable; | 2113 | stack.append(State{ .TypeExprBegin = OptionalCtx{ .Required = &node.rhs } }) catch unreachable; |
| 2271 | if (node.op == ast.Node.PrefixOp.Op.AddrOf) { | 2114 | if (node.op == ast.Node.PrefixOp.Op.AddrOf) { |
| 2272 | try stack.append(State { .AddrOfModifiers = &node.op.AddrOf }); | 2115 | try stack.append(State{ .AddrOfModifiers = &node.op.AddrOf }); |
| 2273 | } | 2116 | } |
| 2274 | continue; | 2117 | continue; |
| 2275 | } else { | 2118 | } else { |
| 2276 | putBackToken(&tok_it, &tree); | 2119 | putBackToken(&tok_it, &tree); |
| 2277 | stack.append(State { .SuffixOpExpressionBegin = opt_ctx }) catch unreachable; | 2120 | stack.append(State{ .SuffixOpExpressionBegin = opt_ctx }) catch unreachable; |
| 2278 | continue; | 2121 | continue; |
| 2279 | } | 2122 | } |
| 2280 | }, | 2123 | }, |
| 2281 | | 2124 | |
| 2282 | State.SuffixOpExpressionBegin => |opt_ctx| { | 2125 | State.SuffixOpExpressionBegin => |opt_ctx| { |
| 2283 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_async)) |async_token| { | 2126 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_async)) |async_token| { |
| 2284 | const async_node = try arena.construct(ast.Node.AsyncAttribute { | 2127 | const async_node = try arena.construct(ast.Node.AsyncAttribute{ |
| 2285 | .base = ast.Node {.id = ast.Node.Id.AsyncAttribute}, | 2128 | .base = ast.Node{ .id = ast.Node.Id.AsyncAttribute }, |
| 2286 | .async_token = async_token, | 2129 | .async_token = async_token, |
| 2287 | .allocator_type = null, | 2130 | .allocator_type = null, |
| 2288 | .rangle_bracket = null, | 2131 | .rangle_bracket = null, |
| 2289 | }); | 2132 | }); |
| 2290 | stack.append(State { | 2133 | stack.append(State{ .AsyncEnd = AsyncEndCtx{ |
| 2291 | .AsyncEnd = AsyncEndCtx { | 2134 | .ctx = opt_ctx, |
| 2292 | .ctx = opt_ctx, | 2135 | .attribute = async_node, |
| 2293 | .attribute = async_node, | 2136 | } }) catch unreachable; |
| 2294 | } | 2137 | try stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }); |
| 2295 | }) catch unreachable; | 2138 | try stack.append(State{ .PrimaryExpression = opt_ctx.toRequired() }); |
| 2296 | try stack.append(State { .SuffixOpExpressionEnd = opt_ctx.toRequired() }); | 2139 | try stack.append(State{ .AsyncAllocator = async_node }); |
| 2297 | try stack.append(State { .PrimaryExpression = opt_ctx.toRequired() }); | | |
| 2298 | try stack.append(State { .AsyncAllocator = async_node }); | | |
| 2299 | continue; | 2140 | continue; |
| 2300 | } | 2141 | } |
| 2301 | | 2142 | |
| 2302 | stack.append(State { .SuffixOpExpressionEnd = opt_ctx }) catch unreachable; | 2143 | stack.append(State{ .SuffixOpExpressionEnd = opt_ctx }) catch unreachable; |
| 2303 | try stack.append(State { .PrimaryExpression = opt_ctx }); | 2144 | try stack.append(State{ .PrimaryExpression = opt_ctx }); |
| 2304 | continue; | 2145 | continue; |
| 2305 | }, | 2146 | }, |
| 2306 | | 2147 | |
| ... | @@ -2312,48 +2153,42 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2312,48 +2153,42 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2312 | const token_ptr = token.ptr; | 2153 | const token_ptr = token.ptr; |
| 2313 | switch (token_ptr.id) { | 2154 | switch (token_ptr.id) { |
| 2314 | Token.Id.LParen => { | 2155 | Token.Id.LParen => { |
| 2315 | const node = try arena.construct(ast.Node.SuffixOp { | 2156 | const node = try arena.construct(ast.Node.SuffixOp{ |
| 2316 | .base = ast.Node {.id = ast.Node.Id.SuffixOp }, | 2157 | .base = ast.Node{ .id = ast.Node.Id.SuffixOp }, |
| 2317 | .lhs = lhs, | 2158 | .lhs = lhs, |
| 2318 | .op = ast.Node.SuffixOp.Op { | 2159 | .op = ast.Node.SuffixOp.Op{ .Call = ast.Node.SuffixOp.Op.Call{ |
| 2319 | .Call = ast.Node.SuffixOp.Op.Call { | 2160 | .params = ast.Node.SuffixOp.Op.Call.ParamList.init(arena), |
| 2320 | .params = ast.Node.SuffixOp.Op.Call.ParamList.init(arena), | 2161 | .async_attr = null, |
| 2321 | .async_attr = null, | 2162 | } }, |
| 2322 | } | | |
| 2323 | }, | | |
| 2324 | .rtoken = undefined, | 2163 | .rtoken = undefined, |
| 2325 | }); | 2164 | }); |
| 2326 | opt_ctx.store(&node.base); | 2165 | opt_ctx.store(&node.base); |
| 2327 | | 2166 | |
| 2328 | stack.append(State { .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2167 | stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2329 | try stack.append(State { | 2168 | try stack.append(State{ .ExprListItemOrEnd = ExprListCtx{ |
| 2330 | .ExprListItemOrEnd = ExprListCtx { | 2169 | .list = &node.op.Call.params, |
| 2331 | .list = &node.op.Call.params, | 2170 | .end = Token.Id.RParen, |
| 2332 | .end = Token.Id.RParen, | 2171 | .ptr = &node.rtoken, |
| 2333 | .ptr = &node.rtoken, | 2172 | } }); |
| 2334 | } | | |
| 2335 | }); | | |
| 2336 | continue; | 2173 | continue; |
| 2337 | }, | 2174 | }, |
| 2338 | Token.Id.LBracket => { | 2175 | Token.Id.LBracket => { |
| 2339 | const node = try arena.construct(ast.Node.SuffixOp { | 2176 | const node = try arena.construct(ast.Node.SuffixOp{ |
| 2340 | .base = ast.Node {.id = ast.Node.Id.SuffixOp }, | 2177 | .base = ast.Node{ .id = ast.Node.Id.SuffixOp }, |
| 2341 | .lhs = lhs, | 2178 | .lhs = lhs, |
| 2342 | .op = ast.Node.SuffixOp.Op { | 2179 | .op = ast.Node.SuffixOp.Op{ .ArrayAccess = undefined }, |
| 2343 | .ArrayAccess = undefined, | 2180 | .rtoken = undefined, |
| 2344 | }, | | |
| 2345 | .rtoken = undefined | | |
| 2346 | }); | 2181 | }); |
| 2347 | opt_ctx.store(&node.base); | 2182 | opt_ctx.store(&node.base); |
| 2348 | | 2183 | |
| 2349 | stack.append(State { .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2184 | stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2350 | try stack.append(State { .SliceOrArrayAccess = node }); | 2185 | try stack.append(State{ .SliceOrArrayAccess = node }); |
| 2351 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.op.ArrayAccess }}); | 2186 | try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.op.ArrayAccess } }); |
| 2352 | continue; | 2187 | continue; |
| 2353 | }, | 2188 | }, |
| 2354 | Token.Id.Period => { | 2189 | Token.Id.Period => { |
| 2355 | const node = try arena.construct(ast.Node.InfixOp { | 2190 | const node = try arena.construct(ast.Node.InfixOp{ |
| 2356 | .base = ast.Node {.id = ast.Node.Id.InfixOp }, | 2191 | .base = ast.Node{ .id = ast.Node.Id.InfixOp }, |
| 2357 | .lhs = lhs, | 2192 | .lhs = lhs, |
| 2358 | .op_token = token_index, | 2193 | .op_token = token_index, |
| 2359 | .op = ast.Node.InfixOp.Op.Period, | 2194 | .op = ast.Node.InfixOp.Op.Period, |
| ... | @@ -2361,8 +2196,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2361,8 +2196,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2361 | }); | 2196 | }); |
| 2362 | opt_ctx.store(&node.base); | 2197 | opt_ctx.store(&node.base); |
| 2363 | | 2198 | |
| 2364 | stack.append(State { .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; | 2199 | stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; |
| 2365 | try stack.append(State { .Identifier = OptionalCtx { .Required = &node.rhs } }); | 2200 | try stack.append(State{ .Identifier = OptionalCtx{ .Required = &node.rhs } }); |
| 2366 | continue; | 2201 | continue; |
| 2367 | }, | 2202 | }, |
| 2368 | else => { | 2203 | else => { |
| ... | @@ -2391,7 +2226,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2391,7 +2226,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2391 | _ = try createToCtxLiteral(arena, opt_ctx, ast.Node.UndefinedLiteral, token.index); | 2226 | _ = try createToCtxLiteral(arena, opt_ctx, ast.Node.UndefinedLiteral, token.index); |
| 2392 | continue; | 2227 | continue; |
| 2393 | }, | 2228 | }, |
| 2394 | Token.Id.Keyword_true, Token.Id.Keyword_false => { | 2229 | Token.Id.Keyword_true, |
| | 2230 | Token.Id.Keyword_false => { |
| 2395 | _ = try createToCtxLiteral(arena, opt_ctx, ast.Node.BoolLiteral, token.index); | 2231 | _ = try createToCtxLiteral(arena, opt_ctx, ast.Node.BoolLiteral, token.index); |
| 2396 | continue; | 2232 | continue; |
| 2397 | }, | 2233 | }, |
| ... | @@ -2412,10 +2248,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2412,10 +2248,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2412 | continue; | 2248 | continue; |
| 2413 | }, | 2249 | }, |
| 2414 | Token.Id.Keyword_promise => { | 2250 | Token.Id.Keyword_promise => { |
| 2415 | const node = try arena.construct(ast.Node.PromiseType { | 2251 | const node = try arena.construct(ast.Node.PromiseType{ |
| 2416 | .base = ast.Node { | 2252 | .base = ast.Node{ .id = ast.Node.Id.PromiseType }, |
| 2417 | .id = ast.Node.Id.PromiseType, | | |
| 2418 | }, | | |
| 2419 | .promise_token = token.index, | 2253 | .promise_token = token.index, |
| 2420 | .result = null, | 2254 | .result = null, |
| 2421 | }); | 2255 | }); |
| ... | @@ -2427,121 +2261,108 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2427,121 +2261,108 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2427 | putBackToken(&tok_it, &tree); | 2261 | putBackToken(&tok_it, &tree); |
| 2428 | continue; | 2262 | continue; |
| 2429 | } | 2263 | } |
| 2430 | node.result = ast.Node.PromiseType.Result { | 2264 | node.result = ast.Node.PromiseType.Result{ |
| 2431 | .arrow_token = next_token_index, | 2265 | .arrow_token = next_token_index, |
| 2432 | .return_type = undefined, | 2266 | .return_type = undefined, |
| 2433 | }; | 2267 | }; |
| 2434 | const return_type_ptr = &((??node.result).return_type); | 2268 | const return_type_ptr = &((??node.result).return_type); |
| 2435 | try stack.append(State { .Expression = OptionalCtx { .Required = return_type_ptr, } }); | 2269 | try stack.append(State{ .Expression = OptionalCtx{ .Required = return_type_ptr } }); |
| 2436 | continue; | 2270 | continue; |
| 2437 | }, | 2271 | }, |
| 2438 | Token.Id.StringLiteral, Token.Id.MultilineStringLiteralLine => { | 2272 | Token.Id.StringLiteral, |
| | 2273 | Token.Id.MultilineStringLiteralLine => { |
| 2439 | opt_ctx.store((try parseStringLiteral(arena, &tok_it, token.ptr, token.index, &tree)) ?? unreachable); | 2274 | opt_ctx.store((try parseStringLiteral(arena, &tok_it, token.ptr, token.index, &tree)) ?? unreachable); |
| 2440 | continue; | 2275 | continue; |
| 2441 | }, | 2276 | }, |
| 2442 | Token.Id.LParen => { | 2277 | Token.Id.LParen => { |
| 2443 | const node = try arena.construct(ast.Node.GroupedExpression { | 2278 | const node = try arena.construct(ast.Node.GroupedExpression{ |
| 2444 | .base = ast.Node {.id = ast.Node.Id.GroupedExpression }, | 2279 | .base = ast.Node{ .id = ast.Node.Id.GroupedExpression }, |
| 2445 | .lparen = token.index, | 2280 | .lparen = token.index, |
| 2446 | .expr = undefined, | 2281 | .expr = undefined, |
| 2447 | .rparen = undefined, | 2282 | .rparen = undefined, |
| 2448 | }); | 2283 | }); |
| 2449 | opt_ctx.store(&node.base); | 2284 | opt_ctx.store(&node.base); |
| 2450 | | 2285 | |
| 2451 | stack.append(State { | 2286 | stack.append(State{ .ExpectTokenSave = ExpectTokenSave{ |
| 2452 | .ExpectTokenSave = ExpectTokenSave { | 2287 | .id = Token.Id.RParen, |
| 2453 | .id = Token.Id.RParen, | 2288 | .ptr = &node.rparen, |
| 2454 | .ptr = &node.rparen, | 2289 | } }) catch unreachable; |
| 2455 | } | 2290 | try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.expr } }); |
| 2456 | }) catch unreachable; | | |
| 2457 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.expr } }); | | |
| 2458 | continue; | 2291 | continue; |
| 2459 | }, | 2292 | }, |
| 2460 | Token.Id.Builtin => { | 2293 | Token.Id.Builtin => { |
| 2461 | const node = try arena.construct(ast.Node.BuiltinCall { | 2294 | const node = try arena.construct(ast.Node.BuiltinCall{ |
| 2462 | .base = ast.Node {.id = ast.Node.Id.BuiltinCall }, | 2295 | .base = ast.Node{ .id = ast.Node.Id.BuiltinCall }, |
| 2463 | .builtin_token = token.index, | 2296 | .builtin_token = token.index, |
| 2464 | .params = ast.Node.BuiltinCall.ParamList.init(arena), | 2297 | .params = ast.Node.BuiltinCall.ParamList.init(arena), |
| 2465 | .rparen_token = undefined, | 2298 | .rparen_token = undefined, |
| 2466 | }); | 2299 | }); |
| 2467 | opt_ctx.store(&node.base); | 2300 | opt_ctx.store(&node.base); |
| 2468 | | 2301 | |
| 2469 | stack.append(State { | 2302 | stack.append(State{ .ExprListItemOrEnd = ExprListCtx{ |
| 2470 | .ExprListItemOrEnd = ExprListCtx { | 2303 | .list = &node.params, |
| 2471 | .list = &node.params, | 2304 | .end = Token.Id.RParen, |
| 2472 | .end = Token.Id.RParen, | 2305 | .ptr = &node.rparen_token, |
| 2473 | .ptr = &node.rparen_token, | 2306 | } }) catch unreachable; |
| 2474 | } | 2307 | try stack.append(State{ .ExpectToken = Token.Id.LParen }); |
| 2475 | }) catch unreachable; | | |
| 2476 | try stack.append(State { .ExpectToken = Token.Id.LParen, }); | | |
| 2477 | continue; | 2308 | continue; |
| 2478 | }, | 2309 | }, |
| 2479 | Token.Id.LBracket => { | 2310 | Token.Id.LBracket => { |
| 2480 | const node = try arena.construct(ast.Node.PrefixOp { | 2311 | const node = try arena.construct(ast.Node.PrefixOp{ |
| 2481 | .base = ast.Node {.id = ast.Node.Id.PrefixOp }, | 2312 | .base = ast.Node{ .id = ast.Node.Id.PrefixOp }, |
| 2482 | .op_token = token.index, | 2313 | .op_token = token.index, |
| 2483 | .op = undefined, | 2314 | .op = undefined, |
| 2484 | .rhs = undefined, | 2315 | .rhs = undefined, |
| 2485 | }); | 2316 | }); |
| 2486 | opt_ctx.store(&node.base); | 2317 | opt_ctx.store(&node.base); |
| 2487 | | 2318 | |
| 2488 | stack.append(State { .SliceOrArrayType = node }) catch unreachable; | 2319 | stack.append(State{ .SliceOrArrayType = node }) catch unreachable; |
| 2489 | continue; | 2320 | continue; |
| 2490 | }, | 2321 | }, |
| 2491 | Token.Id.Keyword_error => { | 2322 | Token.Id.Keyword_error => { |
| 2492 | stack.append(State { | 2323 | stack.append(State{ .ErrorTypeOrSetDecl = ErrorTypeOrSetDeclCtx{ |
| 2493 | .ErrorTypeOrSetDecl = ErrorTypeOrSetDeclCtx { | 2324 | .error_token = token.index, |
| 2494 | .error_token = token.index, | 2325 | .opt_ctx = opt_ctx, |
| 2495 | .opt_ctx = opt_ctx | 2326 | } }) catch unreachable; |
| 2496 | } | | |
| 2497 | }) catch unreachable; | | |
| 2498 | continue; | 2327 | continue; |
| 2499 | }, | 2328 | }, |
| 2500 | Token.Id.Keyword_packed => { | 2329 | Token.Id.Keyword_packed => { |
| 2501 | stack.append(State { | 2330 | stack.append(State{ .ContainerKind = ContainerKindCtx{ |
| 2502 | .ContainerKind = ContainerKindCtx { | 2331 | .opt_ctx = opt_ctx, |
| 2503 | .opt_ctx = opt_ctx, | 2332 | .ltoken = token.index, |
| 2504 | .ltoken = token.index, | 2333 | .layout = ast.Node.ContainerDecl.Layout.Packed, |
| 2505 | .layout = ast.Node.ContainerDecl.Layout.Packed, | 2334 | } }) catch unreachable; |
| 2506 | }, | | |
| 2507 | }) catch unreachable; | | |
| 2508 | continue; | 2335 | continue; |
| 2509 | }, | 2336 | }, |
| 2510 | Token.Id.Keyword_extern => { | 2337 | Token.Id.Keyword_extern => { |
| 2511 | stack.append(State { | 2338 | stack.append(State{ .ExternType = ExternTypeCtx{ |
| 2512 | .ExternType = ExternTypeCtx { | 2339 | .opt_ctx = opt_ctx, |
| 2513 | .opt_ctx = opt_ctx, | 2340 | .extern_token = token.index, |
| 2514 | .extern_token = token.index, | 2341 | .comments = null, |
| 2515 | .comments = null, | 2342 | } }) catch unreachable; |
| 2516 | }, | | |
| 2517 | }) catch unreachable; | | |
| 2518 | continue; | 2343 | continue; |
| 2519 | }, | 2344 | }, |
| 2520 | Token.Id.Keyword_struct, Token.Id.Keyword_union, Token.Id.Keyword_enum => { | 2345 | Token.Id.Keyword_struct, |
| | 2346 | Token.Id.Keyword_union, |
| | 2347 | Token.Id.Keyword_enum => { |
| 2521 | putBackToken(&tok_it, &tree); | 2348 | putBackToken(&tok_it, &tree); |
| 2522 | stack.append(State { | 2349 | stack.append(State{ .ContainerKind = ContainerKindCtx{ |
| 2523 | .ContainerKind = ContainerKindCtx { | 2350 | .opt_ctx = opt_ctx, |
| 2524 | .opt_ctx = opt_ctx, | 2351 | .ltoken = token.index, |
| 2525 | .ltoken = token.index, | 2352 | .layout = ast.Node.ContainerDecl.Layout.Auto, |
| 2526 | .layout = ast.Node.ContainerDecl.Layout.Auto, | 2353 | } }) catch unreachable; |
| 2527 | }, | | |
| 2528 | }) catch unreachable; | | |
| 2529 | continue; | 2354 | continue; |
| 2530 | }, | 2355 | }, |
| 2531 | Token.Id.Identifier => { | 2356 | Token.Id.Identifier => { |
| 2532 | stack.append(State { | 2357 | stack.append(State{ .MaybeLabeledExpression = MaybeLabeledExpressionCtx{ |
| 2533 | .MaybeLabeledExpression = MaybeLabeledExpressionCtx { | 2358 | .label = token.index, |
| 2534 | .label = token.index, | 2359 | .opt_ctx = opt_ctx, |
| 2535 | .opt_ctx = opt_ctx | 2360 | } }) catch unreachable; |
| 2536 | } | | |
| 2537 | }) catch unreachable; | | |
| 2538 | continue; | 2361 | continue; |
| 2539 | }, | 2362 | }, |
| 2540 | Token.Id.Keyword_fn => { | 2363 | Token.Id.Keyword_fn => { |
| 2541 | const fn_proto = try arena.construct(ast.Node.FnProto { | 2364 | const fn_proto = try arena.construct(ast.Node.FnProto{ |
| 2542 | .base = ast.Node { | 2365 | .base = ast.Node{ .id = ast.Node.Id.FnProto }, |
| 2543 | .id = ast.Node.Id.FnProto, | | |
| 2544 | }, | | |
| 2545 | .doc_comments = null, | 2366 | .doc_comments = null, |
| 2546 | .visib_token = null, | 2367 | .visib_token = null, |
| 2547 | .name_token = null, | 2368 | .name_token = null, |
| ... | @@ -2557,14 +2378,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2557,14 +2378,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2557 | .align_expr = null, | 2378 | .align_expr = null, |
| 2558 | }); | 2379 | }); |
| 2559 | opt_ctx.store(&fn_proto.base); | 2380 | opt_ctx.store(&fn_proto.base); |
| 2560 | stack.append(State { .FnProto = fn_proto }) catch unreachable; | 2381 | stack.append(State{ .FnProto = fn_proto }) catch unreachable; |
| 2561 | continue; | 2382 | continue; |
| 2562 | }, | 2383 | }, |
| 2563 | Token.Id.Keyword_nakedcc, Token.Id.Keyword_stdcallcc => { | 2384 | Token.Id.Keyword_nakedcc, |
| 2564 | const fn_proto = try arena.construct(ast.Node.FnProto { | 2385 | Token.Id.Keyword_stdcallcc => { |
| 2565 | .base = ast.Node { | 2386 | const fn_proto = try arena.construct(ast.Node.FnProto{ |
| 2566 | .id = ast.Node.Id.FnProto, | 2387 | .base = ast.Node{ .id = ast.Node.Id.FnProto }, |
| 2567 | }, | | |
| 2568 | .doc_comments = null, | 2388 | .doc_comments = null, |
| 2569 | .visib_token = null, | 2389 | .visib_token = null, |
| 2570 | .name_token = null, | 2390 | .name_token = null, |
| ... | @@ -2580,18 +2400,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2580,18 +2400,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2580 | .align_expr = null, | 2400 | .align_expr = null, |
| 2581 | }); | 2401 | }); |
| 2582 | opt_ctx.store(&fn_proto.base); | 2402 | opt_ctx.store(&fn_proto.base); |
| 2583 | stack.append(State { .FnProto = fn_proto }) catch unreachable; | 2403 | stack.append(State{ .FnProto = fn_proto }) catch unreachable; |
| 2584 | try stack.append(State { | 2404 | try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{ |
| 2585 | .ExpectTokenSave = ExpectTokenSave { | 2405 | .id = Token.Id.Keyword_fn, |
| 2586 | .id = Token.Id.Keyword_fn, | 2406 | .ptr = &fn_proto.fn_token, |
| 2587 | .ptr = &fn_proto.fn_token | 2407 | } }); |
| 2588 | } | | |
| 2589 | }); | | |
| 2590 | continue; | 2408 | continue; |
| 2591 | }, | 2409 | }, |
| 2592 | Token.Id.Keyword_asm => { | 2410 | Token.Id.Keyword_asm => { |
| 2593 | const node = try arena.construct(ast.Node.Asm { | 2411 | const node = try arena.construct(ast.Node.Asm{ |
| 2594 | .base = ast.Node {.id = ast.Node.Id.Asm }, | 2412 | .base = ast.Node{ .id = ast.Node.Id.Asm }, |
| 2595 | .asm_token = token.index, | 2413 | .asm_token = token.index, |
| 2596 | .volatile_token = null, | 2414 | .volatile_token = null, |
| 2597 | .template = undefined, | 2415 | .template = undefined, |
| ... | @@ -2602,94 +2420,77 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2602,94 +2420,77 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2602 | }); | 2420 | }); |
| 2603 | opt_ctx.store(&node.base); | 2421 | opt_ctx.store(&node.base); |
| 2604 | | 2422 | |
| 2605 | stack.append(State { | 2423 | stack.append(State{ .ExpectTokenSave = ExpectTokenSave{ |
| 2606 | .ExpectTokenSave = ExpectTokenSave { | 2424 | .id = Token.Id.RParen, |
| 2607 | .id = Token.Id.RParen, | 2425 | .ptr = &node.rparen, |
| 2608 | .ptr = &node.rparen, | 2426 | } }) catch unreachable; |
| 2609 | } | 2427 | try stack.append(State{ .AsmClobberItems = &node.clobbers }); |
| 2610 | }) catch unreachable; | 2428 | try stack.append(State{ .IfToken = Token.Id.Colon }); |
| 2611 | try stack.append(State { .AsmClobberItems = &node.clobbers }); | 2429 | try stack.append(State{ .AsmInputItems = &node.inputs }); |
| 2612 | try stack.append(State { .IfToken = Token.Id.Colon }); | 2430 | try stack.append(State{ .IfToken = Token.Id.Colon }); |
| 2613 | try stack.append(State { .AsmInputItems = &node.inputs }); | 2431 | try stack.append(State{ .AsmOutputItems = &node.outputs }); |
| 2614 | try stack.append(State { .IfToken = Token.Id.Colon }); | 2432 | try stack.append(State{ .IfToken = Token.Id.Colon }); |
| 2615 | try stack.append(State { .AsmOutputItems = &node.outputs }); | 2433 | try stack.append(State{ .StringLiteral = OptionalCtx{ .Required = &node.template } }); |
| 2616 | try stack.append(State { .IfToken = Token.Id.Colon }); | 2434 | try stack.append(State{ .ExpectToken = Token.Id.LParen }); |
| 2617 | try stack.append(State { .StringLiteral = OptionalCtx { .Required = &node.template } }); | 2435 | try stack.append(State{ .OptionalTokenSave = OptionalTokenSave{ |
| 2618 | try stack.append(State { .ExpectToken = Token.Id.LParen }); | 2436 | .id = Token.Id.Keyword_volatile, |
| 2619 | try stack.append(State { | 2437 | .ptr = &node.volatile_token, |
| 2620 | .OptionalTokenSave = OptionalTokenSave { | 2438 | } }); |
| 2621 | .id = Token.Id.Keyword_volatile, | | |
| 2622 | .ptr = &node.volatile_token, | | |
| 2623 | } | | |
| 2624 | }); | | |
| 2625 | }, | 2439 | }, |
| 2626 | Token.Id.Keyword_inline => { | 2440 | Token.Id.Keyword_inline => { |
| 2627 | stack.append(State { | 2441 | stack.append(State{ .Inline = InlineCtx{ |
| 2628 | .Inline = InlineCtx { | 2442 | .label = null, |
| 2629 | .label = null, | 2443 | .inline_token = token.index, |
| 2630 | .inline_token = token.index, | 2444 | .opt_ctx = opt_ctx, |
| 2631 | .opt_ctx = opt_ctx, | 2445 | } }) catch unreachable; |
| 2632 | } | | |
| 2633 | }) catch unreachable; | | |
| 2634 | continue; | 2446 | continue; |
| 2635 | }, | 2447 | }, |
| 2636 | else => { | 2448 | else => { |
| 2637 | if (!try parseBlockExpr(&stack, arena, opt_ctx, token.ptr, token.index)) { | 2449 | if (!try parseBlockExpr(&stack, arena, opt_ctx, token.ptr, token.index)) { |
| 2638 | putBackToken(&tok_it, &tree); | 2450 | putBackToken(&tok_it, &tree); |
| 2639 | if (opt_ctx != OptionalCtx.Optional) { | 2451 | if (opt_ctx != OptionalCtx.Optional) { |
| 2640 | *(try tree.errors.addOne()) = Error { | 2452 | ((try tree.errors.addOne())).* = Error{ .ExpectedPrimaryExpr = Error.ExpectedPrimaryExpr{ .token = token.index } }; |
| 2641 | .ExpectedPrimaryExpr = Error.ExpectedPrimaryExpr { .token = token.index }, | | |
| 2642 | }; | | |
| 2643 | return tree; | 2453 | return tree; |
| 2644 | } | 2454 | } |
| 2645 | } | 2455 | } |
| 2646 | continue; | 2456 | continue; |
| 2647 | } | 2457 | }, |
| 2648 | } | 2458 | } |
| 2649 | }, | 2459 | }, |
| 2650 | | 2460 | |
| 2651 | | | |
| 2652 | State.ErrorTypeOrSetDecl => |ctx| { | 2461 | State.ErrorTypeOrSetDecl => |ctx| { |
| 2653 | if (eatToken(&tok_it, &tree, Token.Id.LBrace) == null) { | 2462 | if (eatToken(&tok_it, &tree, Token.Id.LBrace) == null) { |
| 2654 | _ = try createToCtxLiteral(arena, ctx.opt_ctx, ast.Node.ErrorType, ctx.error_token); | 2463 | _ = try createToCtxLiteral(arena, ctx.opt_ctx, ast.Node.ErrorType, ctx.error_token); |
| 2655 | continue; | 2464 | continue; |
| 2656 | } | 2465 | } |
| 2657 | | 2466 | |
| 2658 | const node = try arena.construct(ast.Node.ErrorSetDecl { | 2467 | const node = try arena.construct(ast.Node.ErrorSetDecl{ |
| 2659 | .base = ast.Node { | 2468 | .base = ast.Node{ .id = ast.Node.Id.ErrorSetDecl }, |
| 2660 | .id = ast.Node.Id.ErrorSetDecl, | | |
| 2661 | }, | | |
| 2662 | .error_token = ctx.error_token, | 2469 | .error_token = ctx.error_token, |
| 2663 | .decls = ast.Node.ErrorSetDecl.DeclList.init(arena), | 2470 | .decls = ast.Node.ErrorSetDecl.DeclList.init(arena), |
| 2664 | .rbrace_token = undefined, | 2471 | .rbrace_token = undefined, |
| 2665 | }); | 2472 | }); |
| 2666 | ctx.opt_ctx.store(&node.base); | 2473 | ctx.opt_ctx.store(&node.base); |
| 2667 | | 2474 | |
| 2668 | stack.append(State { | 2475 | stack.append(State{ .ErrorTagListItemOrEnd = ListSave(@typeOf(node.decls)){ |
| 2669 | .ErrorTagListItemOrEnd = ListSave(@typeOf(node.decls)) { | 2476 | .list = &node.decls, |
| 2670 | .list = &node.decls, | 2477 | .ptr = &node.rbrace_token, |
| 2671 | .ptr = &node.rbrace_token, | 2478 | } }) catch unreachable; |
| 2672 | } | | |
| 2673 | }) catch unreachable; | | |
| 2674 | continue; | 2479 | continue; |
| 2675 | }, | 2480 | }, |
| 2676 | State.StringLiteral => |opt_ctx| { | 2481 | State.StringLiteral => |opt_ctx| { |
| 2677 | const token = nextToken(&tok_it, &tree); | 2482 | const token = nextToken(&tok_it, &tree); |
| 2678 | const token_index = token.index; | 2483 | const token_index = token.index; |
| 2679 | const token_ptr = token.ptr; | 2484 | const token_ptr = token.ptr; |
| 2680 | opt_ctx.store( | 2485 | opt_ctx.store((try parseStringLiteral(arena, &tok_it, token_ptr, token_index, &tree)) ?? { |
| 2681 | (try parseStringLiteral(arena, &tok_it, token_ptr, token_index, &tree)) ?? { | 2486 | putBackToken(&tok_it, &tree); |
| 2682 | putBackToken(&tok_it, &tree); | 2487 | if (opt_ctx != OptionalCtx.Optional) { |
| 2683 | if (opt_ctx != OptionalCtx.Optional) { | 2488 | ((try tree.errors.addOne())).* = Error{ .ExpectedPrimaryExpr = Error.ExpectedPrimaryExpr{ .token = token_index } }; |
| 2684 | *(try tree.errors.addOne()) = Error { | 2489 | return tree; |
| 2685 | .ExpectedPrimaryExpr = Error.ExpectedPrimaryExpr { .token = token_index }, | | |
| 2686 | }; | | |
| 2687 | return tree; | | |
| 2688 | } | | |
| 2689 | | | |
| 2690 | continue; | | |
| 2691 | } | 2490 | } |
| 2692 | ); | 2491 | |
| | 2492 | continue; |
| | 2493 | }); |
| 2693 | }, | 2494 | }, |
| 2694 | | 2495 | |
| 2695 | State.Identifier => |opt_ctx| { | 2496 | State.Identifier => |opt_ctx| { |
| ... | @@ -2702,12 +2503,10 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2702,12 +2503,10 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2702 | const token = nextToken(&tok_it, &tree); | 2503 | const token = nextToken(&tok_it, &tree); |
| 2703 | const token_index = token.index; | 2504 | const token_index = token.index; |
| 2704 | const token_ptr = token.ptr; | 2505 | const token_ptr = token.ptr; |
| 2705 | *(try tree.errors.addOne()) = Error { | 2506 | ((try tree.errors.addOne())).* = Error{ .ExpectedToken = Error.ExpectedToken{ |
| 2706 | .ExpectedToken = Error.ExpectedToken { | 2507 | .token = token_index, |
| 2707 | .token = token_index, | 2508 | .expected_id = Token.Id.Identifier, |
| 2708 | .expected_id = Token.Id.Identifier, | 2509 | } }; |
| 2709 | }, | | |
| 2710 | }; | | |
| 2711 | return tree; | 2510 | return tree; |
| 2712 | } | 2511 | } |
| 2713 | }, | 2512 | }, |
| ... | @@ -2718,23 +2517,19 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2718,23 +2517,19 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2718 | const ident_token_index = ident_token.index; | 2517 | const ident_token_index = ident_token.index; |
| 2719 | const ident_token_ptr = ident_token.ptr; | 2518 | const ident_token_ptr = ident_token.ptr; |
| 2720 | if (ident_token_ptr.id != Token.Id.Identifier) { | 2519 | if (ident_token_ptr.id != Token.Id.Identifier) { |
| 2721 | *(try tree.errors.addOne()) = Error { | 2520 | ((try tree.errors.addOne())).* = Error{ .ExpectedToken = Error.ExpectedToken{ |
| 2722 | .ExpectedToken = Error.ExpectedToken { | 2521 | .token = ident_token_index, |
| 2723 | .token = ident_token_index, | 2522 | .expected_id = Token.Id.Identifier, |
| 2724 | .expected_id = Token.Id.Identifier, | 2523 | } }; |
| 2725 | }, | | |
| 2726 | }; | | |
| 2727 | return tree; | 2524 | return tree; |
| 2728 | } | 2525 | } |
| 2729 | | 2526 | |
| 2730 | const node = try arena.construct(ast.Node.ErrorTag { | 2527 | const node = try arena.construct(ast.Node.ErrorTag{ |
| 2731 | .base = ast.Node { | 2528 | .base = ast.Node{ .id = ast.Node.Id.ErrorTag }, |
| 2732 | .id = ast.Node.Id.ErrorTag, | | |
| 2733 | }, | | |
| 2734 | .doc_comments = comments, | 2529 | .doc_comments = comments, |
| 2735 | .name_token = ident_token_index, | 2530 | .name_token = ident_token_index, |
| 2736 | }); | 2531 | }); |
| 2737 | *node_ptr = &node.base; | 2532 | node_ptr.* = &node.base; |
| 2738 | continue; | 2533 | continue; |
| 2739 | }, | 2534 | }, |
| 2740 | | 2535 | |
| ... | @@ -2743,12 +2538,10 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2743,12 +2538,10 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2743 | const token_index = token.index; | 2538 | const token_index = token.index; |
| 2744 | const token_ptr = token.ptr; | 2539 | const token_ptr = token.ptr; |
| 2745 | if (token_ptr.id != token_id) { | 2540 | if (token_ptr.id != token_id) { |
| 2746 | *(try tree.errors.addOne()) = Error { | 2541 | ((try tree.errors.addOne())).* = Error{ .ExpectedToken = Error.ExpectedToken{ |
| 2747 | .ExpectedToken = Error.ExpectedToken { | 2542 | .token = token_index, |
| 2748 | .token = token_index, | 2543 | .expected_id = token_id, |
| 2749 | .expected_id = token_id, | 2544 | } }; |
| 2750 | }, | | |
| 2751 | }; | | |
| 2752 | return tree; | 2545 | return tree; |
| 2753 | } | 2546 | } |
| 2754 | continue; | 2547 | continue; |
| ... | @@ -2758,15 +2551,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2758,15 +2551,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2758 | const token_index = token.index; | 2551 | const token_index = token.index; |
| 2759 | const token_ptr = token.ptr; | 2552 | const token_ptr = token.ptr; |
| 2760 | if (token_ptr.id != expect_token_save.id) { | 2553 | if (token_ptr.id != expect_token_save.id) { |
| 2761 | *(try tree.errors.addOne()) = Error { | 2554 | ((try tree.errors.addOne())).* = Error{ .ExpectedToken = Error.ExpectedToken{ |
| 2762 | .ExpectedToken = Error.ExpectedToken { | 2555 | .token = token_index, |
| 2763 | .token = token_index, | 2556 | .expected_id = expect_token_save.id, |
| 2764 | .expected_id = expect_token_save.id, | 2557 | } }; |
| 2765 | }, | | |
| 2766 | }; | | |
| 2767 | return tree; | 2558 | return tree; |
| 2768 | } | 2559 | } |
| 2769 | *expect_token_save.ptr = token_index; | 2560 | (expect_token_save.ptr).* = token_index; |
| 2770 | continue; | 2561 | continue; |
| 2771 | }, | 2562 | }, |
| 2772 | State.IfToken => |token_id| { | 2563 | State.IfToken => |token_id| { |
| ... | @@ -2779,7 +2570,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2779,7 +2570,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2779 | }, | 2570 | }, |
| 2780 | State.IfTokenSave => |if_token_save| { | 2571 | State.IfTokenSave => |if_token_save| { |
| 2781 | if (eatToken(&tok_it, &tree, if_token_save.id)) |token_index| { | 2572 | if (eatToken(&tok_it, &tree, if_token_save.id)) |token_index| { |
| 2782 | *if_token_save.ptr = token_index; | 2573 | (if_token_save.ptr).* = token_index; |
| 2783 | continue; | 2574 | continue; |
| 2784 | } | 2575 | } |
| 2785 | | 2576 | |
| ... | @@ -2788,7 +2579,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { | ... | @@ -2788,7 +2579,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { |
| 2788 | }, | 2579 | }, |
| 2789 | State.OptionalTokenSave => |optional_token_save| { | 2580 | State.OptionalTokenSave => |optional_token_save| { |
| 2790 | if (eatToken(&tok_it, &tree, optional_token_save.id)) |token_index| { | 2581 | if (eatToken(&tok_it, &tree, optional_token_save.id)) |token_index| { |
| 2791 | *optional_token_save.ptr = token_index; | 2582 | (optional_token_save.ptr).* = token_index; |
| 2792 | continue; | 2583 | continue; |
| 2793 | } | 2584 | } |
| 2794 | | 2585 | |
| ... | @@ -2911,28 +2702,28 @@ const OptionalCtx = union(enum) { | ... | @@ -2911,28 +2702,28 @@ const OptionalCtx = union(enum) { |
| 2911 | Required: &&ast.Node, | 2702 | Required: &&ast.Node, |
| 2912 | | 2703 | |
| 2913 | pub fn store(self: &const OptionalCtx, value: &ast.Node) void { | 2704 | pub fn store(self: &const OptionalCtx, value: &ast.Node) void { |
| 2914 | switch (*self) { | 2705 | switch (self.*) { |
| 2915 | OptionalCtx.Optional => |ptr| *ptr = value, | 2706 | OptionalCtx.Optional => |ptr| ptr.* = value, |
| 2916 | OptionalCtx.RequiredNull => |ptr| *ptr = value, | 2707 | OptionalCtx.RequiredNull => |ptr| ptr.* = value, |
| 2917 | OptionalCtx.Required => |ptr| *ptr = value, | 2708 | OptionalCtx.Required => |ptr| ptr.* = value, |
| 2918 | } | 2709 | } |
| 2919 | } | 2710 | } |
| 2920 | | 2711 | |
| 2921 | pub fn get(self: &const OptionalCtx) ?&ast.Node { | 2712 | pub fn get(self: &const OptionalCtx) ?&ast.Node { |
| 2922 | switch (*self) { | 2713 | switch (self.*) { |
| 2923 | OptionalCtx.Optional => |ptr| return *ptr, | 2714 | OptionalCtx.Optional => |ptr| return ptr.*, |
| 2924 | OptionalCtx.RequiredNull => |ptr| return ??*ptr, | 2715 | OptionalCtx.RequiredNull => |ptr| return ??ptr.*, |
| 2925 | OptionalCtx.Required => |ptr| return *ptr, | 2716 | OptionalCtx.Required => |ptr| return ptr.*, |
| 2926 | } | 2717 | } |
| 2927 | } | 2718 | } |
| 2928 | | 2719 | |
| 2929 | pub fn toRequired(self: &const OptionalCtx) OptionalCtx { | 2720 | pub fn toRequired(self: &const OptionalCtx) OptionalCtx { |
| 2930 | switch (*self) { | 2721 | switch (self.*) { |
| 2931 | OptionalCtx.Optional => |ptr| { | 2722 | OptionalCtx.Optional => |ptr| { |
| 2932 | return OptionalCtx { .RequiredNull = ptr }; | 2723 | return OptionalCtx{ .RequiredNull = ptr }; |
| 2933 | }, | 2724 | }, |
| 2934 | OptionalCtx.RequiredNull => |ptr| return *self, | 2725 | OptionalCtx.RequiredNull => |ptr| return self.*, |
| 2935 | OptionalCtx.Required => |ptr| return *self, | 2726 | OptionalCtx.Required => |ptr| return self.*, |
| 2936 | } | 2727 | } |
| 2937 | } | 2728 | } |
| 2938 | }; | 2729 | }; |
| ... | @@ -3054,7 +2845,6 @@ const State = union(enum) { | ... | @@ -3054,7 +2845,6 @@ const State = union(enum) { |
| 3054 | Identifier: OptionalCtx, | 2845 | Identifier: OptionalCtx, |
| 3055 | ErrorTag: &&ast.Node, | 2846 | ErrorTag: &&ast.Node, |
| 3056 | | 2847 | |
| 3057 | | | |
| 3058 | IfToken: @TagType(Token.Id), | 2848 | IfToken: @TagType(Token.Id), |
| 3059 | IfTokenSave: ExpectTokenSave, | 2849 | IfTokenSave: ExpectTokenSave, |
| 3060 | ExpectToken: @TagType(Token.Id), | 2850 | ExpectToken: @TagType(Token.Id), |
| ... | @@ -3064,16 +2854,14 @@ const State = union(enum) { | ... | @@ -3064,16 +2854,14 @@ const State = union(enum) { |
| 3064 | | 2854 | |
| 3065 | fn pushDocComment(arena: &mem.Allocator, line_comment: TokenIndex, result: &?&ast.Node.DocComment) !void { | 2855 | fn pushDocComment(arena: &mem.Allocator, line_comment: TokenIndex, result: &?&ast.Node.DocComment) !void { |
| 3066 | const node = blk: { | 2856 | const node = blk: { |
| 3067 | if (*result) |comment_node| { | 2857 | if (result.*) |comment_node| { |
| 3068 | break :blk comment_node; | 2858 | break :blk comment_node; |
| 3069 | } else { | 2859 | } else { |
| 3070 | const comment_node = try arena.construct(ast.Node.DocComment { | 2860 | const comment_node = try arena.construct(ast.Node.DocComment{ |
| 3071 | .base = ast.Node { | 2861 | .base = ast.Node{ .id = ast.Node.Id.DocComment }, |
| 3072 | .id = ast.Node.Id.DocComment, | | |
| 3073 | }, | | |
| 3074 | .lines = ast.Node.DocComment.LineList.init(arena), | 2862 | .lines = ast.Node.DocComment.LineList.init(arena), |
| 3075 | }); | 2863 | }); |
| 3076 | *result = comment_node; | 2864 | result.* = comment_node; |
| 3077 | break :blk comment_node; | 2865 | break :blk comment_node; |
| 3078 | } | 2866 | } |
| 3079 | }; | 2867 | }; |
| ... | @@ -3094,24 +2882,20 @@ fn eatDocComments(arena: &mem.Allocator, tok_it: &ast.Tree.TokenList.Iterator, t | ... | @@ -3094,24 +2882,20 @@ fn eatDocComments(arena: &mem.Allocator, tok_it: &ast.Tree.TokenList.Iterator, t |
| 3094 | | 2882 | |
| 3095 | fn eatLineComment(arena: &mem.Allocator, tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree) !?&ast.Node.LineComment { | 2883 | fn eatLineComment(arena: &mem.Allocator, tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree) !?&ast.Node.LineComment { |
| 3096 | const token = eatToken(tok_it, tree, Token.Id.LineComment) ?? return null; | 2884 | const token = eatToken(tok_it, tree, Token.Id.LineComment) ?? return null; |
| 3097 | return try arena.construct(ast.Node.LineComment { | 2885 | return try arena.construct(ast.Node.LineComment{ |
| 3098 | .base = ast.Node { | 2886 | .base = ast.Node{ .id = ast.Node.Id.LineComment }, |
| 3099 | .id = ast.Node.Id.LineComment, | | |
| 3100 | }, | | |
| 3101 | .token = token, | 2887 | .token = token, |
| 3102 | }); | 2888 | }); |
| 3103 | } | 2889 | } |
| 3104 | | 2890 | |
| 3105 | fn parseStringLiteral(arena: &mem.Allocator, tok_it: &ast.Tree.TokenList.Iterator, | 2891 | fn parseStringLiteral(arena: &mem.Allocator, tok_it: &ast.Tree.TokenList.Iterator, token_ptr: &const Token, token_index: TokenIndex, tree: &ast.Tree) !?&ast.Node { |
| 3106 | token_ptr: &const Token, token_index: TokenIndex, tree: &ast.Tree) !?&ast.Node | | |
| 3107 | { | | |
| 3108 | switch (token_ptr.id) { | 2892 | switch (token_ptr.id) { |
| 3109 | Token.Id.StringLiteral => { | 2893 | Token.Id.StringLiteral => { |
| 3110 | return &(try createLiteral(arena, ast.Node.StringLiteral, token_index)).base; | 2894 | return &(try createLiteral(arena, ast.Node.StringLiteral, token_index)).base; |
| 3111 | }, | 2895 | }, |
| 3112 | Token.Id.MultilineStringLiteralLine => { | 2896 | Token.Id.MultilineStringLiteralLine => { |
| 3113 | const node = try arena.construct(ast.Node.MultilineStringLiteral { | 2897 | const node = try arena.construct(ast.Node.MultilineStringLiteral{ |
| 3114 | .base = ast.Node { .id = ast.Node.Id.MultilineStringLiteral }, | 2898 | .base = ast.Node{ .id = ast.Node.Id.MultilineStringLiteral }, |
| 3115 | .lines = ast.Node.MultilineStringLiteral.LineList.init(arena), | 2899 | .lines = ast.Node.MultilineStringLiteral.LineList.init(arena), |
| 3116 | }); | 2900 | }); |
| 3117 | try node.lines.push(token_index); | 2901 | try node.lines.push(token_index); |
| ... | @@ -3135,12 +2919,11 @@ fn parseStringLiteral(arena: &mem.Allocator, tok_it: &ast.Tree.TokenList.Iterato | ... | @@ -3135,12 +2919,11 @@ fn parseStringLiteral(arena: &mem.Allocator, tok_it: &ast.Tree.TokenList.Iterato |
| 3135 | } | 2919 | } |
| 3136 | } | 2920 | } |
| 3137 | | 2921 | |
| 3138 | fn parseBlockExpr(stack: &std.ArrayList(State), arena: &mem.Allocator, ctx: &const OptionalCtx, | 2922 | fn parseBlockExpr(stack: &std.ArrayList(State), arena: &mem.Allocator, ctx: &const OptionalCtx, token_ptr: &const Token, token_index: TokenIndex) !bool { |
| 3139 | token_ptr: &const Token, token_index: TokenIndex) !bool { | | |
| 3140 | switch (token_ptr.id) { | 2923 | switch (token_ptr.id) { |
| 3141 | Token.Id.Keyword_suspend => { | 2924 | Token.Id.Keyword_suspend => { |
| 3142 | const node = try arena.construct(ast.Node.Suspend { | 2925 | const node = try arena.construct(ast.Node.Suspend{ |
| 3143 | .base = ast.Node {.id = ast.Node.Id.Suspend }, | 2926 | .base = ast.Node{ .id = ast.Node.Id.Suspend }, |
| 3144 | .label = null, | 2927 | .label = null, |
| 3145 | .suspend_token = token_index, | 2928 | .suspend_token = token_index, |
| 3146 | .payload = null, | 2929 | .payload = null, |
| ... | @@ -3148,13 +2931,13 @@ fn parseBlockExpr(stack: &std.ArrayList(State), arena: &mem.Allocator, ctx: &con | ... | @@ -3148,13 +2931,13 @@ fn parseBlockExpr(stack: &std.ArrayList(State), arena: &mem.Allocator, ctx: &con |
| 3148 | }); | 2931 | }); |
| 3149 | ctx.store(&node.base); | 2932 | ctx.store(&node.base); |
| 3150 | | 2933 | |
| 3151 | stack.append(State { .SuspendBody = node }) catch unreachable; | 2934 | stack.append(State{ .SuspendBody = node }) catch unreachable; |
| 3152 | try stack.append(State { .Payload = OptionalCtx { .Optional = &node.payload } }); | 2935 | try stack.append(State{ .Payload = OptionalCtx{ .Optional = &node.payload } }); |
| 3153 | return true; | 2936 | return true; |
| 3154 | }, | 2937 | }, |
| 3155 | Token.Id.Keyword_if => { | 2938 | Token.Id.Keyword_if => { |
| 3156 | const node = try arena.construct(ast.Node.If { | 2939 | const node = try arena.construct(ast.Node.If{ |
| 3157 | .base = ast.Node {.id = ast.Node.Id.If }, | 2940 | .base = ast.Node{ .id = ast.Node.Id.If }, |
| 3158 | .if_token = token_index, | 2941 | .if_token = token_index, |
| 3159 | .condition = undefined, | 2942 | .condition = undefined, |
| 3160 | .payload = null, | 2943 | .payload = null, |
| ... | @@ -3163,41 +2946,35 @@ fn parseBlockExpr(stack: &std.ArrayList(State), arena: &mem.Allocator, ctx: &con | ... | @@ -3163,41 +2946,35 @@ fn parseBlockExpr(stack: &std.ArrayList(State), arena: &mem.Allocator, ctx: &con |
| 3163 | }); | 2946 | }); |
| 3164 | ctx.store(&node.base); | 2947 | ctx.store(&node.base); |
| 3165 | | 2948 | |
| 3166 | stack.append(State { .Else = &node.@"else" }) catch unreachable; | 2949 | stack.append(State{ .Else = &node.@"else" }) catch unreachable; |
| 3167 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.body } }); | 2950 | try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.body } }); |
| 3168 | try stack.append(State { .PointerPayload = OptionalCtx { .Optional = &node.payload } }); | 2951 | try stack.append(State{ .PointerPayload = OptionalCtx{ .Optional = &node.payload } }); |
| 3169 | try stack.append(State { .ExpectToken = Token.Id.RParen }); | 2952 | try stack.append(State{ .ExpectToken = Token.Id.RParen }); |
| 3170 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.condition } }); | 2953 | try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.condition } }); |
| 3171 | try stack.append(State { .ExpectToken = Token.Id.LParen }); | 2954 | try stack.append(State{ .ExpectToken = Token.Id.LParen }); |
| 3172 | return true; | 2955 | return true; |
| 3173 | }, | 2956 | }, |
| 3174 | Token.Id.Keyword_while => { | 2957 | Token.Id.Keyword_while => { |
| 3175 | stack.append(State { | 2958 | stack.append(State{ .While = LoopCtx{ |
| 3176 | .While = LoopCtx { | 2959 | .label = null, |
| 3177 | .label = null, | 2960 | .inline_token = null, |
| 3178 | .inline_token = null, | 2961 | .loop_token = token_index, |
| 3179 | .loop_token = token_index, | 2962 | .opt_ctx = ctx.*, |
| 3180 | .opt_ctx = *ctx, | 2963 | } }) catch unreachable; |
| 3181 | } | | |
| 3182 | }) catch unreachable; | | |
| 3183 | return true; | 2964 | return true; |
| 3184 | }, | 2965 | }, |
| 3185 | Token.Id.Keyword_for => { | 2966 | Token.Id.Keyword_for => { |
| 3186 | stack.append(State { | 2967 | stack.append(State{ .For = LoopCtx{ |
| 3187 | .For = LoopCtx { | 2968 | .label = null, |
| 3188 | .label = null, | 2969 | .inline_token = null, |
| 3189 | .inline_token = null, | 2970 | .loop_token = token_index, |
| 3190 | .loop_token = token_index, | 2971 | .opt_ctx = ctx.*, |
| 3191 | .opt_ctx = *ctx, | 2972 | } }) catch unreachable; |
| 3192 | } | | |
| 3193 | }) catch unreachable; | | |
| 3194 | return true; | 2973 | return true; |
| 3195 | }, | 2974 | }, |
| 3196 | Token.Id.Keyword_switch => { | 2975 | Token.Id.Keyword_switch => { |
| 3197 | const node = try arena.construct(ast.Node.Switch { | 2976 | const node = try arena.construct(ast.Node.Switch{ |
| 3198 | .base = ast.Node { | 2977 | .base = ast.Node{ .id = ast.Node.Id.Switch }, |
| 3199 | .id = ast.Node.Id.Switch, | | |
| 3200 | }, | | |
| 3201 | .switch_token = token_index, | 2978 | .switch_token = token_index, |
| 3202 | .expr = undefined, | 2979 | .expr = undefined, |
| 3203 | .cases = ast.Node.Switch.CaseList.init(arena), | 2980 | .cases = ast.Node.Switch.CaseList.init(arena), |
| ... | @@ -3205,45 +2982,43 @@ fn parseBlockExpr(stack: &std.ArrayList(State), arena: &mem.Allocator, ctx: &con | ... | @@ -3205,45 +2982,43 @@ fn parseBlockExpr(stack: &std.ArrayList(State), arena: &mem.Allocator, ctx: &con |
| 3205 | }); | 2982 | }); |
| 3206 | ctx.store(&node.base); | 2983 | ctx.store(&node.base); |
| 3207 | | 2984 | |
| 3208 | stack.append(State { | 2985 | stack.append(State{ .SwitchCaseOrEnd = ListSave(@typeOf(node.cases)){ |
| 3209 | .SwitchCaseOrEnd = ListSave(@typeOf(node.cases)) { | 2986 | .list = &node.cases, |
| 3210 | .list = &node.cases, | 2987 | .ptr = &node.rbrace, |
| 3211 | .ptr = &node.rbrace, | 2988 | } }) catch unreachable; |
| 3212 | }, | 2989 | try stack.append(State{ .ExpectToken = Token.Id.LBrace }); |
| 3213 | }) catch unreachable; | 2990 | try stack.append(State{ .ExpectToken = Token.Id.RParen }); |
| 3214 | try stack.append(State { .ExpectToken = Token.Id.LBrace }); | 2991 | try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.expr } }); |
| 3215 | try stack.append(State { .ExpectToken = Token.Id.RParen }); | 2992 | try stack.append(State{ .ExpectToken = Token.Id.LParen }); |
| 3216 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.expr } }); | | |
| 3217 | try stack.append(State { .ExpectToken = Token.Id.LParen }); | | |
| 3218 | return true; | 2993 | return true; |
| 3219 | }, | 2994 | }, |
| 3220 | Token.Id.Keyword_comptime => { | 2995 | Token.Id.Keyword_comptime => { |
| 3221 | const node = try arena.construct(ast.Node.Comptime { | 2996 | const node = try arena.construct(ast.Node.Comptime{ |
| 3222 | .base = ast.Node {.id = ast.Node.Id.Comptime }, | 2997 | .base = ast.Node{ .id = ast.Node.Id.Comptime }, |
| 3223 | .comptime_token = token_index, | 2998 | .comptime_token = token_index, |
| 3224 | .expr = undefined, | 2999 | .expr = undefined, |
| 3225 | .doc_comments = null, | 3000 | .doc_comments = null, |
| 3226 | }); | 3001 | }); |
| 3227 | ctx.store(&node.base); | 3002 | ctx.store(&node.base); |
| 3228 | | 3003 | |
| 3229 | try stack.append(State { .Expression = OptionalCtx { .Required = &node.expr } }); | 3004 | try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.expr } }); |
| 3230 | return true; | 3005 | return true; |
| 3231 | }, | 3006 | }, |
| 3232 | Token.Id.LBrace => { | 3007 | Token.Id.LBrace => { |
| 3233 | const block = try arena.construct(ast.Node.Block { | 3008 | const block = try arena.construct(ast.Node.Block{ |
| 3234 | .base = ast.Node {.id = ast.Node.Id.Block }, | 3009 | .base = ast.Node{ .id = ast.Node.Id.Block }, |
| 3235 | .label = null, | 3010 | .label = null, |
| 3236 | .lbrace = token_index, | 3011 | .lbrace = token_index, |
| 3237 | .statements = ast.Node.Block.StatementList.init(arena), | 3012 | .statements = ast.Node.Block.StatementList.init(arena), |
| 3238 | .rbrace = undefined, | 3013 | .rbrace = undefined, |
| 3239 | }); | 3014 | }); |
| 3240 | ctx.store(&block.base); | 3015 | ctx.store(&block.base); |
| 3241 | stack.append(State { .Block = block }) catch unreachable; | 3016 | stack.append(State{ .Block = block }) catch unreachable; |
| 3242 | return true; | 3017 | return true; |
| 3243 | }, | 3018 | }, |
| 3244 | else => { | 3019 | else => { |
| 3245 | return false; | 3020 | return false; |
| 3246 | } | 3021 | }, |
| 3247 | } | 3022 | } |
| 3248 | } | 3023 | } |
| 3249 | | 3024 | |
| ... | @@ -3257,20 +3032,16 @@ fn expectCommaOrEnd(tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree, end: | ... | @@ -3257,20 +3032,16 @@ fn expectCommaOrEnd(tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree, end: |
| 3257 | const token_index = token.index; | 3032 | const token_index = token.index; |
| 3258 | const token_ptr = token.ptr; | 3033 | const token_ptr = token.ptr; |
| 3259 | switch (token_ptr.id) { | 3034 | switch (token_ptr.id) { |
| 3260 | Token.Id.Comma => return ExpectCommaOrEndResult { .end_token = null}, | 3035 | Token.Id.Comma => return ExpectCommaOrEndResult{ .end_token = null }, |
| 3261 | else => { | 3036 | else => { |
| 3262 | if (end == token_ptr.id) { | 3037 | if (end == token_ptr.id) { |
| 3263 | return ExpectCommaOrEndResult { .end_token = token_index }; | 3038 | return ExpectCommaOrEndResult{ .end_token = token_index }; |
| 3264 | } | 3039 | } |
| 3265 | | 3040 | |
| 3266 | return ExpectCommaOrEndResult { | 3041 | return ExpectCommaOrEndResult{ .parse_error = Error{ .ExpectedCommaOrEnd = Error.ExpectedCommaOrEnd{ |
| 3267 | .parse_error = Error { | 3042 | .token = token_index, |
| 3268 | .ExpectedCommaOrEnd = Error.ExpectedCommaOrEnd { | 3043 | .end_id = end, |
| 3269 | .token = token_index, | 3044 | } } }; |
| 3270 | .end_id = end, | | |
| 3271 | }, | | |
| 3272 | }, | | |
| 3273 | }; | | |
| 3274 | }, | 3045 | }, |
| 3275 | } | 3046 | } |
| 3276 | } | 3047 | } |
| ... | @@ -3278,103 +3049,102 @@ fn expectCommaOrEnd(tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree, end: | ... | @@ -3278,103 +3049,102 @@ fn expectCommaOrEnd(tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree, end: |
| 3278 | fn tokenIdToAssignment(id: &const Token.Id) ?ast.Node.InfixOp.Op { | 3049 | fn tokenIdToAssignment(id: &const Token.Id) ?ast.Node.InfixOp.Op { |
| 3279 | // TODO: We have to cast all cases because of this: | 3050 | // TODO: We have to cast all cases because of this: |
| 3280 | // error: expected type '?InfixOp', found '?@TagType(InfixOp)' | 3051 | // error: expected type '?InfixOp', found '?@TagType(InfixOp)' |
| 3281 | return switch (*id) { | 3052 | return switch (id.*) { |
| 3282 | Token.Id.AmpersandEqual => ast.Node.InfixOp.Op { .AssignBitAnd = {} }, | 3053 | Token.Id.AmpersandEqual => ast.Node.InfixOp.Op{ .AssignBitAnd = {} }, |
| 3283 | Token.Id.AngleBracketAngleBracketLeftEqual => ast.Node.InfixOp.Op { .AssignBitShiftLeft = {} }, | 3054 | Token.Id.AngleBracketAngleBracketLeftEqual => ast.Node.InfixOp.Op{ .AssignBitShiftLeft = {} }, |
| 3284 | Token.Id.AngleBracketAngleBracketRightEqual => ast.Node.InfixOp.Op { .AssignBitShiftRight = {} }, | 3055 | Token.Id.AngleBracketAngleBracketRightEqual => ast.Node.InfixOp.Op{ .AssignBitShiftRight = {} }, |
| 3285 | Token.Id.AsteriskEqual => ast.Node.InfixOp.Op { .AssignTimes = {} }, | 3056 | Token.Id.AsteriskEqual => ast.Node.InfixOp.Op{ .AssignTimes = {} }, |
| 3286 | Token.Id.AsteriskPercentEqual => ast.Node.InfixOp.Op { .AssignTimesWarp = {} }, | 3057 | Token.Id.AsteriskPercentEqual => ast.Node.InfixOp.Op{ .AssignTimesWarp = {} }, |
| 3287 | Token.Id.CaretEqual => ast.Node.InfixOp.Op { .AssignBitXor = {} }, | 3058 | Token.Id.CaretEqual => ast.Node.InfixOp.Op{ .AssignBitXor = {} }, |
| 3288 | Token.Id.Equal => ast.Node.InfixOp.Op { .Assign = {} }, | 3059 | Token.Id.Equal => ast.Node.InfixOp.Op{ .Assign = {} }, |
| 3289 | Token.Id.MinusEqual => ast.Node.InfixOp.Op { .AssignMinus = {} }, | 3060 | Token.Id.MinusEqual => ast.Node.InfixOp.Op{ .AssignMinus = {} }, |
| 3290 | Token.Id.MinusPercentEqual => ast.Node.InfixOp.Op { .AssignMinusWrap = {} }, | 3061 | Token.Id.MinusPercentEqual => ast.Node.InfixOp.Op{ .AssignMinusWrap = {} }, |
| 3291 | Token.Id.PercentEqual => ast.Node.InfixOp.Op { .AssignMod = {} }, | 3062 | Token.Id.PercentEqual => ast.Node.InfixOp.Op{ .AssignMod = {} }, |
| 3292 | Token.Id.PipeEqual => ast.Node.InfixOp.Op { .AssignBitOr = {} }, | 3063 | Token.Id.PipeEqual => ast.Node.InfixOp.Op{ .AssignBitOr = {} }, |
| 3293 | Token.Id.PlusEqual => ast.Node.InfixOp.Op { .AssignPlus = {} }, | 3064 | Token.Id.PlusEqual => ast.Node.InfixOp.Op{ .AssignPlus = {} }, |
| 3294 | Token.Id.PlusPercentEqual => ast.Node.InfixOp.Op { .AssignPlusWrap = {} }, | 3065 | Token.Id.PlusPercentEqual => ast.Node.InfixOp.Op{ .AssignPlusWrap = {} }, |
| 3295 | Token.Id.SlashEqual => ast.Node.InfixOp.Op { .AssignDiv = {} }, | 3066 | Token.Id.SlashEqual => ast.Node.InfixOp.Op{ .AssignDiv = {} }, |
| 3296 | else => null, | 3067 | else => null, |
| 3297 | }; | 3068 | }; |
| 3298 | } | 3069 | } |
| 3299 | | 3070 | |
| 3300 | fn tokenIdToUnwrapExpr(id: @TagType(Token.Id)) ?ast.Node.InfixOp.Op { | 3071 | fn tokenIdToUnwrapExpr(id: @TagType(Token.Id)) ?ast.Node.InfixOp.Op { |
| 3301 | return switch (id) { | 3072 | return switch (id) { |
| 3302 | Token.Id.Keyword_catch => ast.Node.InfixOp.Op { .Catch = null }, | 3073 | Token.Id.Keyword_catch => ast.Node.InfixOp.Op{ .Catch = null }, |
| 3303 | Token.Id.QuestionMarkQuestionMark => ast.Node.InfixOp.Op { .UnwrapMaybe = void{} }, | 3074 | Token.Id.QuestionMarkQuestionMark => ast.Node.InfixOp.Op{ .UnwrapMaybe = void{} }, |
| 3304 | else => null, | 3075 | else => null, |
| 3305 | }; | 3076 | }; |
| 3306 | } | 3077 | } |
| 3307 | | 3078 | |
| 3308 | fn tokenIdToComparison(id: @TagType(Token.Id)) ?ast.Node.InfixOp.Op { | 3079 | fn tokenIdToComparison(id: @TagType(Token.Id)) ?ast.Node.InfixOp.Op { |
| 3309 | return switch (id) { | 3080 | return switch (id) { |
| 3310 | Token.Id.BangEqual => ast.Node.InfixOp.Op { .BangEqual = void{} }, | 3081 | Token.Id.BangEqual => ast.Node.InfixOp.Op{ .BangEqual = void{} }, |
| 3311 | Token.Id.EqualEqual => ast.Node.InfixOp.Op { .EqualEqual = void{} }, | 3082 | Token.Id.EqualEqual => ast.Node.InfixOp.Op{ .EqualEqual = void{} }, |
| 3312 | Token.Id.AngleBracketLeft => ast.Node.InfixOp.Op { .LessThan = void{} }, | 3083 | Token.Id.AngleBracketLeft => ast.Node.InfixOp.Op{ .LessThan = void{} }, |
| 3313 | Token.Id.AngleBracketLeftEqual => ast.Node.InfixOp.Op { .LessOrEqual = void{} }, | 3084 | Token.Id.AngleBracketLeftEqual => ast.Node.InfixOp.Op{ .LessOrEqual = void{} }, |
| 3314 | Token.Id.AngleBracketRight => ast.Node.InfixOp.Op { .GreaterThan = void{} }, | 3085 | Token.Id.AngleBracketRight => ast.Node.InfixOp.Op{ .GreaterThan = void{} }, |
| 3315 | Token.Id.AngleBracketRightEqual => ast.Node.InfixOp.Op { .GreaterOrEqual = void{} }, | 3086 | Token.Id.AngleBracketRightEqual => ast.Node.InfixOp.Op{ .GreaterOrEqual = void{} }, |
| 3316 | else => null, | 3087 | else => null, |
| 3317 | }; | 3088 | }; |
| 3318 | } | 3089 | } |
| 3319 | | 3090 | |
| 3320 | fn tokenIdToBitShift(id: @TagType(Token.Id)) ?ast.Node.InfixOp.Op { | 3091 | fn tokenIdToBitShift(id: @TagType(Token.Id)) ?ast.Node.InfixOp.Op { |
| 3321 | return switch (id) { | 3092 | return switch (id) { |
| 3322 | Token.Id.AngleBracketAngleBracketLeft => ast.Node.InfixOp.Op { .BitShiftLeft = void{} }, | 3093 | Token.Id.AngleBracketAngleBracketLeft => ast.Node.InfixOp.Op{ .BitShiftLeft = void{} }, |
| 3323 | Token.Id.AngleBracketAngleBracketRight => ast.Node.InfixOp.Op { .BitShiftRight = void{} }, | 3094 | Token.Id.AngleBracketAngleBracketRight => ast.Node.InfixOp.Op{ .BitShiftRight = void{} }, |
| 3324 | else => null, | 3095 | else => null, |
| 3325 | }; | 3096 | }; |
| 3326 | } | 3097 | } |
| 3327 | | 3098 | |
| 3328 | fn tokenIdToAddition(id: @TagType(Token.Id)) ?ast.Node.InfixOp.Op { | 3099 | fn tokenIdToAddition(id: @TagType(Token.Id)) ?ast.Node.InfixOp.Op { |
| 3329 | return switch (id) { | 3100 | return switch (id) { |
| 3330 | Token.Id.Minus => ast.Node.InfixOp.Op { .Sub = void{} }, | 3101 | Token.Id.Minus => ast.Node.InfixOp.Op{ .Sub = void{} }, |
| 3331 | Token.Id.MinusPercent => ast.Node.InfixOp.Op { .SubWrap = void{} }, | 3102 | Token.Id.MinusPercent => ast.Node.InfixOp.Op{ .SubWrap = void{} }, |
| 3332 | Token.Id.Plus => ast.Node.InfixOp.Op { .Add = void{} }, | 3103 | Token.Id.Plus => ast.Node.InfixOp.Op{ .Add = void{} }, |
| 3333 | Token.Id.PlusPercent => ast.Node.InfixOp.Op { .AddWrap = void{} }, | 3104 | Token.Id.PlusPercent => ast.Node.InfixOp.Op{ .AddWrap = void{} }, |
| 3334 | Token.Id.PlusPlus => ast.Node.InfixOp.Op { .ArrayCat = void{} }, | 3105 | Token.Id.PlusPlus => ast.Node.InfixOp.Op{ .ArrayCat = void{} }, |
| 3335 | else => null, | 3106 | else => null, |
| 3336 | }; | 3107 | }; |
| 3337 | } | 3108 | } |
| 3338 | | 3109 | |
| 3339 | fn tokenIdToMultiply(id: @TagType(Token.Id)) ?ast.Node.InfixOp.Op { | 3110 | fn tokenIdToMultiply(id: @TagType(Token.Id)) ?ast.Node.InfixOp.Op { |
| 3340 | return switch (id) { | 3111 | return switch (id) { |
| 3341 | Token.Id.Slash => ast.Node.InfixOp.Op { .Div = void{} }, | 3112 | Token.Id.Slash => ast.Node.InfixOp.Op{ .Div = void{} }, |
| 3342 | Token.Id.Asterisk => ast.Node.InfixOp.Op { .Mult = void{} }, | 3113 | Token.Id.Asterisk => ast.Node.InfixOp.Op{ .Mult = void{} }, |
| 3343 | Token.Id.AsteriskAsterisk => ast.Node.InfixOp.Op { .ArrayMult = void{} }, | 3114 | Token.Id.AsteriskAsterisk => ast.Node.InfixOp.Op{ .ArrayMult = void{} }, |
| 3344 | Token.Id.AsteriskPercent => ast.Node.InfixOp.Op { .MultWrap = void{} }, | 3115 | Token.Id.AsteriskPercent => ast.Node.InfixOp.Op{ .MultWrap = void{} }, |
| 3345 | Token.Id.Percent => ast.Node.InfixOp.Op { .Mod = void{} }, | 3116 | Token.Id.Percent => ast.Node.InfixOp.Op{ .Mod = void{} }, |
| 3346 | Token.Id.PipePipe => ast.Node.InfixOp.Op { .MergeErrorSets = void{} }, | 3117 | Token.Id.PipePipe => ast.Node.InfixOp.Op{ .MergeErrorSets = void{} }, |
| 3347 | else => null, | 3118 | else => null, |
| 3348 | }; | 3119 | }; |
| 3349 | } | 3120 | } |
| 3350 | | 3121 | |
| 3351 | fn tokenIdToPrefixOp(id: @TagType(Token.Id)) ?ast.Node.PrefixOp.Op { | 3122 | fn tokenIdToPrefixOp(id: @TagType(Token.Id)) ?ast.Node.PrefixOp.Op { |
| 3352 | return switch (id) { | 3123 | return switch (id) { |
| 3353 | Token.Id.Bang => ast.Node.PrefixOp.Op { .BoolNot = void{} }, | 3124 | Token.Id.Bang => ast.Node.PrefixOp.Op{ .BoolNot = void{} }, |
| 3354 | Token.Id.Tilde => ast.Node.PrefixOp.Op { .BitNot = void{} }, | 3125 | Token.Id.Tilde => ast.Node.PrefixOp.Op{ .BitNot = void{} }, |
| 3355 | Token.Id.Minus => ast.Node.PrefixOp.Op { .Negation = void{} }, | 3126 | Token.Id.Minus => ast.Node.PrefixOp.Op{ .Negation = void{} }, |
| 3356 | Token.Id.MinusPercent => ast.Node.PrefixOp.Op { .NegationWrap = void{} }, | 3127 | Token.Id.MinusPercent => ast.Node.PrefixOp.Op{ .NegationWrap = void{} }, |
| 3357 | Token.Id.Asterisk, Token.Id.AsteriskAsterisk => ast.Node.PrefixOp.Op { .Deref = void{} }, | 3128 | Token.Id.Asterisk, |
| 3358 | Token.Id.Ampersand => ast.Node.PrefixOp.Op { | 3129 | Token.Id.AsteriskAsterisk => ast.Node.PrefixOp.Op{ .Deref = void{} }, |
| 3359 | .AddrOf = ast.Node.PrefixOp.AddrOfInfo { | 3130 | Token.Id.Ampersand => ast.Node.PrefixOp.Op{ .AddrOf = ast.Node.PrefixOp.AddrOfInfo{ |
| 3360 | .align_expr = null, | 3131 | .align_expr = null, |
| 3361 | .bit_offset_start_token = null, | 3132 | .bit_offset_start_token = null, |
| 3362 | .bit_offset_end_token = null, | 3133 | .bit_offset_end_token = null, |
| 3363 | .const_token = null, | 3134 | .const_token = null, |
| 3364 | .volatile_token = null, | 3135 | .volatile_token = null, |
| 3365 | }, | 3136 | } }, |
| 3366 | }, | 3137 | Token.Id.QuestionMark => ast.Node.PrefixOp.Op{ .MaybeType = void{} }, |
| 3367 | Token.Id.QuestionMark => ast.Node.PrefixOp.Op { .MaybeType = void{} }, | 3138 | Token.Id.QuestionMarkQuestionMark => ast.Node.PrefixOp.Op{ .UnwrapMaybe = void{} }, |
| 3368 | Token.Id.QuestionMarkQuestionMark => ast.Node.PrefixOp.Op { .UnwrapMaybe = void{} }, | 3139 | Token.Id.Keyword_await => ast.Node.PrefixOp.Op{ .Await = void{} }, |
| 3369 | Token.Id.Keyword_await => ast.Node.PrefixOp.Op { .Await = void{} }, | 3140 | Token.Id.Keyword_try => ast.Node.PrefixOp.Op{ .Try = void{} }, |
| 3370 | Token.Id.Keyword_try => ast.Node.PrefixOp.Op { .Try = void{ } }, | | |
| 3371 | else => null, | 3141 | else => null, |
| 3372 | }; | 3142 | }; |
| 3373 | } | 3143 | } |
| 3374 | | 3144 | |
| 3375 | fn createLiteral(arena: &mem.Allocator, comptime T: type, token_index: TokenIndex) !&T { | 3145 | fn createLiteral(arena: &mem.Allocator, comptime T: type, token_index: TokenIndex) !&T { |
| 3376 | return arena.construct(T { | 3146 | return arena.construct(T{ |
| 3377 | .base = ast.Node {.id = ast.Node.typeToId(T)}, | 3147 | .base = ast.Node{ .id = ast.Node.typeToId(T) }, |
| 3378 | .token = token_index, | 3148 | .token = token_index, |
| 3379 | }); | 3149 | }); |
| 3380 | } | 3150 | } |
| ... | @@ -3389,15 +3159,14 @@ fn createToCtxLiteral(arena: &mem.Allocator, opt_ctx: &const OptionalCtx, compti | ... | @@ -3389,15 +3159,14 @@ fn createToCtxLiteral(arena: &mem.Allocator, opt_ctx: &const OptionalCtx, compti |
| 3389 | fn eatToken(tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree, id: @TagType(Token.Id)) ?TokenIndex { | 3159 | fn eatToken(tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree, id: @TagType(Token.Id)) ?TokenIndex { |
| 3390 | const token = nextToken(tok_it, tree); | 3160 | const token = nextToken(tok_it, tree); |
| 3391 | | 3161 | |
| 3392 | if (token.ptr.id == id) | 3162 | if (token.ptr.id == id) return token.index; |
| 3393 | return token.index; | | |
| 3394 | | 3163 | |
| 3395 | putBackToken(tok_it, tree); | 3164 | putBackToken(tok_it, tree); |
| 3396 | return null; | 3165 | return null; |
| 3397 | } | 3166 | } |
| 3398 | | 3167 | |
| 3399 | fn nextToken(tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree) AnnotatedToken { | 3168 | fn nextToken(tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree) AnnotatedToken { |
| 3400 | const result = AnnotatedToken { | 3169 | const result = AnnotatedToken{ |
| 3401 | .index = tok_it.index, | 3170 | .index = tok_it.index, |
| 3402 | .ptr = ??tok_it.next(), | 3171 | .ptr = ??tok_it.next(), |
| 3403 | }; | 3172 | }; |