JetBrains / JetBrains/Grammar-Kit

Left rules with "more than one quantifier"

Open
#396 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
771
Forks
137
Avg merge
11h 14m
Merged PRs (30d)
1

Description

I have a rule in my plugin
```
private index_or_call_expr ::= simple_reference (index_access | func_call)+

left func_call ::= func_args | ':' simple_reference func_args
left index_access ::= ...
```

When I run it in debug mode I get an error that: `Another not done marker added after this one. Must be done before this.`

When I change the quantifier to `*` I don't see this error.
The only difference I see in the generated parser is that with `+` we `marker` call that wraps the rest of the calls
```
private static boolean index_or_call_expr_1(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "index_or_call_expr_1")) return false;
boolean r;
//==========================
Marker m = enter_section_(b);
r = index_or_call_expr_1_0(b, l + 1);
//==========================
while (r) {
int c = current_position_(b);
if (!index_or_call_expr_1_0(b, l + 1)) break;
if (!empty_element_parsed_guard_(b, "index_or_call_expr_1", c)) break;
}
exit_section_(b, m, null, r);
return r;
}
```

The call stack is:
```
at com.intellij.lang.parser.GeneratedParserUtilBase.exit_section_(GeneratedParserUtilBase.java:480)
at com.github.aleksandrsl.intellijluau.parser.LuauParser.func_call(LuauParser.java:879)
at com.github.aleksandrsl.intellijluau.parser.LuauParser.index_or_call_expr_1_0(LuauParser.java:1495)
at com.github.aleksandrsl.intellijluau.parser.LuauParser.index_or_call_expr_1(LuauParser.java:1483)
at com.github.aleksandrsl.intellijluau.parser.LuauParser.index_or_call_expr(LuauParser.java:1470)
```

So basically
1. We enter the section
2. Parse the first `index_or_call_expr_1_0` it parses as true
3. Try parsing the second `index_or_call_expr_1_0` inside the loop it parses as false calls exit and fails

If I comment the marker inside `index_or_call_expr_1` everything works fine, so I guess the `func_call` calling the `exit` being `left` tries to close `marker` that is before the `marker` open in `index_or_call_expr_1`

To sum up:
`left` + `+` - errors
`left` + `*` - works fine
`+` - works fine

---

The question is it expected behaviour or I just shouldn't write this and use left only with `*`?

I'm on "2022.3.2.2" version of GrammarKit

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with GeneratedParserUtilBase.java at exit_section_ and the generated LuauParser.java methods index_or_call_expr, index_or_call_expr_1, and func_call. Compare the generated behavior for the left rule with + and * quantifiers, then determine whether the marker nesting is expected; done means the reported debug-mode error is explained or reproduced with a focused regression case.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.