Giter Site home page Giter Site logo

recursive call of the templates a parameter being passed through, suddenly changes its value between the calls. about stringtemplate4 HOT 3 CLOSED

antlr avatar antlr commented on July 28, 2024
recursive call of the templates a parameter being passed through, suddenly changes its value between the calls.

from stringtemplate4.

Comments (3)

parrt avatar parrt commented on July 28, 2024

Find STRecursionBug.zip in attachments.

from stringtemplate4.

sharwell avatar sharwell commented on July 28, 2024

You are invoking templates with unbound anonymous templates as arguments, with the syntax {...}.

std_field_dropdown(dropdown_field,depends_from) ::= <<
<std_field(dropdown_field,{<std_field_id(dropdown_field.name,[])>},depends_from)>
>>

std_field_selection(selection_field,sel_bt,depends_from) ::= <<
<std_field(selection_field,{<std_field_id(selection_field.name,sel_bt.value)>},depends_from)>
>>

std_field_text(text_field,depend_on) ::= <<
<std_field(text_field,{<std_field_id(text_field.name,[])>},depend_on)>
>>

std_field_textarea(txtarea_field,depends) ::= <<
<std_field(txtarea_field,{<std_field_id(txtarea_field.name,[])>},depends)>
>>

These templates are bound at the time they are rendered, which is a different context from where they are created. What you want to do is force these anonymous templates to bind and render in the current context and pass the evaluated result as the argument, with the syntax ({...}).

std_field_dropdown(dropdown_field,depends_from) ::= <<
<std_field(dropdown_field,({<std_field_id(dropdown_field.name,[])>}),depends_from)>
>>

std_field_selection(selection_field,sel_bt,depends_from) ::= <<
<std_field(selection_field,({<std_field_id(selection_field.name,sel_bt.value)>}),depends_from)>
>>

std_field_text(text_field,depend_on) ::= <<
<std_field(text_field,({<std_field_id(text_field.name,[])>}),depend_on)>
>>

std_field_textarea(txtarea_field,depends) ::= <<
<std_field(txtarea_field,({<std_field_id(txtarea_field.name,[])>}),depends)>
>>

from stringtemplate4.

parrt avatar parrt commented on July 28, 2024

just to be clear

std_field_dropdown(dropdown_field,depends_from) ::= <<
<std_field(dropdown_field,{<std_field_id(dropdown_field.name,[])>},depends_from)>
>>

passes an anonymous template, referencing argument dropdown_field, to another template whose context does not have dropdown_field. ST does dynamic lookup of attributes and does not bind them like closures would in a programming language.

from stringtemplate4.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.