antlr / antlr/stringtemplate4

Zip map wrongly requires i0 and i in the argument list

Open
#320 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
1k
Forks
234
PR merge metrics
No merged PRs in 30d

Description

According to the user guide:

```stringtemplate
parens(x) ::= "()"
main() ::= "<["a", "b", "c"]:parens()>"
```

works and actually does fine. But the following doesn't:

```stringtemplate
parens(x, y) ::= "(, )"
main() ::= "<["a", "b", "c"], ["1", "2", "3"]:parens()>"
```

The error says `parens` requires `i0` and `i`. So the following works:

```stringtemplate
parens(x, y, i, i0) ::= "(, )"
main() ::= "<["a", "b", "c"], ["1", "2", "3"]:parens()>"
```

The same works with anonymous template as follows:

```stringtemplate
parens(x, y) ::= "(, )"
main() ::= "<["a", "b", "c"], ["1", "2", "3"]:{x, y | parens(x, y) }>"
```

If `i` and `i0` are intended to be available only in anonymous subtemplates (the doc seems suggesting so),
then at least the behavior must be consistent across non-zipping and zipping cases.

In non-zipping case, `i` and `i0` aren't required and even if we specify them, no indices are passed in.
But in zipping case, if we add `i` and `i0` to the argument list, the proper indices are passed in.

That's weird to me.

**UPDATE**: I read `Interpreter.java` and for the `zip_map`, `if (st.impl.isAnonSubtemplate)` check around `st.rawSetAttribute("i0", i0)` seems omitted by mistake. `rot_map` and `rot_map_iterator` have one.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.