include homepage.en.yhtml2 page "The Features" { h2 id="text" > Text p >> To output text nodes (¬http://www.w3.org/TR/2008/REC-xml-20081126/#syntax character data¬), write literals. There are integer literals, floating point literals and text literals. >> p >> Literals are written ¬http://docs.python.org/reference/lexical_analysis.html#id7 like in Python¬, that means, text literals are in single or double quotes, or in triple double quotes: >> Code || "text" 'also text' """some more text""" 42 "an integer and" 42.23 "a floating point literal" || h2 id="functioncalls" > Function Calls p >> The main idea of YML scripts is calling functions which then generate XML tags (¬http://www.w3.org/TR/2008/REC-xml-20081126/#syntax Markup¬). Functions are generating single tags, lists or trees of tags. >> p >> To call a function, write the name of the function, followed by a comma separated list of function parameters (C like syntax). Unlike C, you don't need to insert the parameter list into parentheses. A simple function call is terminated by a semicolon «;» >> p >> It does not matter, if you're calling your function using parentheses or brackets or without. So these statements are equal: >> Code || foo "hello, world"; foo("hello, world"); foo["hello, world"]; || h3 id="subtree" > Subtrees p >> If you omit the tailing semicolon, you're creating a Subtree; YML Subtrees can also be opened and closed with braces: >> Code || foo { bar { something; } } || p > If a Subtree only consists of one single subelement, then you may omit the braces: Code || foo bar; || h3 id="named" > Named Parameters p >> To generate ¬http://www.w3.org/TR/2008/REC-xml-20081126/#attdecls attributes¬ by calling a function, you can use Named Parameters. >> p >> For that case, assign literals to attribute names like the following. The name of the parameter then will be used as the name of the generated attribute. An example: >> Code || div id="sample" { "this is a " a href="#sample" "link sample" } || p > This generates: Code |
h3 id="defaultattr" > Giving Default Values for parameters
p >>
To give default values for generating XML attributes, assign a literal to each named parameter
in the declaration parentheses or brackets. Two examples, which do the same:
>>
Code
||
decl img(src, alt="picture");
decl img[src][alt="picture"];
||
h3 id="alias" > Aliasing: using different YML functions for the same XML tag for different tasks
p >>
Sometimes tags are used in different ways to do different things. For this case, you can
use aliasing. Aliasing means, the YML function name and the XML tag name differ. For example:
>>
Code | decl a(href), target(name) alias a;
p > Both defined YML functions then generate «» tags - but the Unnamed Parameter differs.
p >>
The alias name «-» has a special meaning: it omits the tag in the output. That is especially
sensible if you have a ¬#defaultbody default body¬. Then an alias to «-» has the same meaning
as starting the function call with the «&» character: only the body is emitted.
>>
h3 id="descending" > Specifying Descending Attributes
p >>
Maybe you want to write something like this:
>>
Code ||
Module ERP {
Interface Customer {
// ...
}
}
||
p > Without any extras, this compiles to:
Code ||
hello, world
|| p >> Pointers can be referenced in any place in the Default Body of a «decl» statement, also for generating extra tags. Then the value for a Pointer will be the tag name. >> p >> Additionally, you can insert the value of a pointer as text by calling it with two leading asterisks, i.e. if the pointer is defined as «*x», you can insert its value as text using: «**x». >> h3 id="macros", "Macros"; p >> Macros are a way to generate values for attributes with variable content. Macros can be set like any other parameters; they're used for a text search & replace in the values of attributes when attributes are generated. >> p >> Parameters, which represent macros, are determined with a preceding «%» sign. They're accounted for before any other parameter is accounted for in a function call, even if they were defined after other parameters. >> p > An example: Code || decl foo(%macro, myAttr="something %macro for testing"); testing foo "nice"; || p > This generates: Code ||...
tag. >> || h3 > Line Quote | p > The «|» operator does the same as the «>» operator, adding a newline character to the text node. p > Additionally, it can be used to implement an indention system, see ¬yslt YSLT¬ below. p > Then it's used together with additional «>» symbols showing the grade of indention: Code || | not indented |> single indent |>> double indent (...) || h3 > Block Line Quote || p >> The «||» operator opens and closes a block of lines, which then are handled like if each of them would be preceeded with a Line Operator «|». >> p > Sample: Code { | || || this is code being quoted through this is the second line || | || } p > is equivalent to: Code { || | this is code being quoted through | this is the second line || } h3 > Inserting Commands p >> Just like with a ¬http://en.wikipedia.org/wiki/Shell_(computing)#Unix_shells Unix shell¬, you can insert statements into text by using backticks: >> Code ] | Click `a href="http://fdik.org/yml/" "this link"`, please! p { >> Being in a Block Line Quote «||», you additionally can use the Line Command operator (two backquotes, >> ] ``). } p > This is very interesting to have in YSLT, for example: Code { | || | some code ] `` > apply "myTemplate";\n | some other code | || } h3 id="userop" > User defined in-text Operators p > You can define short cuts for inserting commands into text by defining operators. p >> Therefore, you need a ¬http://en.wikipedia.org/wiki/Regular_expression regular expression¬ for matching text and YML text for replacing with. Here an example, how this is used by YSLT: >> Code ] define operator "«(.*?)»" as value "%1"; p > The RegEx have ¬http://docs.python.org/library/re.html Python syntax¬. p >> In this example all matches to the RegEx will be replaced by the YML text in the «as» clause. The text of the first group in the RegEx will replace the «%1» in the resulting YML text. You can do that for more than one group - just use «%2» for the second group, «%3» for the third one and so on. >> h3 id="quotethrough" > Quote Through ] p >> The ¬http://en.wikipedia.org/wiki/Apple_II_series Apple ][¬ prompt operator just quotes through directly into XML what it gets. >> p >> If the first character of a command is a «<», then quote through is applied automatically. >> p > This is the preferred way to output XML tags directly in YML: Code || ] || h2 id="including" > Including YML files p >> You can include a second YML script file into an existing YML script file at any place using: >> Code | include something.yml2 a name="ymlpath"; p >> If you're not starting the filename with '.' or '/' as in the example above, then if the «YML_PATH» environment variable is set to a colon separated list of directories, these directories are being searched for the given filename. Otherwise, the local directory is searched. >> p >> Filename ¬http://en.wikipedia.org/wiki/Glob_(programming) globbing¬ using «*» and «?» placeholders is supported to include more than one file at a time: >> Code | include part*.yml2 p >> Filename globbing also can be used reverted; that means, the files are included in reverse order: >> Code | include reverse part*.yml2 p > If there are the files part1.yml, part2.yml and part3.yml, part3.yml is included first now. p > To include plain text as text nodes, you can use: Code | include text some.txt p > To include ready made XML, use: Code | include xml some.xml h2 id="python" > Escaping into Python - the Escape Operator ! p > You can insert a Python command at any place by using the «!» operator: Code | !class X(str): pass h3 > Python script Operator !! p > You can use the double «!!» to include more than one line of Python code: Code || !! def fak(n): if n == 0: return 1 else: return n * fak(n - 1) def getName(id): return SQL("select name from customers where id='"+str(id)+"';")[0] !! || h3 > Python generated parameters in Function Calls p >> You may use Python expressions to generate names and/or values in Function Calls. To do so, embed the Python expression in «! ... !»: >> Code || f x=!fak(5)!; customer name=!getName(42)!; tag !getNextAttributeName()!=42; || h3 > Python generated Function Calls p >> You can generate text with a Python expression, which represents an YML Function Call. The resulting YML function is then executed. Also here, embed the Python expression in «! ... !»: >> Code | !getTagName() + " " + getAttrib() + "='" + getValue() + "'"! h3 > Using Pointers as values in Python function calls p >> Sometimes it is useful to call a generating Python function using information of a YML Function Call. For that case, there is the «python» statement in YML. You can call there a single Python function using YML Pointers as parameters. >> p > This is used in the YSLT specification, for example: Code || decl apply(select, *indent=1) alias apply-templates { python withIndent(*indent); content; }; || h2 id="comments" > Comments //, /* */ p > Comments are written like in Java or C++: Code || // this is a comment something() { // this is a comment after a tag /* this is some comment, too */ || p > After Quoting Operators, comments are not possible. Instead, they're quoted through: Code || // the following line you'll find in the output document > this text is being output // and this too || div id="bottom" { > ¬programming << Using YML 2¬ > ¬#top ^Top^¬ > ¬yslt >> show me YSLT¬ > ¬features.en.yhtml2 (source)¬ } }