0xMiden / 0xMiden/tree-sitter-masm

Grammar accepts if/else blocks with an empty then branch

Open Beginner friendly
#1 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
0
Forks
1
PR merge metrics
No merged PRs in 30d

Description

`tree-sitter-masm` currently allows an `if` node whose first branch is empty as long as an `else` branch is present:

```masm
proc example
if.true
else
push.1
end
end
```

The grammar has a dedicated alternative for this shape:

```js
choice(
seq("else", field("else_body", $.block)),
seq(
field("then_body", $.block),
optional(seq("else", field("else_body", optional($.block))))
)
)
```

That means editor tooling can mark this as valid MASM even though the assembler rejects empty `if` blocks. In `0xMiden/miden-vm`, `crates/assembly/src/tests.rs` has an `empty_if` regression test that expects `begin if.true end end` to fail with:

```text
invalid syntax: expected a non-empty `if` block
```

The tree-sitter grammar should require a non-empty `then_body` before an optional `else` branch, matching the assembler syntax.

Contributor guide

Open the contributing guide

Research direction

The grammar is in the repository's main file, likely grammar.js. Look at the rule for if statements; the current choice allows an empty then_body. Modify it to require a non-empty block before the optional else. Test by building the parser and checking that the example from the issue is now invalid. The regression test in miden-vm's crates/assembly/src/tests.rs shows the expected error message.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
75/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.