antlr / stringtemplate4

StringTemplate 4
http://www.stringtemplate.org
Other
956 stars 231 forks source link

Hidden argument <i> reported as an error when rendering templates #289

Closed alexZaicev closed 3 years ago

alexZaicev commented 3 years ago

Upon rendering the following templates as an example:

// START: sequences_grammar
sequences_grammar() ::= <<
<sequences.keys:{k| <sequence_grammar(k)>}; separator="\n">
>>
// END: sequences_grammar

// START: sequence_grammar
sequence_grammar(k) ::= <<

<k>
returns [<k; format="firstUppercased">.Builder builder]
  :
  {
    $builder = <k; format="firstUppercased">.newBuilder();
  }
  (
    <sequences.(k):{l| <sq_entry(l)>}; separator="\n    ">
  )
  ;
>>
// END: sequence_grammar

// START: sq_entry
sq_entry(k) ::= <<
( v<i>=<k; format="cardinalityTrimmed"> { $builder.<k; format="setterNamed">($v<i>.builder); } )<k; format="cardinality">
>>
// END: sq_entry

in the logs I found that ST4 reports hidden argument <i> as <string> 421:20: implicitly-defined attribute i not visible

parrt commented 3 years ago

Hmm... it looks like you are using i at the start of sq_entry(k) but <i> is only available inside of {...} blocks.

alexZaicev commented 3 years ago

@parrt thank you for noticing the issue! I fixed it and now argument is passed into the function from the parent function.