aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergio Queiroz <sqmedeiros@gmail.com>2016-06-13 11:56:47 -0300
committerSergio Queiroz <sqmedeiros@gmail.com>2016-06-13 11:56:47 -0300
commit43ce0cb6027033a9a08075d72a77630720895834 (patch)
tree181d3e2ac0c054802f5de35d82f8dd3beeadfe8f
parentd6b07c6c87655aa114af6aae8b6fef241f99aca3 (diff)
downloadlpeglabel-43ce0cb6027033a9a08075d72a77630720895834.tar.gz
lpeglabel-43ce0cb6027033a9a08075d72a77630720895834.tar.bz2
lpeglabel-43ce0cb6027033a9a08075d72a77630720895834.zip
Updating examples and documentation to match the new API
-rw-r--r--examples/listId2.lua4
-rw-r--r--examples/listIdCatchRe.lua2
-rw-r--r--examples/listIdRe1.lua8
-rw-r--r--examples/listIdRe2.lua6
-rw-r--r--examples/tiny.lua2
-rw-r--r--lpeglabel.html47
6 files changed, 39 insertions, 30 deletions
diff --git a/examples/listId2.lua b/examples/listId2.lua
index 4943368..75060f9 100644
--- a/examples/listId2.lua
+++ b/examples/listId2.lua
@@ -18,9 +18,9 @@ local g = m.P{
18} 18}
19 19
20function mymatch (g, s) 20function mymatch (g, s)
21 local r, e = g:match(s) 21 local r, e, sfail = g:match(s)
22 if not r then 22 if not r then
23 return r, terror[e] 23 return r, terror[e] .. " before '" .. sfail .. "'"
24 end 24 end
25 return r 25 return r
26end 26end
diff --git a/examples/listIdCatchRe.lua b/examples/listIdCatchRe.lua
index 5d38fec..8971191 100644
--- a/examples/listIdCatchRe.lua
+++ b/examples/listIdCatchRe.lua
@@ -1,4 +1,4 @@
1local re = require're' 1local re = require'relabel'
2 2
3local terror = {} 3local terror = {}
4 4
diff --git a/examples/listIdRe1.lua b/examples/listIdRe1.lua
index c75bb1d..fc213bc 100644
--- a/examples/listIdRe1.lua
+++ b/examples/listIdRe1.lua
@@ -1,4 +1,4 @@
1local re = require 're' 1local re = require 'relabel'
2 2
3local g = re.compile[[ 3local g = re.compile[[
4 S <- Id List 4 S <- Id List
@@ -7,12 +7,12 @@ local g = re.compile[[
7]] 7]]
8 8
9function mymatch (g, s) 9function mymatch (g, s)
10 local r, e = g:match(s) 10 local r, e, sfail = g:match(s)
11 if not r then 11 if not r then
12 if e == 1 then 12 if e == 1 then
13 return r, "Error: expecting an identifier" 13 return r, "Error: expecting an identifier before '" .. sfail .. "'"
14 elseif e == 2 then 14 elseif e == 2 then
15 return r, "Error: expecting ','" 15 return r, "Error: expecting ',' before '" .. sfail .. "'"
16 else 16 else
17 return r, "Error" 17 return r, "Error"
18 end 18 end
diff --git a/examples/listIdRe2.lua b/examples/listIdRe2.lua
index 67c42f1..4cd140b 100644
--- a/examples/listIdRe2.lua
+++ b/examples/listIdRe2.lua
@@ -1,4 +1,4 @@
1local re = require 're' 1local re = require 'relabel'
2 2
3local errUndef, errId, errComma = 0, 1, 2 3local errUndef, errId, errComma = 0, 1, 2
4 4
@@ -21,9 +21,9 @@ local g = re.compile[[
21]] 21]]
22 22
23function mymatch (g, s) 23function mymatch (g, s)
24 local r, e = g:match(s) 24 local r, e, sfail = g:match(s)
25 if not r then 25 if not r then
26 return r, terror[e] 26 return r, terror[e] .. " before '" .. sfail .. "'"
27 end 27 end
28 return r 28 return r
29end 29end
diff --git a/examples/tiny.lua b/examples/tiny.lua
index aa9dbea..99c3144 100644
--- a/examples/tiny.lua
+++ b/examples/tiny.lua
@@ -1,4 +1,4 @@
1local re = require 're' 1local re = require 'relabel'
2 2
3local terror = {} 3local terror = {}
4 4
diff --git a/lpeglabel.html b/lpeglabel.html
index 30e6636..59e744a 100644
--- a/lpeglabel.html
+++ b/lpeglabel.html
@@ -61,30 +61,27 @@ with the standard patterns of LPeg.
61<p> 61<p>
62This document describes the new functions available 62This document describes the new functions available
63in LpegLabel and presents some examples of usage. 63in LpegLabel and presents some examples of usage.
64For a more detailed and formal discussion about 64In LPegLabel, the result of an unsuccessful matching
65PEGs with labels please see 65is a triple <code>nil, lab, sfail</code>, where <code>lab</code>
66<a href="http://www.inf.puc-rio.br/~roberto/docs/sblp2013-1.pdf"> 66is the label associated with the failure, and
67Exception Handling for Error Reporting in Parsing Expression Grammars 67<code>sfail</code> is the suffix input where
68</a> 68the label was thrown.
69and
70<a href="http://arxiv.org/abs/1405.6646">Error Reporting in Parsing Expression Grammars</a>.
71</p> 69</p>
72 70
73
74<p> 71<p>
75Below there is a brief summary of the new functions 72Below there is a brief summary of the new functions
76provided by LpegLabel: 73provided by LpegLabel:
77</p> 74</p>
78<table border="1"> 75<table border="1">
79<tbody><tr><td><b>Function</b></td><td><b>Description</b></td></tr> 76<tbody><tr><td><b>Function</b></td><td><b>Description</b></td></tr>
80<tr><td><a href="#f-t"><code>lpeglabel.T (l<sub>1</sub>, ..., l<sub>n</sub>)</code></a></td> 77<tr><td><a href="#f-t"><code>lpeglabel.T (l)</code></a></td>
81 <td>Throws labels <code>l<sub>1</sub>, ..., l<sub>n</sub></code></td></tr> 78 <td>Throws label <code>l</code></td></tr>
82<tr><td><a href="#f-lc"><code>lpeglabel.Lc (p1, p2, l<sub>1</sub>, ..., l<sub>n</sub>)</code></a></td> 79<tr><td><a href="#f-lc"><code>lpeglabel.Lc (p1, p2, l<sub>1</sub>, ..., l<sub>n</sub>)</code></a></td>
83 <td>Matches <code>p1</code> and tries to match <code>p2</code> 80 <td>Matches <code>p1</code> and tries to match <code>p2</code>
84 if the matching of <code>p1</code> gives one of l<sub>1</sub>, ..., l<sub>n</sub> 81 if the matching of <code>p1</code> gives one of l<sub>1</sub>, ..., l<sub>n</sub>
85 </td></tr> 82 </td></tr>
86<tr><td><a href="#re-t"><code>%{l<sub>1</sub>, ..., l<sub>n</sub>}</code></a></td> 83<tr><td><a href="#re-t"><code>%{l}</code></a></td>
87 <td>Syntax of <em>relabel</em> module. Equivalent to <code>lpeg.T(l<sub>1</sub>, ..., l<sub>n</sub>)</code> 84 <td>Syntax of <em>relabel</em> module. Equivalent to <code>lpeg.T(l)</code>
88 </td></tr> 85 </td></tr>
89<tr><td><a href="#re-lc"><code>p1 /{l<sub>1</sub>, ..., l<sub>n</sub>} p2</code></a></td> 86<tr><td><a href="#re-lc"><code>p1 /{l<sub>1</sub>, ..., l<sub>n</sub>} p2</code></a></td>
90 <td>Syntax of <em>relabel</em> module. Equivalent to <code>lpeg.Lc(p1, p2, l<sub>1</sub>, ..., l<sub>n</sub>)</code> 87 <td>Syntax of <em>relabel</em> module. Equivalent to <code>lpeg.Lc(p1, p2, l<sub>1</sub>, ..., l<sub>n</sub>)</code>
@@ -95,18 +92,30 @@ provided by LpegLabel:
95</tbody></table> 92</tbody></table>
96 93
97<p> 94<p>
98In case of an unsucessful matching, the <em>match</em> function now returns 95For a more detailed and formal discussion about
96PEGs with labels please see
97<a href="http://www.inf.puc-rio.br/~roberto/docs/sblp2013-1.pdf">
98Exception Handling for Error Reporting in Parsing Expression Grammars</a>,
99<a href="http://arxiv.org/abs/1405.6646">Error Reporting in Parsing Expression Grammars</a>,
100and <a href="http://dx.doi.org/10.1145/2851613.2851750">
101A parsing machine for parsing expression grammars with labeled failures</a>.
102</p>
103
104<!--
105<p>
106In case of an unsucessful matching, the <em>match</em> function returns
99<code>nil</code> plus a list of labels. These labels may be used to build 107<code>nil</code> plus a list of labels. These labels may be used to build
100a good error message. 108a good error message.
101</p> 109</p>
110-->
102 111
103<h2><a name="func">Functions</a></h2> 112<h2><a name="func">Functions</a></h2>
104 113
105 114
106<h3><a name="f-t"></a><code>lpeglabel.T(l<sub>1</sub>, ..., l<sub>n</sub>)</code></h3> 115<h3><a name="f-t"></a><code>lpeglabel.T(l)</code></h3>
107<p> 116<p>
108Returns a pattern that throws the list of labels <code>l<sub>1</sub>, ..., l<sub>n</sub></code>. 117Returns a pattern that throws the label <code>l</code>.
109A label must be an integer between <code>0</code> and <code>31</code>. 118A label must be an integer between <code>0</code> and <code>63</code>.
110 119
111The label <code>0</code> is equivalent to the regular failure of PEGs. 120The label <code>0</code> is equivalent to the regular failure of PEGs.
112 121
@@ -131,9 +140,9 @@ labeled ordered choice pattern.
131</p> 140</p>
132 141
133 142
134<h3><a name="re-t"></a><code>%{l<sub>1</sub>, ..., l<sub>n</sub>}</code></h3> 143<h3><a name="re-t"></a><code>%{l}</code></h3>
135<p> 144<p>
136Syntax of <em>relabel</em> module. Equivalent to <code>lpeg.T(l<sub>1</sub>, ..., l<sub>n</sub>)</code>. 145Syntax of <em>relabel</em> module. Equivalent to <code>lpeg.T(l)</code>.
137</p> 146</p>
138 147
139 148
@@ -157,7 +166,7 @@ of <code>relabel</code> module will not recognize a pattern as
157<h3><a name="re-setl"></a><code>relabel.setlabels (tlabel)</code></h3> 166<h3><a name="re-setl"></a><code>relabel.setlabels (tlabel)</code></h3>
158 167
159<p>Allows to specicify a table with labels. They keys of 168<p>Allows to specicify a table with labels. They keys of
160<code>tlabel</code> must be integers between <code>0</code> and <code>31</code>, 169<code>tlabel</code> must be integers between <code>0</code> and <code>63</code>,
161and the associated values should be strings. 170and the associated values should be strings.
162</p> 171</p>
163 172