Skip to content

Archive Trac dn frag2code

madscatt edited this page Jun 20, 2026 · 1 revision

Dn Frag2Code

Legacy Trac archive page imported from dn_frag2code. Source: https://genapp.rocks/wiki/wiki/dn_frag2code. Review age, links, and examples before treating as current.

fragments to useable code

  • the genapp/languages/{language}.json files define the assembly of output from code fragements

creating one output file

  • as an example, one could add this section to the assembly array
                   {
                    "frequency"  : "once"
                    ,"output"     : "util/airavata_register.xyz"
                    ,"inputs"     : [
                                     {  "airavata/fragments/register/header.xyz"     : "once"            }
                                     ,{ "airavata/fragments/register/eachmenu.xyz"   : "menu:id"         }
                                     ,{ "airavata/fragments/register/eachmodule.xyz" : "menu:modules:id" }
                                     ,{ "airavata/fragments/register/footer.xyz"     : "once"            }
                                    ]
                   },
  • this will take the input code fragments and assemble them into the output code
  • the "frequency" in this case is "once" since we are creating one output file
  • the array of inputs is processed in order to assemble the final output
    • each entry in the array of inputs has its own "sub-frequency", which can be
    • "once" which means "include this fragment once"
    • "menu:id" which means "add this fragment repeatedly for each menu:id"
    • "menu:modules:id" which means "add this fragment repeatedly for each menu:modules:id"
  • during the assembly process, substitutions are made to the fragments in producing the code based upon the context
    • directives.json replacements are always available
    • a special _ basedir _/ input value prefix will use the genapp.pl running directory
    • this is primarily to make copies of menu.json or directives.json if needed
                   ,{
                    "frequency"  : "once",
                    "output"     : "etc/menu.json",
                    "inputs"     : [
                                    { "__basedir__/menu.json" : "once" }
                                   ]
                   }
  • menu.json menu information is available in "menu:id" and "menu:modules:id" sub-frequencies
  • menu.json menu and module information is available in "menu:id" and "menu:modules:id" sub-frequencies
  • replacement occurs on the fragments by looking for tokens with double under scores and they are replaced by the values
  • let's take an example for some language xyz
    • in genapp/src/languages/xyz/airavata/fragments/register
    • header.xyz
from header.java
everything from directives.json is available by wrapping in  __'s
example: application name is __application__
  • eachmenu.xyz
from eachmenu.java
this fragment has every directives.json and menu.json menu top level entries
example: menu:id is __menu:id__
  • eachmodule.xyz
from eachmodule.java
this fragment has every directives.json and menu.json menu top level entries and menu.json modules
example: menu:id is __menu:id__
example: menu:modules:id is __menu:modules:id__
  • footer.xyz
footer.java
everything from directives.json is available by wrapping in  __'s
  • running genapp.pl with this on the genapptest code (as of this writing) produces:
from header.java
everything from directives.json is available by wrapping in  __'s
application name is genapptest_svn
from eachmenu.java
this fragment has every directives.json and menu.json menu top level entries
example: menu:id is tools
from eachmenu.java
this fragment has every directives.json and menu.json menu top level entries
example: menu:id is build
from eachmenu.java
this fragment has every directives.json and menu.json menu top level entries
example: menu:id is interact
from eachmenu.java
this fragment has every directives.json and menu.json menu top level entries
example: menu:id is simulate
from eachmenu.java
this fragment has every directives.json and menu.json menu top level entries
example: menu:id is calculate
from eachmenu.java
this fragment has every directives.json and menu.json menu top level entries
example: menu:id is analyze
from eachmenu.java
this fragment has every directives.json and menu.json menu top level entries
example: menu:id is admin
from eachmodule.java
this fragment has every directives.json and menu.json menu top level entries and menu.json modules
example: menu:id is tools
example: menu:modules:id is center
from eachmodule.java
this fragment has every directives.json and menu.json menu top level entries and menu.json modules
example: menu:id is tools
example: menu:modules:id is align
from eachmodule.java
this fragment has every directives.json and menu.json menu top level entries and menu.json modules
example: menu:id is tools
example: menu:modules:id is filetest
from eachmodule.java
this fragment has every directives.json and menu.json menu top level entries and menu.json modules
example: menu:id is tools
example: menu:modules:id is data_interpolation
from eachmodule.java
this fragment has every directives.json and menu.json menu top level entries and menu.json modules
example: menu:id is build
example: menu:modules:id is build_1
from eachmodule.java
this fragment has every directives.json and menu.json menu top level entries and menu.json modules
example: menu:id is build
example: menu:modules:id is build_2
from eachmodule.java
this fragment has every directives.json and menu.json menu top level entries and menu.json modules
example: menu:id is interact
... more output taken out ...
footer.java
everything from directives.json is available by wrapping in  __'s

conditional code generation

  • in addition to the simple !tagname! replacement described in the previous section, there is also a conditional inclusion option
  __~tagname{code to include if tagname is defined}
  __~tagname{ some code __~tagname2{ more code } }
  • multi-line code to include is not supported
  • e.g.
  __~tagname{ multiple
lines
of
code
}
  • multiple conditionals on one line are not supported
  • e.g.
__~tagname{ code 1 } __~tagname2{ code 2 }

special directives

  • {{{ modulejson }}} will encode the entire modules json

executing command as part of generation

  • requires revision >= 545
  • create an output at some point of the code which contains the script to execute
  • it will be run under the bash shell as a script
  • it can, of course, be assembled like any other output with multiple inputs/frequencies etc.
  • add "execute" : attribute to the assembly step to execute the script
    • set to "true" for immediate execution of the script from the running directory
    • set to "atend" for execution of the script after all output has been created and from the output/language directory
      • multiple execute : atend's will be run in order of appearance in the assembly sequence
    • e.g.:
                   ,{
                       "frequency"  : "once"
                       ,"execute"    : "atend"
                       ,"output"     : "myscriptoutput"
                       ,"inputs"     : [
                        {  "myscriptinput"        : "once" }
                       ]
                   }

future plans

  • remove Important restrictions
  • new conditionals:
  • proposed possibilities
    • if tagname is not defined
 __!tagname{ this code if tagname is not defined }
- ? if-else 
- logical combinations
   __{tagname && !tagname2}{ code }
- tag value check
   __{tagname == "xyz"}{ code }
- [ak] something that would give all the module name separated by given string
  • more special directives, e.g.:
  • {{{ menujson }}} will encode the entire menu json
  • {{{ directivesjson }}} will encode the entire directives json

Clone this wiki locally