prism/examples/prism-parser.html

71 lines
1.4 KiB
HTML

<h2>Comments</h2>
<pre><code>$foo[bar] # Some comment</code></pre>
<h2>Variables and functions</h2>
<pre><code>@navigation[]
$sections[^table::load[sections.cfg]]
$sections.uri</code></pre>
<h2>Literals</h2>
<pre><code>$foo(3+$bar)
^switch[$sMode]{
^case[def]{$result(true)}
}
^if(in "/news/"){}</code></pre>
<h2>Escape sequences</h2>
<pre><code>^^
^"
^;</code></pre>
<h2>Embedded in markup</h2>
<pre><code>&lt;nav>
&lt;ul>
^sections.menu{
&lt;li>
&lt;a href="$sections.uri">$sections.name&lt;/a>
&lt;/li>
}
&lt;/ul>
&lt;/nav></code></pre>
<h2>Full example</h2>
<pre><code>@CLASS
MyTable
@create[uParam]
^switch[$uParam.CLASS_NAME]{
^case[string;void]{$t[^table::create{$uParam}]}
^case[table;MyTable]{$t[^table::create[$uParam]]}
^case[DEFAULT]{^throw[MyTable;Unsupported type $uParam.CLASS_NAME]}
}
# method will return value in different calling contexts
@GET[sMode]
^switch[$sMode]{
^case[table]{$result[$t]}
^case[bool]{$result($t!=0)}
^case[def]{$result(true)}
^case[expression;double]{$result($t)}
^case[DEFAULT]{^throw[MyTable;Unsupported mode '$sMode']}
}
# method will handle access to the "columns"
@GET_DEFAULT[sName]
$result[$t.$sName]
# wrappers for all existing methods are required
@count[]
^t.count[]
@menu[jCode;sSeparator]
^t.menu{$jCode}[$sSeparator]
# new functionality
@remove[iOffset;iLimit]
$iLimit(^iLimit.int(0))
$t[^t.select(^t.offset[]&lt;$iOffset || ^t.offset[]>=$iOffset+$iLimit)]</code></pre>