Tcl Library Source Code

pt_peg_import_peg.html at [f6d9f0dde2]
Login

File embedded/www/tcllib/files/modules/pt/pt_peg_import_peg.html artifact 1d8daf134f part of check-in f6d9f0dde2



<html><head>
<title>pt::peg::import::peg - Parser Tools</title>
<style type="text/css"><!--
    HTML {
	background: 	#FFFFFF;
	color: 		black;
    }
    BODY {
	background: 	#FFFFFF;
	color:	 	black;
    }
    DIV.doctools {
	margin-left:	10%;
	margin-right:	10%;
    }
    DIV.doctools H1,DIV.doctools H2 {
	margin-left:	-5%;
    }
    H1, H2, H3, H4 {
	margin-top: 	1em;
	font-family:	sans-serif;
	font-size:	large;
	color:		#005A9C;
	background: 	transparent;
	text-align:		left;
    }
    H1.title {
	text-align: center;
    }
    UL,OL {
	margin-right: 0em;
	margin-top: 3pt;
	margin-bottom: 3pt;
    }
    UL LI {
	list-style: disc;
    }
    OL LI {
	list-style: decimal;
    }
    DT {
	padding-top: 	1ex;
    }
    UL.toc,UL.toc UL, UL.toc UL UL {
	font:		normal 12pt/14pt sans-serif;
	list-style:	none;
    }
    LI.section, LI.subsection {
	list-style: 	none;
	margin-left: 	0em;
	text-indent:	0em;
	padding: 	0em;
    }
    PRE {
	display: 	block;
	font-family:	monospace;
	white-space:	pre;
	margin:		0%;
	padding-top:	0.5ex;
	padding-bottom:	0.5ex;
	padding-left:	1ex;
	padding-right:	1ex;
	width:		100%;
    }
    PRE.example {
	color: 		black;
	background: 	#f5dcb3;
	border:		1px solid black;
    }
    UL.requirements LI, UL.syntax LI {
	list-style: 	none;
	margin-left: 	0em;
	text-indent:	0em;
	padding:	0em;
    }
    DIV.synopsis {
	color: 		black;
	background: 	#80ffff;
	border:		1px solid black;
	font-family:	serif;
	margin-top: 	1em;
	margin-bottom: 	1em;
    }
    UL.syntax {
	margin-top: 	1em;
	border-top:	1px solid black;
    }
    UL.requirements {
	margin-bottom: 	1em;
	border-bottom:	1px solid black;
    }
--></style>
</head>
<! -- Generated from file 'plugin.inc' by tcllib/doctools with format 'html'
   -->
<! -- Copyright &copy; 2009 Andreas Kupries &lt;[email protected]&gt;
   -->
<! -- CVS: $Id$ pt::peg::import::peg.n
   -->
<body><div class="doctools">
<hr> [
   <a href="../../../../../../../../home">Tcllib Home</a>
| <a href="../../../../toc.html">Main Table Of Contents</a>
| <a href="../../../toc.html">Table Of Contents</a>
| <a href="../../../../index.html">Keyword Index</a>
| <a href="../../../../toc0.html">Categories</a>
| <a href="../../../../toc1.html">Modules</a>
| <a href="../../../../toc2.html">Applications</a>
 ] <hr>
