Skip to content

Commit 7ae0b13

Browse files
olwangclaude
andcommitted
refactor(selfhost): finish id-constant coverage (word_id returns + id compares)
Follow-up to the previous sweep, which only converted the wid:/code: arg sites and kind assignments. Convert the remaining raw token/word ids: - word_id: returns WORD_* instead of raw 1..30 (the not-a-keyword `return 0` sentinel stays). - is_ident_tok: k == TOK_IDENT || k == TOK_KEYWORD (was 1 || 6). - starts_top_level_item: WORD_* disjunction (was raw v == 17 || 16 || ...). - parser is_feature_tok: WORD_* disjunction (was raw v == 26 || 9 || ...). Also narrow the coverage comment to name exactly what is covered (kinds, symbol codes, word ids — including word_id returns and the id compares) and what intentionally is not (raw ASCII char-code compares in the char scanners, and the 0 / -1 sentinels), so it no longer over-claims. Corpus parity still byte-for-byte green over 556 files (lexer/parser/checker). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 50c9a96 commit 7ae0b13

2 files changed

Lines changed: 41 additions & 35 deletions

File tree

selfhost/parser.rss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn is_feature_tok(toks: read List<Tok>, i: read Int) -> Bool {
3838
return false
3939
}
4040
let v = tk_val(toks: read toks, i: read i)
41-
return v == 26 || v == 9 || v == 27 || v == 14 || v == 28 || v == 29 || v == 30
41+
return v == WORD_LOCAL || v == WORD_NATIVE || v == WORD_UNSAFE || v == WORD_ASYNC || v == WORD_DEVICE || v == WORD_FFI || v == WORD_REFLECTION
4242
}
4343

4444
fn feature_dup(toks: read List<Tok>, fstart: read Int, k: read Int) -> Bool {

selfhost/scan.rss

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,14 @@ struct Tok {
3636
}
3737

3838
// --- Named ids (replace the raw numeric tables the scanner/parser/checker share).
39-
// These are the single source of truth for token kinds, symbol codes, and
40-
// declaration-keyword ids; every `kind`/`code:`/`wid:` site refers to one of them.
39+
// These are the single source of truth for the three id spaces: token KINDS
40+
// (Tok.kind), symbol token CODES (Tok.val for symbols), and declaration-keyword
41+
// WORD ids (Tok.val for idents/keywords). Every token-kind, symbol-code, and
42+
// word-id site — assignments, `code:`/`wid:` args, `word_id` returns, and the
43+
// comparisons in is_ident_tok / starts_top_level_item / is_feature_tok — refers
44+
// to one of these constants. NOT covered (intentionally): the raw ASCII
45+
// character-code compares inside the low-level char scanners (e.g. `c1 == 34`
46+
// for `"`), which pair with adjacent char literals, and the 0 / -1 sentinels.
4147

4248
// Token kinds (Tok.kind). 0 = "no token emitted this step" and -1 = "index past
4349
// end" are sentinels, NOT token kinds, so they stay as bare literals.
@@ -415,36 +421,36 @@ fn scan_ident(chars: read List<Char>, n: read Int, i: read Int) -> Int {
415421
// Map an identifier/keyword's text to a small word id the tools recognize.
416422
// Anything the tools never check by name maps to 0.
417423
fn word_id(word: read String) -> Int {
418-
if word == "fn" { return 1 }
419-
if word == "struct" { return 2 }
420-
if word == "class" { return 3 }
421-
if word == "resource" { return 4 }
422-
if word == "opaque" { return 5 }
423-
if word == "sum" { return 6 }
424-
if word == "protocol" { return 7 }
425-
if word == "impl" { return 8 }
426-
if word == "native" { return 9 }
427-
if word == "module" { return 10 }
428-
if word == "type" { return 11 }
429-
if word == "const" { return 12 }
430-
if word == "pub" { return 13 }
431-
if word == "async" { return 14 }
432-
if word == "use" { return 15 }
433-
if word == "profile" { return 16 }
434-
if word == "features" { return 17 }
435-
if word == "for" { return 18 }
436-
if word == "deprecated" { return 19 }
437-
if word == "lower_name" { return 20 }
438-
if word == "derives" { return 21 }
439-
if word == "effects" { return 22 }
440-
if word == "fresh" { return 23 }
441-
if word == "_" { return 24 }
442-
if word == "as" { return 25 }
443-
if word == "local" { return 26 }
444-
if word == "unsafe" { return 27 }
445-
if word == "device" { return 28 }
446-
if word == "ffi" { return 29 }
447-
if word == "reflection" { return 30 }
424+
if word == "fn" { return WORD_FN }
425+
if word == "struct" { return WORD_STRUCT }
426+
if word == "class" { return WORD_CLASS }
427+
if word == "resource" { return WORD_RESOURCE }
428+
if word == "opaque" { return WORD_OPAQUE }
429+
if word == "sum" { return WORD_SUM }
430+
if word == "protocol" { return WORD_PROTOCOL }
431+
if word == "impl" { return WORD_IMPL }
432+
if word == "native" { return WORD_NATIVE }
433+
if word == "module" { return WORD_MODULE }
434+
if word == "type" { return WORD_TYPE }
435+
if word == "const" { return WORD_CONST }
436+
if word == "pub" { return WORD_PUB }
437+
if word == "async" { return WORD_ASYNC }
438+
if word == "use" { return WORD_USE }
439+
if word == "profile" { return WORD_PROFILE }
440+
if word == "features" { return WORD_FEATURES }
441+
if word == "for" { return WORD_FOR }
442+
if word == "deprecated" { return WORD_DEPRECATED }
443+
if word == "lower_name" { return WORD_LOWER_NAME }
444+
if word == "derives" { return WORD_DERIVES }
445+
if word == "effects" { return WORD_EFFECTS }
446+
if word == "fresh" { return WORD_FRESH }
447+
if word == "_" { return WORD_UNDERSCORE }
448+
if word == "as" { return WORD_AS }
449+
if word == "local" { return WORD_LOCAL }
450+
if word == "unsafe" { return WORD_UNSAFE }
451+
if word == "device" { return WORD_DEVICE }
452+
if word == "ffi" { return WORD_FFI }
453+
if word == "reflection" { return WORD_REFLECTION }
448454
return 0
449455
}
450456

@@ -604,7 +610,7 @@ fn tk_line(toks: read List<Tok>, i: read Int) -> Int {
604610

605611
fn is_ident_tok(toks: read List<Tok>, i: read Int) -> Bool {
606612
let k = tk_kind(toks: read toks, i: read i)
607-
return k == 1 || k == 6
613+
return k == TOK_IDENT || k == TOK_KEYWORD
608614
}
609615

610616
// at_ident: token i is an Ident/Keyword with the given word id.
@@ -697,7 +703,7 @@ fn starts_top_level_item(toks: read List<Tok>, index: read Int) -> Bool {
697703
return false
698704
}
699705
let v = tk_val(toks: read toks, i: read index)
700-
return v == 17 || v == 16 || v == 3 || v == 2 || v == 4 || v == 1 || v == 13 || v == 14 || v == 9 || v == 7 || v == 8
706+
return v == WORD_FEATURES || v == WORD_PROFILE || v == WORD_CLASS || v == WORD_STRUCT || v == WORD_RESOURCE || v == WORD_FN || v == WORD_PUB || v == WORD_ASYNC || v == WORD_NATIVE || v == WORD_PROTOCOL || v == WORD_IMPL
701707
}
702708

703709
fn function_signature_end(toks: read List<Tok>, start: read Int) -> Int {

0 commit comments

Comments
 (0)