Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

substitute function implementation #59

Merged
merged 10 commits into from
Aug 18, 2014
5 changes: 5 additions & 0 deletions panc-docs/src/docbkx/README.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@
<title>Version 10.1</title>

<itemizedlist>
<listitem>
<para>(GitHub Issue #59) add substitute function to replace named
values in string template</para>
</listitem>

<listitem>
<para>(GitHub Issue #24) add OBJECT to debug and error output</para>
</listitem>
Expand Down
267 changes: 171 additions & 96 deletions panc-docs/src/docbkx/appendix/appendix-built-in-functions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1182,62 +1182,65 @@ ok = first(table, k, v);
</refentry>

<refentry xml:id="ip4_to_long">
<info>
<productnumber><?eval ${project.version}?></productnumber>
<productname>panc</productname>
<date><?eval ${buildTimestamp}?></date>
<copyright>
<year>2013</year>
<holder>Universiteit Gent</holder>
</copyright>
</info>

<refmeta>
<refentrytitle>ip4_to_long</refentrytitle>
<manvolnum>3</manvolnum>
</refmeta>

<refnamediv>
<refname>panc:ip4_to_long</refname>
<refpurpose>converts an IP address in dotted format with an
optional bitmask to a list of longs</refpurpose>
</refnamediv>

<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>long[]
<function>ip4_to_long</function></funcdef>
<paramdef>string
<parameter>ip</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>

<refsection>
<title>Description</title>

<para>The <function>ip4_to_long</function> function returns
the binary representation of an IPv4 address or network
specification represented as a dotted string, where the
netmask part is optional, like <literal>inet_aton</literal>
does in the C standard library.</para>

<para>The first element of the return value is the binary
representation of the IP address, where the second, if
present, is the binary representation of the network
mask.</para>

<para>This can be used for applying network masks and
calculating network ranges.</para>

<programlisting>variable NETWORK_RANGE_FOR_LOCALHOST = {
<info>
<productnumber><?eval ${project.version}?></productnumber>

<productname>panc</productname>

<date><?eval ${buildTimestamp}?></date>

<copyright>
<year>2013</year>

<holder>Universiteit Gent</holder>
</copyright>
</info>

<refmeta>
<refentrytitle>ip4_to_long</refentrytitle>

<manvolnum>3</manvolnum>
</refmeta>

<refnamediv>
<refname>panc:ip4_to_long</refname>

<refpurpose>converts an IP address in dotted format with an optional
bitmask to a list of longs</refpurpose>
</refnamediv>

<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>long[] <function>ip4_to_long</function></funcdef>

<paramdef>string <parameter>ip</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>

<refsection>
<title>Description</title>

<para>The <function>ip4_to_long</function> function returns the binary
representation of an IPv4 address or network specification represented
as a dotted string, where the netmask part is optional, like
<literal>inet_aton</literal> does in the C standard library.</para>

<para>The first element of the return value is the binary representation
of the IP address, where the second, if present, is the binary
representation of the network mask.</para>

<para>This can be used for applying network masks and calculating
network ranges.</para>

<programlisting>variable NETWORK_RANGE_FOR_LOCALHOST = {
l = ip4_to_long("127.0.0.1/8");
l[0] &amp; l[1];
};</programlisting>

<programlisting>variable BINARY_LOCALHOST = ip4_to_long("127.0.0.1");</programlisting>
</refsection>
<programlisting>variable BINARY_LOCALHOST = ip4_to_long("127.0.0.1");</programlisting>
</refsection>
</refentry>

<refentry xml:id="is_boolean">
Expand Down Expand Up @@ -1923,50 +1926,52 @@ ok = first(table, k, v);
</refentry>

<refentry xml:id="long_to_ip4">
<info>
<productnumber><?eval ${project.version}?></productnumber>
<productname>panc</productname>
<date><?eval ${buildTimestamp}?></date>
<copyright>
<year>2013</year>
<holder>Universiteit Gent</holder>
</copyright>
</info>

<refmeta>
<refentrytitle>long_to_ip4</refentrytitle>
<manvolnum>3</manvolnum>
</refmeta>

<refnamediv>
<refname>panc:long_to_ip4</refname>
<refpurpose>converts a long into an IP address in dotted
format</refpurpose>
</refnamediv>

<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>string
<function>long_to_ip4</function></funcdef>
<paramdef>long
<parameter>ip</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>

<refsection>
<title>Description</title>

<para>The <function>long_to_ip4</function> function converts
an IP address represented as a long into a string with
numbers and dots, like <literal>inet_ntoa</literal> does in
the C standard library.</para>

<programlisting>"/ipaddr" = long_to_ip4(0x01020304); # 1.2.3.4</programlisting>

</refsection>
<info>
<productnumber><?eval ${project.version}?></productnumber>

<productname>panc</productname>

<date><?eval ${buildTimestamp}?></date>

<copyright>
<year>2013</year>

<holder>Universiteit Gent</holder>
</copyright>
</info>

<refmeta>
<refentrytitle>long_to_ip4</refentrytitle>

<manvolnum>3</manvolnum>
</refmeta>

<refnamediv>
<refname>panc:long_to_ip4</refname>

<refpurpose>converts a long into an IP address in dotted
format</refpurpose>
</refnamediv>

<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>long_to_ip4</function></funcdef>

<paramdef>long <parameter>ip</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>

<refsection>
<title>Description</title>

<para>The <function>long_to_ip4</function> function converts an IP
address represented as a long into a string with numbers and dots, like
<literal>inet_ntoa</literal> does in the C standard library.</para>

<programlisting>"/ipaddr" = long_to_ip4(0x01020304); # 1.2.3.4</programlisting>
</refsection>
</refentry>

<refentry xml:id="match">
Expand Down Expand Up @@ -2043,7 +2048,8 @@ type device_t = string with match(self, ’ˆ(disk|cd|net)$’);</programlisting
<refnamediv>
<refname>panc:matches</refname>

<refpurpose>returns captured substrings matching a regular expression</refpurpose>
<refpurpose>returns captured substrings matching a regular
expression</refpurpose>
</refnamediv>

<refsynopsisdiv>
Expand Down Expand Up @@ -2672,6 +2678,75 @@ type ipv4 = string with {
</refsection>
</refentry>

<refentry xml:id="substitute">
<info>
<productnumber><?eval ${project.version}?></productnumber>

<productname>panc</productname>

<date><?eval ${buildTimestamp}?></date>

<copyright>
<year>2014</year>

<holder>Centre National de la Recherche Scientifique (CNRS) and
UGent</holder>
</copyright>
</info>

<refmeta>
<refentrytitle>substitute</refentrytitle>

<manvolnum>3</manvolnum>
</refmeta>

<refnamediv>
<refname>panc:substitute</refname>

<refpurpose>substitute named values in string template</refpurpose>
</refnamediv>

<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>string <function>substitute</function></funcdef>

<paramdef>string <parameter>template</parameter></paramdef>
</funcprototype>

<funcprototype>
<funcdef>string <function>substitute</function></funcdef>

<paramdef>string <parameter>template</parameter></paramdef>

<paramdef>nlist <parameter>substitutions</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>

<refsection>
<title>Description</title>

<para>The <function>substitute</function> function will replace all
named values in the template, delimited like '${myvar}', with associated
values. If only one argument is given, then the values will be looked up
in the local and global variable definitions. If two arguments are
given, then the lookup will be done in the explicit nlist provided; this
form will <emphasis>not</emphasis> use local or global variable
values.</para>

<programlisting>variable vars = nlist('freq', 3, 'msg', 'hello');

# produces string 'say hello 3 times'
'/result' = substitute('say ${msg} ${freq} times', vars);</programlisting>

<para>The substitution allows for recursive references. If you need to
have something like '${myvar}' literally in the string, then use
'$${myvar}'. If the template references an undefined value, then an
EvaluationException will be raised.</para>
</refsection>
</refentry>

<refentry xml:id="substr">
<info>
<productnumber><?eval ${project.version}?></productnumber>
Expand Down
13 changes: 13 additions & 0 deletions panc-docs/src/docbkx/pan-book.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2226,6 +2226,7 @@ if ( condition-dml ) true-dml else false-dml;</programlisting>
<thead>
<row>
<entry>Name</entry>

<entry>Description</entry>
</row>
</thead>
Expand Down Expand Up @@ -2293,6 +2294,12 @@ if ( condition-dml ) true-dml else false-dml;</programlisting>
return an array of the results.</entry>
</row>

<row>
<entry><xref linkend="substitute" /></entry>

<entry>Substitute named values in a string template.</entry>
</row>

<row>
<entry><xref linkend="substr" /></entry>

Expand Down Expand Up @@ -2327,6 +2334,7 @@ if ( condition-dml ) true-dml else false-dml;</programlisting>
<thead>
<row>
<entry>Name</entry>

<entry>Description</entry>
</row>
</thead>
Expand Down Expand Up @@ -2375,6 +2383,7 @@ if ( condition-dml ) true-dml else false-dml;</programlisting>
<thead>
<row>
<entry>Name</entry>

<entry>Description</entry>
</row>
</thead>
Expand Down Expand Up @@ -2427,6 +2436,7 @@ if ( condition-dml ) true-dml else false-dml;</programlisting>
<thead>
<row>
<entry>Name</entry>

<entry>Description</entry>
</row>
</thead>
Expand Down Expand Up @@ -2519,6 +2529,7 @@ if ( condition-dml ) true-dml else false-dml;</programlisting>
<thead>
<row>
<entry>Name</entry>

<entry>Description</entry>
</row>
</thead>
Expand Down Expand Up @@ -2638,6 +2649,7 @@ if ( condition-dml ) true-dml else false-dml;</programlisting>
<thead>
<row>
<entry>Name</entry>

<entry>Description</entry>
</row>
</thead>
Expand Down Expand Up @@ -2714,6 +2726,7 @@ if ( condition-dml ) true-dml else false-dml;</programlisting>
<thead>
<row>
<entry>Name</entry>

<entry>Description</entry>
</row>
</thead>
Expand Down
Loading