<h1 class="title">pt::peg::import::peg(n) 1 tcllib &quot;Parser Tools&quot;</h1>
<div id="name" class="section"><h2><a name="name">Name</a></h2>
<p>pt::peg::import::peg - PEG Import Plugin. Read PEG format</p>
</div>
<div id="toc" class="section"><h2><a name="toc">Table Of Contents</a></h2>
<ul class="toc">
<li class="section"><a href="#toc">Table Of Contents</a></li>
<li class="section"><a href="#synopsis">Synopsis</a></li>
<li class="section"><a href="#section1">Description</a></li>
<li class="section"><a href="#section2">API</a></li>
<li class="section"><a href="#section3">PEG Specification Language</a>
<ul>
<li class="subsection"><a href="#subsection1">Example</a></li>
</ul>
</li>
<li class="section"><a href="#section4">PEG serialization format</a>
<ul>
<li class="subsection"><a href="#subsection2">Example</a></li>
</ul>
</li>
<li class="section"><a href="#section5">PE serialization format</a>
<ul>
<li class="subsection"><a href="#subsection3">Example</a></li>
</ul>
</li>
<li class="section"><a href="#section6">Bugs, Ideas, Feedback</a></li>
<li class="section"><a href="#keywords">Keywords</a></li>
<li class="section"><a href="#category">Category</a></li>
<li class="section"><a href="#copyright">Copyright</a></li>
</ul>
</div>
<div id="synopsis" class="section"><h2><a name="synopsis">Synopsis</a></h2>
<div class="synopsis">
<ul class="requirements">
<li>package require <b class="pkgname">Tcl 8.5</b></li>
<li>package require <b class="pkgname">pt::peg::import::peg <span class="opt">?1?</span></b></li>
<li>package require <b class="pkgname">pt::peg::to::peg</b></li>
</ul>
<ul class="syntax">
<li><a href="#1"><b class="cmd"><a href="../../../../index.html#key291">import</a></b> <i class="arg">text</i></a></li>
</ul>
</div>
</div>
<div id="section1" class="section"><h2><a name="section1">Description</a></h2>
<p>Are you lost ?
Do you have trouble understanding this document ?
In that case please read the overview provided by the
<i class="term"><a href="pt_introduction.html">Introduction to Parser Tools</a></i>. This document is the
entrypoint to the whole system the current package is a part of.</p>
<p>This package implements the parsing expression grammar import plugin
processing PEG markup.</p>
<p>It resides in the Import section of the Core Layer of Parser Tools and
is intended to be used by <b class="package"><a href="pt_peg_import.html">pt::peg::import</a></b>, the import
manager, sitting between it and the corresponding core conversion
functionality provided by <b class="package"><a href="pt_peg_from_peg.html">pt::peg::from::peg</a></b>.</p>
<p><img alt="arch_core_iplugins" src="../../../../image/arch_core_iplugins.png"></p>
<p>While the direct use of this package with a regular interpreter is
possible, this is strongly disrecommended and requires a number of
contortions to provide the expected environment.
The proper way to use this functionality depends on the situation:</p>
<ol class="enumerated">
<li><p>In an untrusted environment the proper access is through the package
<b class="package"><a href="pt_peg_import.html">pt::peg::import</a></b> and the import manager objects it
provides.</p></li>
<li><p>In a trusted environment however simply use the package
<b class="package"><a href="pt_peg_from_peg.html">pt::peg::from::peg</a></b> and access the core
conversion functionality directly.</p></li>
</ol>
</div>
<div id="section2" class="section"><h2><a name="section2">API</a></h2>
<p>The API provided by this package satisfies the specification of the
Plugin API found in the <i class="term"><a href="pt_from_api.html">Parser Tools Import API</a></i>
specification.</p>
<dl class="definitions">
<dt><a name="1"><b class="cmd"><a href="../../../../index.html#key291">import</a></b> <i class="arg">text</i></a></dt>
<dd><p>This command takes the PEG markup encoding a parsing
expression grammar and contained in <i class="arg">text</i>, and generates the
canonical serialization of said grammar, as specified in section
<span class="sectref"><a href="#section4">PEG serialization format</a></span>.
The created value is then returned as the result of the command.</p></dd>
</dl>
</div>
<div id="section3" class="section"><h2><a name="section3">PEG Specification Language</a></h2>
<p><b class="const">peg</b>, a language for the specification of parsing expression
grammars is meant to be human readable, and writable as well, yet
strict enough to allow its processing by machine. Like any computer
language. It was defined to make writing the specification of a
grammar easy, something the other formats found in the Parser Tools do
not lend themselves too.</p>
<p>It is formally specified by the grammar shown below, written in
itself. For a tutorial / introduction to the language please go and
read the <i class="term"><a href="pt_peg_language.html">PEG Language Tutorial</a></i>.</p>
<pre class="example">
PEG pe-grammar-for-peg (Grammar)
	# --------------------------------------------------------------------
        # Syntactical constructs
        Grammar         &lt;- WHITESPACE Header Definition* Final EOF ;
        Header          &lt;- PEG Identifier StartExpr ;
        Definition      &lt;- Attribute? Identifier IS Expression SEMICOLON ;
        Attribute       &lt;- (VOID / LEAF) COLON ;
        Expression      &lt;- Sequence (SLASH Sequence)* ;
        Sequence        &lt;- Prefix+ ;
        Prefix          &lt;- (AND / NOT)? Suffix ;
        Suffix          &lt;- Primary (QUESTION / STAR / PLUS)? ;
        Primary         &lt;- ALNUM / ALPHA / ASCII / CONTROL / DDIGIT / DIGIT
                        /  GRAPH / LOWER / PRINTABLE / PUNCT / SPACE / UPPER
                        /  WORDCHAR / XDIGIT
                        / Identifier
                        /  OPEN Expression CLOSE
                        /  Literal
                        /  Class
                        /  DOT
                        ;
        Literal         &lt;- APOSTROPH  (!APOSTROPH  Char)* APOSTROPH  WHITESPACE
                        /  DAPOSTROPH (!DAPOSTROPH Char)* DAPOSTROPH WHITESPACE ;
        Class           &lt;- OPENB (!CLOSEB Range)* CLOSEB WHITESPACE ;
        Range           &lt;- Char TO Char / Char ;
        StartExpr       &lt;- OPEN Expression CLOSE ;
