antlr / antlr/stringtemplate4

StackOverFlow when template is recursive

Open
#110 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

I use the template as recursion, it will cause stack overflow. I'm sure there will not be an endless recursive call.
The template looks as following:

```
struct(name, struct) ::= <<
}>
>>

anonymousStruct(name1, field) ::= <<

}, field.asStruct)>

>>
```

In the above code, the struct() in anonymousStruct() can be call one time, the second time will cause stack overflow.
If I change "name1" to "name", the first time when call struct() in annonymousStruct() will cause stack overflow.

When I try to solve the problem, I find even there is no recursion, the stack overflow may happen.
Here I try to combine name1 and name2 into one name.

```
entry() ::= <<

>>

combine(name1, name2) ::= <<
})>
>>

combineoutput(name) ::= <<

>>

combineoutput2(name1) ::= <<

>>
```

combineoutput2 and combineoutput is just like the situation when I mentioned above.

If I really want to combine names in template, How can I solve the problem?

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.