feat(asm): Phase A.0 — add kw_asm keyword + lex test
`asm` now lexes as a dedicated `kw_asm` keyword (Token.Tag + keyword map entry).
`volatile` and `clobbers` stay out of the global keyword table — they are
recognized contextually only inside an `asm { … }` body (PLAN-ASM Deviation 4).
- token.zig: kw_asm tag + `.{ "asm", .kw_asm }` map entry.
- lsp/server.zig: classifyToken exhaustive switch gained the .kw_asm arm
(the new enum value forced coverage — intended tripwire).
- lexer.test.zig (new, wired into root.zig barrel): locks `asm`->kw_asm and
`volatile`/`clobbers`->identifier.
Lock commit (behavior-locking passing test). zig build test green (445 unit).
This commit is contained in:
14
src/lexer.test.zig
Normal file
14
src/lexer.test.zig
Normal file
@@ -0,0 +1,14 @@
|
||||
const std = @import("std");
|
||||
const Lexer = @import("lexer.zig").Lexer;
|
||||
const Tag = @import("token.zig").Tag;
|
||||
|
||||
// ASM stream Phase A.0: `asm` lexes as the dedicated `kw_asm` keyword, while
|
||||
// `volatile` / `clobbers` deliberately stay plain identifiers (recognized
|
||||
// contextually inside an `asm { … }` body, never reserved globally).
|
||||
test "lex asm keyword; volatile/clobbers stay identifiers" {
|
||||
var lex = Lexer.init("asm volatile clobbers");
|
||||
const expected = [_]Tag{ .kw_asm, .identifier, .identifier };
|
||||
for (expected) |exp| {
|
||||
try std.testing.expectEqual(exp, lex.next().tag);
|
||||
}
|
||||
}
|
||||
@@ -1685,6 +1685,7 @@ pub const Server = struct {
|
||||
.kw_callconv,
|
||||
.kw_extern,
|
||||
.kw_export,
|
||||
.kw_asm,
|
||||
.hash_run,
|
||||
.hash_import,
|
||||
.hash_insert,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
pub const llvm_api = @import("llvm_api.zig");
|
||||
pub const token = @import("token.zig");
|
||||
pub const lexer = @import("lexer.zig");
|
||||
pub const lexer_tests = @import("lexer.test.zig");
|
||||
pub const ast = @import("ast.zig");
|
||||
pub const parser = @import("parser.zig");
|
||||
pub const print = @import("print.zig");
|
||||
|
||||
@@ -45,6 +45,7 @@ pub const Tag = enum {
|
||||
kw_callconv, // callconv (calling convention annotation)
|
||||
kw_extern, // extern (import: external linkage, C ABI, no body)
|
||||
kw_export, // export (define + expose: external linkage, C ABI)
|
||||
kw_asm, // asm (inline assembly expression / global asm decl)
|
||||
|
||||
// Symbols
|
||||
colon, // :
|
||||
@@ -283,6 +284,9 @@ pub const keywords = std.StaticStringMap(Tag).initComptime(.{
|
||||
.{ "callconv", .kw_callconv },
|
||||
.{ "extern", .kw_extern },
|
||||
.{ "export", .kw_export },
|
||||
// `asm` is a real keyword; `volatile` / `clobbers` stay OUT of this table
|
||||
// (recognized contextually only inside an `asm { … }` body — see PLAN-ASM).
|
||||
.{ "asm", .kw_asm },
|
||||
});
|
||||
|
||||
pub fn getKeyword(bytes: []const u8) ?Tag {
|
||||
|
||||
Reference in New Issue
Block a user