void:   Final           &lt;- &quot;END&quot; WHITESPACE SEMICOLON WHITESPACE ;
        # --------------------------------------------------------------------
        # Lexing constructs
        Identifier      &lt;- Ident WHITESPACE ;
leaf:   Ident           &lt;- ([_:] / &lt;alpha&gt;) ([_:] / &lt;alnum&gt;)* ;
        Char            &lt;- CharSpecial / CharOctalFull / CharOctalPart
                        /  CharUnicode / CharUnescaped
                        ;
leaf:   CharSpecial     &lt;- &quot;\\&quot; [nrt'&quot;\[\]\\] ;
leaf:   CharOctalFull   &lt;- &quot;\\&quot; [0-2][0-7][0-7] ;
leaf:   CharOctalPart   &lt;- &quot;\\&quot; [0-7][0-7]? ;
leaf:   CharUnicode     &lt;- &quot;\\&quot; 'u' HexDigit (HexDigit (HexDigit HexDigit?)?)? ;
leaf:   CharUnescaped   &lt;- !&quot;\\&quot; . ;
void:   HexDigit        &lt;- [0-9a-fA-F] ;
void:   TO              &lt;- '-'           ;
void:   OPENB           &lt;- &quot;[&quot;           ;
void:   CLOSEB          &lt;- &quot;]&quot;           ;
void:   APOSTROPH       &lt;- &quot;'&quot;           ;
void:   DAPOSTROPH      &lt;- '&quot;'           ;
void:   PEG             &lt;- &quot;PEG&quot; !([_:] / &lt;alnum&gt;) WHITESPACE ;
void:   IS              &lt;- &quot;&lt;-&quot;    WHITESPACE ;
leaf:   VOID            &lt;- &quot;void&quot;  WHITESPACE ; # Implies that definition has no semantic value.
leaf:   LEAF            &lt;- &quot;leaf&quot;  WHITESPACE ; # Implies that definition has no terminals.
void:   SEMICOLON       &lt;- &quot;;&quot;     WHITESPACE ;
void:   COLON           &lt;- &quot;:&quot;     WHITESPACE ;
void:   SLASH           &lt;- &quot;/&quot;     WHITESPACE ;
leaf:   AND             &lt;- &quot;&amp;&quot;     WHITESPACE ;
leaf:   NOT             &lt;- &quot;!&quot;     WHITESPACE ;
leaf:   QUESTION        &lt;- &quot;?&quot;     WHITESPACE ;
leaf:   STAR            &lt;- &quot;*&quot;     WHITESPACE ;
leaf:   PLUS            &lt;- &quot;+&quot;     WHITESPACE ;
void:   OPEN            &lt;- &quot;(&quot;     WHITESPACE ;
void:   CLOSE           &lt;- &quot;)&quot;     WHITESPACE ;
leaf:   DOT             &lt;- &quot;.&quot;     WHITESPACE ;
leaf:   ALNUM           &lt;- &quot;&lt;alnum&gt;&quot;    WHITESPACE ;
leaf:   ALPHA           &lt;- &quot;&lt;alpha&gt;&quot;    WHITESPACE ;
leaf:   ASCII           &lt;- &quot;&lt;ascii&gt;&quot;    WHITESPACE ;
leaf:   CONTROL         &lt;- &quot;&lt;control&gt;&quot;  WHITESPACE ;
leaf:   DDIGIT          &lt;- &quot;&lt;ddigit&gt;&quot;   WHITESPACE ;
leaf:   DIGIT           &lt;- &quot;&lt;digit&gt;&quot;    WHITESPACE ;
leaf:   GRAPH           &lt;- &quot;&lt;graph&gt;&quot;    WHITESPACE ;
leaf:   LOWER           &lt;- &quot;&lt;lower&gt;&quot;    WHITESPACE ;
leaf:   PRINTABLE       &lt;- &quot;&lt;print&gt;&quot;    WHITESPACE ;
leaf:   PUNCT           &lt;- &quot;&lt;punct&gt;&quot;    WHITESPACE ;
leaf:   SPACE           &lt;- &quot;&lt;space&gt;&quot;    WHITESPACE ;
leaf:   UPPER           &lt;- &quot;&lt;upper&gt;&quot;    WHITESPACE ;
leaf:   WORDCHAR        &lt;- &quot;&lt;wordchar&gt;&quot; WHITESPACE ;
leaf:   XDIGIT          &lt;- &quot;&lt;xdigit&gt;&quot;   WHITESPACE ;
void:   WHITESPACE      &lt;- (&quot; &quot; / &quot;\t&quot; / EOL / COMMENT)* ;
void:   COMMENT         &lt;- '#' (!EOL .)* EOL ;
void:   EOL             &lt;- &quot;\n\r&quot; / &quot;\n&quot; / &quot;\r&quot; ;
void:   EOF             &lt;- !. ;
        # --------------------------------------------------------------------
END;
</pre>
<div id="subsection1" class="subsection"><h3><a name="subsection1">Example</a></h3>
<p>Our example specifies the grammar for a basic 4-operation calculator.</p>
<pre class="example">
PEG calculator (Expression)
    Digit      &lt;- '0'/'1'/'2'/'3'/'4'/'5'/'6'/'7'/'8'/'9'       ;
    Sign       &lt;- '-' / '+'                                     ;
    Number     &lt;- Sign? Digit+                                  ;
    Expression &lt;- Term (AddOp Term)*                            ;
    MulOp      &lt;- '*' / '/'                                     ;
    Term       &lt;- Factor (MulOp Factor)*                        ;
    AddOp      &lt;- '+'/'-'                                       ;
    Factor     &lt;- '(' Expression ')' / Number                   ;
END;
</pre>
<p>Using higher-level features of the notation, i.e. the character
classes (predefined and custom), this example can be rewritten as</p>
<pre class="example">
PEG calculator (Expression)
    Sign       &lt;- [-+] 						;
    Number     &lt;- Sign? &lt;ddigit&gt;+				;
    Expression &lt;- '(' Expression ')' / (Factor (MulOp Factor)*)	;
    MulOp      &lt;- [*/]						;
    Factor     &lt;- Term (AddOp Term)*				;
    AddOp      &lt;- [-+]						;
    Term       &lt;- Number					;
END;
</pre>
</div>
</div>
<div id="section4" class="section"><h2><a name="section4">PEG serialization format</a></h2>
<p>Here we specify the format used by the Parser Tools to serialize
Parsing Expression Grammars as immutable values for transport,
comparison, etc.</p>
<p>We distinguish between <i class="term">regular</i> and <i class="term">canonical</i>
serializations.
While a PEG may have more than one regular serialization only exactly
one of them will be <i class="term">canonical</i>.</p>
<dl class="definitions">
<dt>regular serialization</dt>
<dd><ol class="enumerated">
<li><p>The serialization of any PEG is a nested Tcl dictionary.</p></li>
<li><p>This dictionary holds a single key, <b class="const">pt::grammar::peg</b>, and its
value. This value holds the contents of the grammar.</p></li>
<li><p>The contents of the grammar are a Tcl dictionary holding the set of
nonterminal symbols and the starting expression. The relevant keys and
their values are</p>
<dl class="definitions">
<dt><b class="const">rules</b></dt>
<dd><p>The value is a Tcl dictionary whose keys are the names of the
nonterminal symbols known to the grammar.</p>
<ol class="enumerated">
<li><p>Each nonterminal symbol may occur only once.</p></li>
<li><p>The empty string is not a legal nonterminal symbol.</p></li>
<li><p>The value for each symbol is a Tcl dictionary itself. The relevant
keys and their values in this dictionary are</p>
<dl class="definitions">
<dt><b class="const">is</b></dt>
<dd><p>The value is the serialization of the parsing expression describing
the symbols sentennial structure, as specified in the section
<span class="sectref"><a href="#section5">PE serialization format</a></span>.</p></dd>
<dt><b class="const">mode</b></dt>
<dd><p>The value can be one of three values specifying how a parser should
handle the semantic value produced by the symbol.</p>
<dl class="definitions">
<dt><b class="const">value</b></dt>
<dd><p>The semantic value of the nonterminal symbol is an abstract syntax
tree consisting of a single node node for the nonterminal itself,
which has the ASTs of the symbol's right hand side as its children.</p></dd>
<dt><b class="const">leaf</b></dt>
<dd><p>The semantic value of the nonterminal symbol is an abstract syntax
tree consisting of a single node node for the nonterminal, without any
children. Any ASTs generated by the symbol's right hand side are
discarded.</p></dd>
<dt><b class="const">void</b></dt>
<dd><p>The nonterminal has no semantic value. Any ASTs generated by the
symbol's right hand side are discarded (as well).</p></dd>
</dl></dd>
</dl>
</li>
</ol></dd>
<dt><b class="const">start</b></dt>
<dd><p>The value is the serialization of the start parsing expression of the
grammar, as specified in the section <span class="sectref"><a href="#section5">PE serialization format</a></span>.</p></dd>
</dl>
</li>
<li><p>The terminal symbols of the grammar are specified implicitly as the
set of all terminal symbols used in the start expression and on the
RHS of the grammar rules.</p></li>
</ol></dd>
<dt>canonical serialization</dt>
<dd><p>The canonical serialization of a grammar has the format as specified
in the previous item, and then additionally satisfies the constraints
below, which make it unique among all the possible serializations of
this grammar.</p>
<ol class="enumerated">
<li><p>The keys found in all the nested Tcl dictionaries are sorted in
ascending dictionary order, as generated by Tcl's builtin command
<b class="cmd">lsort -increasing -dict</b>.</p></li>
<li><p>The string representation of the value is the canonical representation
of a Tcl dictionary. I.e. it does not contain superfluous whitespace.</p></li>
</ol></dd>
</dl>
<div id="subsection2" class="subsection"><h3><a name="subsection2">Example</a></h3>
<p>Assuming the following PEG for simple mathematical expressions</p>
<pre class="example">
PEG calculator (Expression)
    Digit      &lt;- '0'/'1'/'2'/'3'/'4'/'5'/'6'/'7'/'8'/'9'       ;
    Sign       &lt;- '-' / '+'                                     ;
    Number     &lt;- Sign? Digit+                                  ;
    Expression &lt;- Term (AddOp Term)*                            ;
    MulOp      &lt;- '*' / '/'                                     ;
    Term       &lt;- Factor (MulOp Factor)*                        ;
    AddOp      &lt;- '+'/'-'                                       ;
    Factor     &lt;- '(' Expression ')' / Number                   ;
END;
</pre>
<p>then its canonical serialization (except for whitespace) is</p>
<pre class="example">
pt::grammar::peg {
    rules {
        AddOp      {is {/ {t -} {t +}}                                                                mode value}
        Digit      {is {/ {t 0} {t 1} {t 2} {t 3} {t 4} {t 5} {t 6} {t 7} {t 8} {t 9}}                mode value}
        Expression {is {x {n Term} {* {x {n AddOp} {n Term}}}}                                        mode value}
        Factor     {is {/ {x {t (} {n Expression} {t )}} {n Number}}                                  mode value}
        MulOp      {is {/ {t *} {t /}}                                                                mode value}
        Number     {is {x {? {n Sign}} {+ {n Digit}}}                                                 mode value}
        Sign       {is {/ {t -} {t +}}                                                                mode value}
        Term       {is {x {n Factor} {* {x {n MulOp} {n Factor}}}}                                    mode value}
    }
    start {n Expression}
}
</pre>
</div>
</div>
<div id="section5" class="section"><h2><a name="section5">PE serialization format</a></h2>
<p>Here we specify the format used by the Parser Tools to serialize
Parsing Expressions as immutable values for transport, comparison,
etc.</p>
<p>We distinguish between <i class="term">regular</i> and <i class="term">canonical</i>
serializations.
While a parsing expression may have more than one regular
serialization only exactly one of them will be <i class="term">canonical</i>.</p>
<dl class="definitions">
<dt>Regular serialization</dt>
<dd><dl class="definitions">
<dt><b class="const">Atomic Parsing Expressions</b></dt>
<dd><ol class="enumerated">
<li><p>The string <b class="const">epsilon</b> is an atomic parsing expression. It matches
the empty string.</p></li>
<li><p>The string <b class="const">dot</b> is an atomic parsing expression. It matches
any character.</p></li>
<li><p>The string <b class="const">alnum</b> is an atomic parsing expression. It matches
any Unicode alphabet or digit character. This is a custom extension of
PEs based on Tcl's builtin command <b class="cmd">string is</b>.</p></li>
<li><p>The string <b class="const">alpha</b> is an atomic parsing expression. It matches
any Unicode alphabet character. This is a custom extension of PEs
based on Tcl's builtin command <b class="cmd">string is</b>.</p></li>
<li><p>The string <b class="const">ascii</b> is an atomic parsing expression. It matches
any Unicode character below U0080. This is a custom extension of PEs
based on Tcl's builtin command <b class="cmd">string is</b>.</p></li>
<li><p>The string <b class="const">control</b> is an atomic parsing expression. It matches
any Unicode control character. This is a custom extension of PEs based
on Tcl's builtin command <b class="cmd">string is</b>.</p></li>
<li><p>The string <b class="const">digit</b> is an atomic parsing expression. It matches
any Unicode digit character. Note that this includes characters
outside of the [0..9] range. This is a custom extension of PEs
based on Tcl's builtin command <b class="cmd">string is</b>.</p></li>
<li><p>The string <b class="const">graph</b> is an atomic parsing expression. It matches
any Unicode printing character, except for space. This is a custom
extension of PEs based on Tcl's builtin command <b class="cmd">string is</b>.</p></li>
<li><p>The string <b class="const">lower</b> is an atomic parsing expression. It matches
any Unicode lower-case alphabet character. This is a custom extension
of PEs based on Tcl's builtin command <b class="cmd">string is</b>.</p></li>
<li><p>The string <b class="const">print</b> is an atomic parsing expression. It matches
any Unicode printing character, including space. This is a custom
extension of PEs based on Tcl's builtin command <b class="cmd">string is</b>.</p></li>
<li><p>The string <b class="const">punct</b> is an atomic parsing expression. It matches
any Unicode punctuation character. This is a custom extension of PEs
based on Tcl's builtin command <b class="cmd">string is</b>.</p></li>
<li><p>The string <b class="const">space</b> is an atomic parsing expression. It matches
any Unicode space character. This is a custom extension of PEs based
on Tcl's builtin command <b class="cmd">string is</b>.</p></li>
<li><p>The string <b class="const">upper</b> is an atomic parsing expression. It matches
any Unicode upper-case alphabet character. This is a custom extension
of PEs based on Tcl's builtin command <b class="cmd">string is</b>.</p></li>
<li><p>The string <b class="const">wordchar</b> is an atomic parsing expression. It
matches any Unicode word character. This is any alphanumeric character
(see alnum), and any connector punctuation characters (e.g.
underscore). This is a custom extension of PEs based on Tcl's builtin
command <b class="cmd">string is</b>.</p></li>
<li><p>The string <b class="const">xdigit</b> is an atomic parsing expression. It matches
any hexadecimal digit character. This is a custom extension of PEs
based on Tcl's builtin command <b class="cmd">string is</b>.</p></li>
<li><p>The string <b class="const">ddigit</b> is an atomic parsing expression. It matches
any decimal digit character. This is a custom extension of PEs based
on Tcl's builtin command <b class="cmd">regexp</b>.</p></li>
<li><p>The expression
    [list t <b class="variable">x</b>]
is an atomic parsing expression. It matches the terminal string <b class="variable">x</b>.</p></li>
<li><p>The expression
    [list n <b class="variable">A</b>]
is an atomic parsing expression. It matches the nonterminal <b class="variable">A</b>.</p></li>
</ol></dd>
<dt><b class="const">Combined Parsing Expressions</b></dt>
<dd><ol class="enumerated">
<li><p>For parsing expressions <b class="variable">e1</b>, <b class="variable">e2</b>, ... the result of
    [list / <b class="variable">e1</b> <b class="variable">e2</b> ... ]
is a parsing expression as well.
This is the <i class="term">ordered choice</i>, aka <i class="term">prioritized choice</i>.</p></li>
<li><p>For parsing expressions <b class="variable">e1</b>, <b class="variable">e2</b>, ... the result of
    [list x <b class="variable">e1</b> <b class="variable">e2</b> ... ]
is a parsing expression as well.
This is the <i class="term">sequence</i>.</p></li>
<li><p>For a parsing expression <b class="variable">e</b> the result of
    [list * <b class="variable">e</b>]
is a parsing expression as well.
This is the <i class="term">kleene closure</i>, describing zero or more
repetitions.</p></li>
<li><p>For a parsing expression <b class="variable">e</b> the result of
    [list + <b class="variable">e</b>]
is a parsing expression as well.
This is the <i class="term">positive kleene closure</i>, describing one or more
repetitions.</p></li>
<li><p>For a parsing expression <b class="variable">e</b> the result of
    [list &amp; <b class="variable">e</b>]
is a parsing expression as well.
This is the <i class="term">and lookahead predicate</i>.</p></li>
<li><p>For a parsing expression <b class="variable">e</b> the result of
    [list ! <b class="variable">e</b>]
is a parsing expression as well.
This is the <i class="term">not lookahead predicate</i>.</p></li>
<li><p>For a parsing expression <b class="variable">e</b> the result of
    [list ? <b class="variable">e</b>]
is a parsing expression as well.
This is the <i class="term">optional input</i>.</p></li>
</ol></dd>
</dl></dd>
<dt>Canonical serialization</dt>
<dd><p>The canonical serialization of a parsing expression has the format as
specified in the previous item, and then additionally satisfies the
constraints below, which make it unique among all the possible
serializations of this parsing expression.</p>
<ol class="enumerated">
<li><p>The string representation of the value is the canonical representation
of a pure Tcl list. I.e. it does not contain superfluous whitespace.</p></li>
<li><p>Terminals are <em>not</em> encoded as ranges (where start and end of the
range are identical).</p></li>
</ol></dd>
</dl>
<div id="subsection3" class="subsection"><h3><a name="subsection3">Example</a></h3>
<p>Assuming the parsing expression shown on the right-hand side of the
rule</p>
<pre class="example">
    Expression &lt;- Term (AddOp Term)*
</pre>
<p>then its canonical serialization (except for whitespace) is</p>
<pre class="example">
    {x {n Term} {* {x {n AddOp} {n Term}}}}
</pre>
</div>
</div>
<div id="section6" class="section"><h2><a name="section6">Bugs, Ideas, Feedback</a></h2>
<p>This document, and the package it describes, will undoubtedly contain
bugs and other problems.
Please report such in the category <em>pt</em> of the
<a href="http://core.tcl.tk/tcllib/reportlist">Tcllib Trackers</a>.
Please also report any ideas for enhancements you may have for either
package and/or documentation.</p>
</div>
<div id="keywords" class="section"><h2><a name="keywords">Keywords</a></h2>
<p><a href="../../../../index.html#key3">EBNF</a>, <a href="../../../../index.html#key15">LL(k)</a>, <a href="../../../../index.html#key6">PEG</a>, <a href="../../../../index.html#key7">TDPL</a>, <a href="../../../../index.html#key4">context-free languages</a>, <a href="../../../../index.html#key0">expression</a>, <a href="../../../../index.html#key11">grammar</a>, <a href="../../../../index.html#key291">import</a>, <a href="../../../../index.html#key5">matching</a>, <a href="../../../../index.html#key9">parser</a>, <a href="../../../../index.html#key8">parsing expression</a>, <a href="../../../../index.html#key14">parsing expression grammar</a>, <a href="../../../../index.html#key252">plugin</a>, <a href="../../../../index.html#key1">push down automaton</a>, <a href="../../../../index.html#key10">recursive descent</a>, <a href="../../../../index.html#key109">serialization</a>, <a href="../../../../index.html#key2">state</a>, <a href="../../../../index.html#key13">top-down parsing languages</a>, <a href="../../../../index.html#key12">transducer</a></p>
</div>
<div id="category" class="section"><h2><a name="category">Category</a></h2>
<p>Parsing and Grammars</p>
</div>
<div id="copyright" class="section"><h2><a name="copyright">Copyright</a></h2>
<p>Copyright &copy; 2009 Andreas Kupries &lt;[email protected]&gt;</p>
</div>
</div></body></html>