Note that there are some explanatory texts on larger screens.

plurals
  1. POANTLR StringTemplate infinite loop while rendering the template
    primarykey
    data
    text
    <p>I am using antlr-3.4-complete.jar which i believe is using StringTemplate version 3.2.1</p> <p>I have the following productions in the tree grammar</p> <pre><code>functionCall : ^(FUNCCALL NCName pr+=params*) -&gt;template(n={$NCName.text},p={$pr})"&lt;n&gt; &lt;p&gt;" </code></pre> <p>The above StringTemplate runs correctly and is generating correct output.</p> <p>I have another production in the same grammar which is very similar to the production above</p> <pre><code>step : axisSpecifier nodeTest pred+=predicate* -&gt;template(a={$axisSpecifier.st},n={$nodeTest.st},pc={$pred})"&lt;a&gt; &lt;n&gt; &lt;pc&gt;" ; </code></pre> <p>But when i print the template it goes in infinite recursion, the stack is as below</p> <pre><code>Exception in thread "main" java.lang.StackOverflowError at org.antlr.stringtemplate.StringTemplate.getAttributeRenderer(StringTemplate.java:1080) at org.antlr.stringtemplate.StringTemplate.getAttributeRenderer(StringTemplate.java:1080) at org.antlr.stringtemplate.StringTemplate.getAttributeRenderer(StringTemplate.java:1080) at org.antlr.stringtemplate.StringTemplate.getAttributeRenderer(StringTemplate.java:1080) at org.antlr.stringtemplate.StringTemplate.getAttributeRenderer(StringTemplate.java:1080) at org.antlr.stringtemplate.StringTemplate.getAttributeRenderer(StringTemplate.java:1080) at org.antlr.stringtemplate.StringTemplate.getAttributeRenderer(StringTemplate.java:1080) at org.antlr.stringtemplate.StringTemplate.getAttributeRenderer(StringTemplate.java:1080) at org.antlr.stringtemplate.StringTemplate.getAttributeRenderer(StringTemplate.java:1080) at org.antlr.stringtemplate.StringTemplate.getAttributeRenderer(StringTemplate.java:1080) at org.antlr.stringtemplate.StringTemplate.getAttributeRenderer(StringTemplate.java:1080) at org.antlr.stringtemplate.StringTemplate.getAttributeRenderer(StringTemplate.java:1080) at org.antlr.stringtemplate.StringTemplate.getAttributeRenderer(StringTemplate.java:1080) at org.antlr.stringtemplate.StringTemplate.getAttributeRenderer(StringTemplate.java:1080) at org.antlr.stringtemplate.StringTemplate.getAttributeRenderer(StringTemplate.java:1080) </code></pre> <p>The generated code for the above production is as below</p> <pre><code>retval.st = new StringTemplate(templateLib, "&lt;a&gt; &lt;n&gt; &lt;pc&gt;",new STAttrMap().put("a", (axisSpecifier14!=null?axisSpecifier14.st:null)).put("n", (nodeTest15!=null?nodeTest15.st:null)).put("pc", list_pred)); </code></pre> <p>The <code>list_pred</code> is the list containing the StringTemplates for <code>predicate*</code>. When i debug the code i find that just before the above line, the individual StringTemplates are fine. By being fine i mean i can read the value in the debugger as the String value. But as soon as the above line is executed, i.e. <code>new StringTemplate</code> is done, the <code>toString()</code> method starts to fail. not only for the new StringTemplate but also for the StringTemplate <code>list_pred</code></p> <p>I am unable to go forward with my work, as i dont think this is a problem with my grammar, as another production with same structure is working fine.</p> <p>Can this error occur because of the parameter names i have chosen? </p> <p><code>template(a={$axisSpecifier.st},n={$nodeTest.st},pc={$pred})"&lt;a&gt; &lt;n&gt; &lt;pc&gt;"</code></p> <p>if i change the names from <code>a</code>,<code>n</code>,<code>pc</code> to something else will it help? as i see i have used the same names other places in the grammar also.</p> <p>I suspect the method</p> <p><code>StringTemplate.breakTemplateIntoChunks()</code> might be the reason here? as this method will parse the template.</p> <p>Can someone familiar with StringTemplate internals help me with this issue?</p> <p>Thanks, Regards, Vimal</p> <p><strong>UPDATE:</strong> This is the output from my AST construction, this also forms the input for treeGrammar. <code>(VARREF abc) / (STEPS (STEP child x (PRED (&lt; (STEPS (STEP child price)) 10)))) END</code> </p> <p>The <code>PRED</code> is the predicate which is also an <code>Expr</code></p> <p>My Tree Grammars with ST is as follows.</p> <pre><code>expr : ^('&lt;' e1=expr e2=expr) -&gt;template(e11={$e1.st},e21={$e2.st})"\&lt; &lt;e11&gt; &lt;e21&gt;" | mainexpr -&gt; template(mnexpr={$mainexpr.st})"&lt;mnexpr&gt;" ; mainexpr scope { boolean isRLP ; } : filterExpr ('/' {$mainexpr::isRLP = true;} relativeLocationPath)? -&gt; {$mainexpr::isRLP}? template(filtr={$filterExpr.st},rlp= {$relativeLocationPath.st})"&lt;filtr&gt; &lt;rlp&gt;" -&gt; template(filtr={$filterExpr.st})"&lt;filtr&gt;" | relativeLocationPath -&gt; template(rlp={$relativeLocationPath.st})"&lt;rlp&gt;" ; relativeLocationPath : ^(STEPS st+=steps+) -&gt; template(stps={$st})"&lt;stps&gt;"; steps : ^(STEP step) -&gt;template(stp={$step.st})"&lt;stp&gt;" ; step : axisSpecifier nodeTest (pred+=predicate)* -&gt;template(axs={$axisSpecifier.st},ndtst={$nodeTest.st},stppred={$pred})"&lt;axs&gt; &lt;ndtst&gt; &lt;stppred&gt;" ; predicate : ^(PRED expr) -&gt;template(predexp={$expr.st})"&lt;predexp&gt;" ; </code></pre> <p>Output of LintMode:</p> <pre><code>Exception in thread "main" java.lang.IllegalStateException: infinite recursion to &lt;anonymous([])@76&gt; referenced in &lt;anonymous([])@69&gt;; stack trace: &lt;anonymous([])@76&gt;, attributes=[predexp=&lt;anonymous()@75&gt;], references=[predexp, stppred]&gt; &lt;anonymous([])@69&gt;, attributes=[ndtst=&lt;anonymous()@68&gt;, stppred, axs=&lt;anonymous()@67&gt;], references=[axs, ndtst, stppred]&gt; &lt;anonymous([])@70&gt;, attributes=[stp=&lt;anonymous()@69&gt;], references=[stp, stppred]&gt; &lt;anonymous([])@71&gt;, attributes=[stps=List[..&lt;anonymous()@70&gt;..]], references=[stps, stppred]&gt; &lt;anonymous([])@72&gt;, attributes=[rlp=&lt;anonymous()@71&gt;], references=[rlp, stppred]&gt; &lt;anonymous([])@73&gt;, attributes=[mnexpr=&lt;anonymous()@72&gt;], references=[mnexpr, stppred]&gt; &lt;anonymous([])@75&gt;, attributes=[e21=&lt;anonymous()@74&gt;, e11=&lt;anonymous()@73&gt;], references=[e11, stppred]&gt; &lt;anonymous([])@76&gt; (start of recursive cycle) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload