Skip to content

Grammar2 - #17

Open
EugeneKornev wants to merge 27 commits into
nsu-syspro:mainfrom
EugeneKornev:grammar2
Open

EugeneKornev wants to merge 27 commits into
nsu-syspro:mainfrom
EugeneKornev:grammar2

Conversation

@EugeneKornev

Copy link
Copy Markdown

No description provided.

EugeneKornev and others added 27 commits September 18, 2026 18:27
…hema validation

- meta.schema.json now requires 'grammar', 'stages', 'exit' properties
- Create test/validate_schemas.py — validates config.json and all meta.json
  files against their schemas, with clear error messages
- Add schema validation step to both CI workflows (ci.yml, tests.yml)
  before running tests, ensuring invalid meta.json is caught early
Add tokens.schema.json to validate test tokens.json files.
Mandatory fields: kind (string), line (integer >=1), column (integer >=1).
Optional field: value (string).
The validate_schemas.py script now also loads tokens.schema.json and
validates every tokens.json found under test/. The schema requires:
  - kind (string), line (integer >=1), column (integer >=1) — mandatory
  - value (string) — optional

This runs in CI as part of the 'Validate JSON schemas' step in both
ci.yml and tests.yml workflows.
- Create ast.schema.json for AST tree validation: each node requires
  line, column, kind; allows any other fields (value, elems, body, …).
- Update tokens.schema.json: remove 'value' from properties (no longer
  tracked in schema), remove 'additionalProperties: false' so any token
  fields are accepted. Only 'kind', 'line', 'column' remain required.
Each AST node now has:
- elems: ordered list of child nodes (previously in named fields like
  body, left, right, cond, then, else, init, etc.)
- value: scalar payload (name, op, message, field, type, literal value)
  or null for nodes without one
- Extra fields (mut, type, returnType, etc.) preserved
All ast.json golden files regenerated using the fixed compiler that:
- Removes AST_EXPR_STMT wrapper from expression statements
- Produces correct elems arrays per documented format
  (Declare: [name, init], FuncDecl: [name, params..., body],
   ExternDecl: [name, params...], StructDecl: [name, fields...],
   Param: [name], FieldAccess: [base, name])
- Reports correct line/column positions (first token of each node)
- Drops the value field (not compared during golden validation)
Verify that top-level declarations (extern, def, struct) can appear
in any order at the top level:

- grammar3: def and extern interleaved
- grammar4: def and extern with typed params/return types
- grammar5: struct, extern, and def all interleaved
The run_tests.py output format recently changed:
- list command now groups tests under === STAGE === headers with
  indented names (no stage/ prefix)
- test/update commands now group results under === STAGE === headers
  and print names without stage prefix
- config stage key is 'compiler' not 'compile'

Also fix test_compiler_update_regenerates_and_exit_warning to
produce non-empty stdout so the golden file is written.

All 54 self-tests now pass.
Adds 5 new self-tests covering recently added features in run_tests.py:
- Backward compat: stages=['compiler'] auto-adds 'run' stage
- Backward compat: exit dict for 'run' stage falls back to 'compiler' key
- run_exec update with empty stdout removes golden and reports message
- LLVM stage golden comparison is skipped without --check-ir flag
- Fuzz tests in list output use separate FUZZ header with stage/name format

All 59 self-tests pass (54 existing + 5 new).
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.

2 participants