Skip to content

Comments

Add tree-sitter-fe grammar to monorepo#1264

Merged
micahscopes merged 9 commits intoargotorg:masterfrom
micahscopes:treesitter
Feb 21, 2026
Merged

Add tree-sitter-fe grammar to monorepo#1264
micahscopes merged 9 commits intoargotorg:masterfrom
micahscopes:treesitter

Conversation

@micahscopes
Copy link
Collaborator

@micahscopes micahscopes commented Feb 19, 2026

Summary

  • Adds a complete tree-sitter grammar for Fe at crates/tree-sitter-fe, consolidated from the standalone repo for easier co-maintenance with the compiler
  • Includes an external scanner (scanner.c) for < disambiguation (generics vs comparison), automatic semicolons, and method chaining
  • Adds dir-test integration tests in crates/parser that parse all .fe fixtures with tree-sitter: a strict suite (110 files, 100% pass) and a coverage regression suite (363 files)
  • Ships editor query files (highlights, brackets, indents, injections, outline)
  • Parser.c built at -O2 even in debug profile (96K-line state machine is unusable at -O0)

Test plan

  • cargo test -p parser passes (tree-sitter fixture parse tests)
  • cargo build -p tree-sitter-fe succeeds
  • Verify Zed extension loads grammar from crates/tree-sitter-fe path

Consolidates the tree-sitter grammar (previously in a separate repo)
into the main Fe repository for easier maintenance and testing.
Move tree-sitter-fe grammar into crates/ as a workspace member. Add
dir-test driven integration tests to the parser crate that parse all
existing .fe fixtures (syntax nodes, formatter, core/std ingots) with
tree-sitter and assert no ERROR nodes.

Fix unsafe extern block for edition 2024 compatibility.

92 of 117 fixtures pass; failures are expected on files using ref/own/mut
syntax not yet supported by the grammar.
Grammar fixes:
- Add labeled parameter support (from sender: address)
- Add mode_type (ref/mut/own type prefixes) and mode_expression
- Add mode prefix in call_arg for (mut x) arguments
- Extend scoped_path with generic args on path segments (Foo<T>::method)
- Fix nested record/path_tuple patterns in record_pattern_field
- Add pattern bindings in recv_arm_pattern
- Fix scanner < disambiguation: track paren/bracket/brace depth,
  reject ||/&&/=>/.. as generic markers, handle << for nested
  qualified paths, distinguish { block bodies from {expr} const generics

Build system:
- Auto-run tree-sitter generate when grammar.js is newer than parser.c
- Always optimize parser.c at -O2 (96K-line state machine is unusable
  at -O0 in debug builds)

Tests:
- Split into strict test (110 files, must be 100%) and coverage test
  (363 files, regression threshold at 83%)
- Coverage spans syntax_node, fmt, core/std ingots, fe_test, cli_output,
  and all uitest fixture suites
- Exclude intentionally broken files (parse_error.fe) and standalone
  pattern fragments (pats/)
- Support combined receiver modes (`mut own self`, `mut ref self`)
- Make mode expressions bare prefix operators instead of requiring parens
- Add mut_pattern for mutable bindings in patterns (`Some(mut t)`)
- Support qualified paths in recv arm patterns and record pattern fields
- Add attribute call expressions (`#[selector = sol("...")]`)
- Support generic args in uses clauses (`uses Storage<T>`) and with params
- Remove redundant mode-prefixed call_arg variant (handled by mode_expression)

Raises coverage test pass rate from 87% to threshold-passing levels.
Strict test (110 files) still passes at 100%.
Unary + is a real Fe operator (prefix binding power 145 in the native
parser). Naively adding it conflicted with + as the type bound separator
in where clauses — tree-sitter preferred unary + over continuing the
bound list.

Fix: make type_bound_list explicitly left-recursive with
prec.right(UNARY+1) so the + continuation always wins over the unary
interpretation. Both `+expr` and `T: A + B + C` now parse correctly.
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2b285d3c31

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

The scanner stopped searching for a matching '>' after 256 characters,
causing valid generic argument lists longer than that to be mistokenized
as COMPARISON_LT. Remove the cap so disambiguation runs to completion.
Collapses parser.c, grammar.json, and node-types.json in GitHub diffs.
Use println! for cargo:warning= directives in build.rs (Cargo reads
build script directives from stdout, not stderr). Allow print_stderr
clippy lint in tree-sitter parse test file for progress output.
@micahscopes
Copy link
Collaborator Author

@g-r-a-n-t this should be ready for review now

@micahscopes micahscopes merged commit 0d15a58 into argotorg:master Feb 21, 2026
5 checks passed
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