| 1 | //! A subset of the compiler is exposed to wasm |
| 2 | //! This powers the playground |
| 3 | |
| 4 | extern fn iterateTokenCallback( |
| 5 | tag: i32, |
| 6 | offset: ByteOffset, |
| 7 | ) void; |
| 8 | |
| 9 | export fn iterateTokens( |
| 10 | source_bytes: [*]const u8, |
| 11 | source_len: u32, |
| 12 | ) callconv(.C) i32 { |
| 13 | core.unicode_props.init() catch @panic("unicode_props.init failed"); |
| 14 | |
| 15 | var tokenizer: Tokenizer = .{ .code = source_bytes[0..source_len :0], .pos = 0 }; |
| 16 | tokenizer.skipWhitespace(); |
| 17 | while (tokenizer.next()) |token| { |
| 18 | iterateTokenCallback(@intFromEnum(token.tag), token.offset); |
| 19 | tokenizer.skipWhitespace(); |
| 20 | } |
| 21 | |
| 22 | return -1; |
| 23 | } |
| 24 | |
| 25 | const std = @import("std"); |
| 26 | const core = @import("core"); |
| 27 | const Tokenizer = core.Tokenizer; |
| 28 | const Token = Tokenizer.Token; |
| 29 | const ByteOffset = Tokenizer.ByteOffset; |
| 30 | |
| 31 | const wasm_allocator = std.heap.wasm_allocator; |