tiny.smg.tree.runtime.scanner
Defined in tree.runtime.
API (6)
Actions
Public operations.
Types and contracts
Public types and contracts.
Source
Source: tools/smg/src/tree/runtime/root.zig:6
zig
pub const scanner = @import("scanner.zig");Source: tools/smg/src/tree/runtime/scanner.zig
zig
const std = @import("std");const scanners = @import("../scanner/root.zig");const abi = @import("abi.zig");const lexer = @import("lexer.zig");pub const Kind = enum { zig, javascript, typescript, tsx, c, cpp,};pub const State = union(enum) { none, cpp: scanners.cpp.Scanner, pub fn init(kind: Kind) State { return if (kind == .cpp) .{ .cpp = .{} } else .none; } pub fn eql(left: State, right: State) bool { if (std.meta.activeTag(left) != std.meta.activeTag(right)) return false; return switch (left) { .none => true, .cpp => |value| std.meta.eql(value, right.cpp), }; } pub fn isEmpty(self: State) bool { return switch (self) { .none => true, .cpp => |value| value.delimiter_length == 0, }; }};pub fn scan(kind: Kind, state: *State, input: *lexer.Lexer, valid: []const bool) bool { return switch (kind) { .zig, .c => false, .javascript => blk: { var value = scanners.javascript.Scanner{}; break :blk value.scan(input, @bitCast(bits(u8, valid))); }, .typescript, .tsx => blk: { var value = scanners.typescript.Scanner{}; break :blk value.scan(input, @bitCast(bits(u16, valid))); }, .cpp => state.cpp.scan(input, @bitCast(bits(u8, valid))), };}fn bits(comptime T: type, valid: []const bool) T { var result: T = 0; for (valid, 0..) |enabled, index| { if (enabled) result |= @as(T, 1) << @intCast(index); } return result;}test "scanner state is copied by value" { var left = State.init(.cpp); const right = left; try std.testing.expect(left.eql(right)); left.cpp.delimiter_length = 1; try std.testing.expect(!left.eql(right));}test "runtime scanner dispatch never calls grammar link anchors" { var state = State.init(.javascript); var input = lexer.Lexer.init("}", .{ .byte = 0, .point = .{ .row = 0, .column = 0 } }); input.start(); var valid = @as([8]bool, @splat(false)); valid[0] = true; try std.testing.expect(scan(.javascript, &state, &input, &valid)); try std.testing.expectEqual(@as(abi.Symbol, 0), input.abi.result_symbol);}Complete caller list for tree.runtime.scanner.State.init
7 direct callers.
tools.smg.src.tree.runtime.parser.testVersion[function] — private; no exact target attools/smg/src/tree/runtime/parser.zig:681in nearest public ownertiny.smg.tree.runtime.parsertools.smg.src.tree.runtime.parser.test_focused_active_version_compaction_ranks_precedence_before_stable_identities[function] — test; no exact target attools/smg/src/tree/runtime/parser.zig:472in nearest public ownertiny.smg.tree.runtime.parsertools.smg.src.tree.runtime.parser.test_focused_equal-precedence_active_version_compaction_retains_the_first_six_identities[function] — test; no exact target attools/smg/src/tree/runtime/parser.zig:428in nearest public ownertiny.smg.tree.runtime.parsertools.smg.src.tree.runtime.scanner.test_runtime_scanner_dispatch_never_calls_grammar_link_anchors[function] — test; no exact target attools/smg/src/tree/runtime/scanner.zig:71in nearest public ownertiny.smg.tree.runtime.scannertools.smg.src.tree.runtime.scanner.test_scanner_state_is_copied_by_value[function] — test; no exact target attools/smg/src/tree/runtime/scanner.zig:63in nearest public ownertiny.smg.tree.runtime.scannertiny.smg.tree.runtime.stack.Branch.init[function] attools/smg/src/tree/runtime/stack.zig:145tools.smg.src.tree.runtime.stack.test_focused_graph_links_compare_serialized_external_scanner_state[function] — test; no exact target attools/smg/src/tree/runtime/stack.zig:452in nearest public ownertiny.smg.tree.runtime.stack
Audit
| Definitions | 7 |
|---|---|
| Public names | 7 |
| Members | 8 |
| Version | 26.7.0 |
| Revision | daab053ee433 |