<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to Embedded Parsers</title><link>https://sourceforge.net/p/argument/wiki/Embedded%2520Parsers/</link><description>Recent changes to Embedded Parsers</description><atom:link href="https://sourceforge.net/p/argument/wiki/Embedded%20Parsers/feed" rel="self"/><language>en</language><lastBuildDate>Thu, 05 Dec 2013 02:49:16 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/argument/wiki/Embedded%20Parsers/feed" rel="self" type="application/rss+xml"/><item><title>Embedded Parsers modified by Chris DeGreef</title><link>https://sourceforge.net/p/argument/wiki/Embedded%2520Parsers/</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;The embedded Argument parser is needed when you have repeating groups of arguments.  Do not confuse this with &lt;code&gt;--multiple&lt;/code&gt; since that allows for multiple values for the same argument.  There is a good example in Funnel - or more generally, keys for a sort program.&lt;/p&gt;
&lt;p&gt;For this discussion we will have a positional argument for input file and an embedded Argument parser for the &lt;code&gt;--keys.&lt;/code&gt;  This embedded parser will be invoked once for every key.  A command-line like this should be possible.&lt;br /&gt;
&lt;pre class="html:nocontrols:nogutter" name="code"&gt;sort myFile.txt --keys (1 10) (15 3)&lt;/pre&gt;&lt;br /&gt;
This will invoke our program (&lt;code&gt;sort&lt;/code&gt;) and sort the file &lt;code&gt;myFile.txt&lt;/code&gt; on two &lt;code&gt;--keys&lt;/code&gt;.  The first key starts in position 1 and is 10 long, and the second key starts in position 15 and is 3 long.&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;Embedded parsers are always indicated with brackets around them on the command-line. &lt;code&gt;()&lt;/code&gt; and &lt;code&gt;[]&lt;/code&gt; are both valid.&lt;/p&gt;
&lt;p&gt;This &lt;code&gt;--begin&lt;/code&gt; and &lt;code&gt;--end&lt;/code&gt; isolate the embedded parser.  Any arguments between these bookends are part of the embedded parser.  The positional &lt;code&gt;filename &lt;/code&gt;argument is not between the &lt;code&gt;--begin/--end&lt;/code&gt; markers so it is not part of the embedded parser.  And that makes sense since the &lt;code&gt;filename &lt;/code&gt;is not part of each key.  The indentation in the example is just for readability.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="n"&gt;CmdLine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;&amp;quot;--type file --key filename --position&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;&amp;quot;--type begin --key key&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;&amp;quot;--type     integer --key offset --positional --required&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;&amp;quot;--type     integer --key length --positional --required&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;&amp;quot;--type end   --key key&amp;quot;&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;b&gt;--begin and --end&lt;/b&gt;&lt;br /&gt;
The &lt;code&gt;--begin&lt;/code&gt; type indicates the beginning of the embedded parser.  The parser is named, in this example, key, so that it can be referenced in the &lt;code&gt;--end&lt;/code&gt; type.  Embedded parsers can be embedded within other embedded parsers.  That is why they are named; so the &lt;code&gt;--end&lt;/code&gt; can indicate which &lt;code&gt;--begin&lt;/code&gt; it is for.&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Chris DeGreef</dc:creator><pubDate>Thu, 05 Dec 2013 02:49:16 -0000</pubDate><guid>https://sourceforge.netc62392a8b6590f5b2cda9828aac0ae527ccebd9d</guid></item></channel></rss>