ReviewOS

home-lang/home

Parser: 'is' and 'test' should be contextual keywords (6 kernel files blocked)

#47
Closed glennmichael123 opened this 24 days ago · 0 comments
24 days ago

Problem

is and test are reserved keywords in Home (used for type narrowing predicates and unit tests respectively), but the parser treats them as reserved everywhere — including the binding-name slot of let/var declarations, where there's no ambiguity:

var is: u32 = port_read32(port, PORT_IS)   // ahci.home:384
let test: *VerificationTest = &tests[idx]  // network_stack_verification.home:265
let test = &suite.tests[idx]               // test/framework.home:194

All produce error[EP0001]: Expected variable name.

Affected kernel files

  • kernel/src/drivers/ahci.home:384 (is)
  • kernel/src/drivers/storage/ahci.home:580 (is)
  • kernel/src/test/framework.home:194 (test)
  • kernel/src/net/network_stack_verification.home:265 (test)
  • kernel/src/ml/autograd.home:605 (test)
  • kernel/src/mm/user_space.home:278 (test)

(Bucket 'Expected variable name', 6/66 of remaining kernel parse failures.)

Expected behavior

is and test should be contextual keywords: reserved only in their syntactic positions, parseable as plain identifiers everywhere else. Specifically:

  • is is a keyword only in pattern/type-narrowing position (e.g. if x is Foo { ... })
  • test is a keyword only at top-level when followed by a string literal: test \"name\" { ... }

In all other contexts (let/var binding names, struct field names, parameter names, function names), they should parse as identifiers.

Implementation hint

Audit the lexer: confirm is / test are emitted as distinct token kinds (e.g. Tok.Is, Tok.Test). In parseLetDecl / parseVarDecl / parseFnParam / parseStructField, where the parser reads an identifier for the binding name, accept these two token kinds as identifiers. The cleanest fix is a small isIdentifierLikeToken helper.

Tests to add

  • var is: u32 = 0 parses
  • let test = 1 parses
  • test \"name\" { ... } still parses as a unit test (no regression)
  • if x is Foo { ... } still parses as a type-narrow (no regression)

Acceptance

  1. The 6 listed kernel files clear home-debug ast (parser side; is may still need to typecheck against the local declared type).
  2. No regressions on if x is T and top-level test \"...\" blocks.
  3. Existing test suite green.

Sign in to comment on this issue.