parser


CategoriesLanguage

I’ve installed Parser some time ago and do not remember which version I have installed. Can I learn that?
Yes, sure. Refer directly to Parser and it whould report its version.

May I use in text special characters “;”, “^”, “$” and so on?
Sure. But they must be prefixed by “^” character. For instance, if you need to output a semicolon-separated list:

^table.menu{}[^; ]

I read some text with tags from file/database, but in output to user’s browser they got replaced to < and hence are not handled by browser. But I want that data to be output “as is”. What should I do?
Read about External and internal data in documentation.

I’m bored to write in all classes some certain construction, what could be done?
Make yourself a useful operator, see section “User-defined operators” in documentation.

I want to output $name.jpg, but get strange error instead, what’s up?
Use

${name}.jpg
Why? Because there should be destinction between this and…
$table.field
…this. So Parser would know that dot is not part of syntax, and does not mean that Parser should get “jpg” field of ”name” object.

I want to output values of two variables $a and $b one right after the other. But code $a$b outputs nothing.
According to documentation this code outputs value of one variable named a$b. To output values of two variables, separated by nothing, you should use ${a}${b} code, or simplier: ${a}$b

How to add tab or newline characters to replace table for ^string.replace[$replace_table]? Construction $tReplace[^table::create[nameless]{^#0A <p>}] results in error message.
The thing is that ^#0A is equivalent of newline character in person. By such code we create a table with empty first line. For the Parser NOT to understand that character as a table line delimiter, it should be “tainted”. Fix your code:

$tReplace[^table::create{from	to
^taint[^#0A]	<p>}]
And after calling ^sMyString.replace[$tReplace] all newline characters would be replaced to <p>

How to add a line to arbitrary place in a table object and how to change a table cell?
It is allowed to add lines to table object only after last line (^table.append{}). It is not allowed to change table cells. If you want to add lines to arbitrary place in a table or change table cell, create new table object, clone data from existing table, making appropriate changes while you clone. Consider using ^table.select(condition).

I want for operator to step not by 1
You can consult documentation and learn how to create your own for operator, which would behave like you need.
Particularly, there is an example of steppedfor operator which works like for, but has “step” parameter:

@steppedfor[name;from;to;step;code]
$caller.$name($from)
^while($caller.$name<=$to){
    $code
    ^caller.$name.inc($step)
}
Now you can write…
@somewhere[][i]
^steppedfor[i](1;10;2){$i }
…local variable of somewhere method is changed.

I want foreach to output hash elements in the order I specify, now it enumerates them ad hoc.
After referring to documentation we write user-define operator, which then use instead of foreach method:

@foreach[h;key;value;code;order_direction][tkey]
$tkey[^h._keys[]]
^tkey.sort{$tkey.key}[^if(def $order_direction){$order_direction}{asc}]
^tkey.menu{
    $caller.$key[$tkey.key]
    $caller.$value[$h.[$tkey.key]]
    $code
}
Example of usage:
^foreach[$myhash;k;v]{
    key=$k
    value=$v
}[desc]