Skip to content

feat: add edition directive support to the parser - #16

Merged
SammyBytes merged 2 commits into
mainfrom
feat/edition-support
Nov 17, 2026
Merged

SammyBytes merged 2 commits into
mainfrom
feat/edition-support

Conversation

@SammyBytes

Copy link
Copy Markdown
Owner

Summary

Adds the edition directive to the Sam parser and records the language edition on the AST. Branched directly from main.

Behavior

  • edition is now a lexer keyword.
  • ProgramNode exposes edition: SamEdition.
  • With no directive, the edition defaults to "2026".
  • edition "2026" at the top of the file sets the program edition.
  • Unsupported editions (e.g. "2099") fail with the supported list.
  • An edition directive after another declaration fails with its line and column.

Tests

In packages/compiler/src/parser/index.test.ts:

  1. No edition → ast.edition === "2026".
  2. edition "2026" at the top → ast.edition === "2026".
  3. edition "2099" → Unsupported edition '2099'.
  4. edition "2026" below a provider → position error (line 6, column 5).

Verification

  • bun test: 128 pass, 1 skip, 0 fail
  • bun run typecheck: no errors

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Sam PR Review

Verdict: approve · Risk: low

The patch correctly adds edition support, updates lexer, AST, parser, and tests. No obvious bugs or security issues were found.

Advisory review generated by Sam with Groq. It does not approve or block the pull request; ci.yml remains the required check.

@SammyBytes

Copy link
Copy Markdown
Owner Author

Applied in 14dbc6d.

  1. ../lexer import — not actually broken: lexer/index.ts re-exports Token and TokenType, which is why typecheck passed. Still switched parser/types.ts to ../lexer/tokens to match the other parser files and make the dependency explicit.
  2. Duplicated edition logic — removed the double EDITION check and duplicate default. parse() now resolves the edition once, and parseHeaderEdition() only consumes edition "<year>"; the caller guarantees the token.
  3. Position test — added a case where edition follows a flow, asserting line 2, column 1; the existing provider case asserts line 6, column 5.

Verification: 129 pass, 1 skip, 0 fail; typecheck clean.

- tokenize `edition` as a keyword and track the Sam edition on the AST
- default the program edition to "2026" when no directive is present
- parse `edition "2026"` at the top of the file and reject unsupported
  editions with the supported list
- reject edition directives that appear after another declaration
- add parser tests for the default, valid, unsupported, and misplaced
  edition cases
- import Token types directly from `../lexer/tokens` in parser/types.ts
- resolve the edition once in parse() instead of checking EDITION twice
- add a test asserting the line and column of an edition directive that
  follows a flow
@SammyBytes
SammyBytes merged commit d89bf9f into main Nov 17, 2026
8 checks passed
@SammyBytes
SammyBytes deleted the feat/edition-support branch November 17, 2026 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant