<?xml version='1.0'?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD Docbook XML V4.1.2//EN" "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
<book>
<title>ABNF Generator</title>
<bookinfo>
<releaseinfo>
md5-hash:2defc6a77fd6245bf1e7bbe913647996
weight:0
depth:1
</releaseinfo>
</bookinfo>
<preface>
<title>Preface</title>
<literallayout><![CDATA[The abnfgen parses ABNF definitions from source file and generatesoutput as state machine definition for <em id="opus">Ragel</em>. The aim is to makesimplier implementation of parsers defined by ABNF language which is used inmany RFCs.<!--break--><h2 id="opus">ABNF</h2>

<p cc="cc" />The abnfgen takes one or more ABNF definitions specified at command line. Unless nameis recognized as internal rule list name then is treated as name of file containingrule declarations according in ABNF format (RFC2234). If no name is providedor "-" name is used then standard input is read. Input files are processed in order asprovided.

<p cc="cc" />Because more input files may be processed a conflict may happen when rule name being readalready exists in rule list. In such case latter rule overrides former one. But if "=/" isused then rules re merged together. Internal rule list cannot override any other rule

<p cc="cc" />Syntax declaration are often located in plain text so must be manuallyseparated and checked if rule definition starting at the begining of line.

<p cc="cc" />Even ABNF defines mandatory CRLF line ends then abnfgen accepts also simple LF.

<p cc="cc" />Unfortunately even particular RFCs reference ABNF's RFC whendeclaring own syntax then in many cases the syntax hasdeviations and won't pass through strict parser, e.g. alternation delimiter"|" instead of "/", numbers are declared as "0xFF" instead of "%xFF" etc.

<p cc="cc" />Because many RFCs references ABNF core definitions then these rules arebuilt-in abnfgen as internal "core" rule list.

<p cc="cc" />If a problem is detected then a message is written to stderr and no other output isgenerated unless "-F" option is specifies. It ofter happen if unknown rule nameis referenced.

<p cc="cc" />There are multiple formats from abnfgen:<ul compact id="opus"><li /><em id="opus">ABNF</em>: normalized ABNF format<li /><em id="opus">Ragel</em> state machine definition: it's the main product and will be discussed bellow<li /><em id="opus">abnfgen</em> structures which may be used for compiling internal rule list in abnfgen itself

<p cc="cc" /></ul ><h2 id="opus">Ragel</h2>

<p cc="cc" />Ragel (<a href="http://www.cs.queensu.ca/~thurston/ragel/">http://www.cs.queensu.ca/~thurston/ragel/</a>) is fast GNU state machine compiler enablingcalling custom actions in any state of processing. The abnfgen generates state machinedefinition in format known to Ragel but developer must know logic and check if such definitionmeets requirments. The main problem is ambiguity. It's often mind bending problemrecognize which state is ambigious and causes the machine will produce false results oreven jump in never ending loop. Note the very good Ragel instrument is scanner which helps toovercome many ambiguities. Also priorities help but it's a kind of magic.

<p cc="cc" />The Ragel does not support circular references (easily detectable because raises error message.Such case must be corrected manually probably asseparate state machine. The circularily dependend machines will call each other using <em id="opus">fcall/fret</em>commands.

<p cc="cc" />The rule which the abnfgen takes to be main rule is located as <em id="opus">main:=</em> instance. It's simplythe last rule which does not depend on any other rule.<h2 id="opus">Examples</h2>

<p cc="cc" /><pre># pipe from stdin to stdout  abnfgen -f abnf

<p cc="cc" /># load my.txt  abnfgen my.txt -f ragel -o my.rl

<p cc="cc" /># load built-in rules core + abnf + my.txt  abnfgen core abnf my.txt -f ragel -o my.rl

<p cc="cc" /># read RFC2234 core rules and RFC3261 and print to stdout  abnfgen core rfc3261.txt -f ragel</pre><h4 id="opus"> Input</h4>

<p cc="cc" /><pre>list = 1*(item CRLF)item = name ":" *SP bodyname = ALPHA *( ALPHA / DIGIT / "_")body = *( %x20-7e )</pre><h4 id="opus"> Ragel</h4>

<p cc="cc" /><pre>abnfgen core test.txt -f ragel# Generated by abnfgen at Sun Aug 12 15:03:04 2007# Sources:#       core#       test.txt%%{        # write your name        machine generated_from_abnf;

<p cc="cc" />        # generated rules, define required actions        ALPHA = 0x41..0x5a | 0x61..0x7a;        BIT = "0" | "1";        CHAR = 0x01..0x7f;        CR = "\r";        LF = "\n";        CRLF = CR LF;        CTL = 0x00..0x1f | 0x7f;        DIGIT = 0x30..0x39;        DQUOTE = "\"";        HEXDIG = DIGIT | "A"i | "B"i | "C"i | "D"i | "E"i | "F"i;        HTAB = "\t";        SP = " ";        WSP = SP | HTAB;        LWSP = ( WSP | ( CRLF WSP ) )*;        OCTET = 0x00..0xff;        VCHAR = 0x21..0x7e;        name = ALPHA ( ALPHA | DIGIT | "_" )*;        body = 0x20..0x7e*;        item = name ":" SP* body;        list = ( item CRLF )+;

<p cc="cc" />        # instantiate machine rules        main:= list;}%%</pre><h4 id="opus"> ABNF output</h4>

<p cc="cc" /><pre>abnfgen core test.txt -f abnf; Generated by abnfgen at Sun Aug 12 14:58:43 2007; Sources:;       core;       test.txtALPHA  = %x41-5a / %x61-7aBIT    = "0" / "1"CHAR   = %x01-7fCR     = %x0dCRLF   = CR LFCTL    = %x00-1f / %x7fDIGIT  = %x30-39DQUOTE = %x22HEXDIG = DIGIT / "A" / "B" / "C" / "D" / "E" / "F"HTAB   = %x09LF     = %x0aLWSP   = *( WSP / ( CRLF WSP ) )OCTET  = %x00-ffSP     = " "VCHAR  = %x21-7eWSP    = SP / HTABlist   = 1*( item CRLF )item   = name ":" *SP bodyname   = ALPHA *( ALPHA / DIGIT / "_" )body   = *%x20-7e</pre><div class="download">
<h3 class="title">abnfgen</h3>
<div class="description"><p>ABNF generator</p>
</div><br />
<table id="attachments">
 <tr><th>File</th><th>Size</th><th>Last modif</th> </tr>
 <tr class="odd"><td><a href="http://www.2p.cz/files/2p.cz/downloads/abnfgen-src.0.1.tgz">abnfgen-src.0.1.tgz</a></td><td>19.44 KB</td><td>2007-08-12 15:55</td> </tr>
 <tr class="even"><td><a href="http://www.2p.cz/files/2p.cz/downloads/abnfgen-src.0.2.tgz">abnfgen-src.0.2.tgz</a></td><td>19.13 KB</td><td>2008-09-11 18:30</td> </tr>
</table>
<br /><br /></div>
]]></literallayout>
</preface>
</book>
