diff options
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 48 |
1 files changed, 24 insertions, 24 deletions
@@ -35,21 +35,21 @@ Below there is a brief summary of the new functions provided by LpegLabel: | |||
35 | 35 | ||
36 | <table border="1"> | 36 | <table border="1"> |
37 | <tbody><tr><td><b>Function</b></td><td><b>Description</b></td></tr> | 37 | <tbody><tr><td><b>Function</b></td><td><b>Description</b></td></tr> |
38 | <tr><td><a href="#f-t"><code>lpeglabelrec.T (l)</code></a></td> | 38 | <tr><td><a href="#f-t"><code>lpeglabel.T (l)</code></a></td> |
39 | <td>Throws a label <code>l</code> to signal an error</td></tr> | 39 | <td>Throws a label <code>l</code> to signal an error</td></tr> |
40 | <tr><td><a href="#f-rec"><code>lpeglabelrec.Rec (p1, p2, l1 [, l2, ..., ln])</code></a></td> | 40 | <tr><td><a href="#f-rec"><code>lpeglabel.Rec (p1, p2, l1 [, l2, ..., ln])</code></a></td> |
41 | <td>Specifies a recovery pattern <code>p2</code> for <code>p1</code>, | 41 | <td>Specifies a recovery pattern <code>p2</code> for <code>p1</code>, |
42 | when the matching of <code>p1</code> gives one of the labels l1, ..., ln.</td></tr> | 42 | when the matching of <code>p1</code> gives one of the labels l1, ..., ln.</td></tr> |
43 | <tr><td><a href="#re-t"><code>%{l}</code></a></td> | 43 | <tr><td><a href="#re-t"><code>%{l}</code></a></td> |
44 | <td>Syntax of <em>relabelrec</em> module. Equivalent to <code>lpeglabelrec.T(l)</code> | 44 | <td>Syntax of <em>relabel</em> module. Equivalent to <code>lpeglabel.T(l)</code> |
45 | </td></tr> | 45 | </td></tr> |
46 | <tr><td><a href="#re-rec"><code>p1 //{l1 [, l2, ..., ln} p2</code></a></td> | 46 | <tr><td><a href="#re-rec"><code>p1 //{l1 [, l2, ..., ln} p2</code></a></td> |
47 | <td>Syntax of <em>relabelrec</em> module. Equivalent to <code>lpeglabelrec.Rec(p1, p2, l1, ..., ln)</code> | 47 | <td>Syntax of <em>relabel</em> module. Equivalent to <code>lpeglabel.Rec(p1, p2, l1, ..., ln)</code> |
48 | </td></tr> | 48 | </td></tr> |
49 | <tr><td><a href="#re-line"><code>relabelrec.calcline(subject, i)</code></a></td> | 49 | <tr><td><a href="#re-line"><code>relabel.calcline(subject, i)</code></a></td> |
50 | <td>Calculates line and column information regarding position <i>i</i> of the subject</code> | 50 | <td>Calculates line and column information regarding position <i>i</i> of the subject</code> |
51 | </td></tr> | 51 | </td></tr> |
52 | <tr><td><a href="#re-setl"><code>relabelrec.setlabels (tlabel)</code></a></td> | 52 | <tr><td><a href="#re-setl"><code>relabel.setlabels (tlabel)</code></a></td> |
53 | <td>Allows to specicify a table with mnemonic labels. | 53 | <td>Allows to specicify a table with mnemonic labels. |
54 | </td></tr> | 54 | </td></tr> |
55 | </tbody></table> | 55 | </tbody></table> |
@@ -58,14 +58,14 @@ Below there is a brief summary of the new functions provided by LpegLabel: | |||
58 | ### Functions | 58 | ### Functions |
59 | 59 | ||
60 | 60 | ||
61 | #### <a name="f-t"></a><code>lpeglabelrec.T(l)</code> | 61 | #### <a name="f-t"></a><code>lpeglabel.T(l)</code> |
62 | 62 | ||
63 | 63 | ||
64 | Returns a pattern that throws the label `l`. | 64 | Returns a pattern that throws the label `l`. |
65 | A label must be an integer between 1 and 255. | 65 | A label must be an integer between 1 and 255. |
66 | 66 | ||
67 | 67 | ||
68 | #### <a name="f-rec"></a><code>lpeglabelrec.Rec(p1, p2, l1, ..., ln)</code> | 68 | #### <a name="f-rec"></a><code>lpeglabel.Rec(p1, p2, l1, ..., ln)</code> |
69 | 69 | ||
70 | Returns a *recovery pattern*. | 70 | Returns a *recovery pattern*. |
71 | If the matching of `p1` gives one of the labels `l1, ..., ln`, | 71 | If the matching of `p1` gives one of the labels `l1, ..., ln`, |
@@ -76,23 +76,23 @@ Otherwise, the result of the matching of `p1` is the pattern's result. | |||
76 | 76 | ||
77 | #### <a name="re-t"></a><code>%{l}</code> | 77 | #### <a name="re-t"></a><code>%{l}</code> |
78 | 78 | ||
79 | Syntax of *relabelrec* module. Equivalent to `lpeg.T(l)`. | 79 | Syntax of *relabel* module. Equivalent to `lpeg.T(l)`. |
80 | 80 | ||
81 | 81 | ||
82 | #### <a name="re-lc"></a><code>p1 //{l1, ..., ln} p2</code> | 82 | #### <a name="re-lc"></a><code>p1 //{l1, ..., ln} p2</code> |
83 | 83 | ||
84 | Syntax of *relabelrec* module. Equivalent to `lpeglabelrec.Rec(p1, p2, l1, ..., ln)`. | 84 | Syntax of *relabel* module. Equivalent to `lpeglabel.Rec(p1, p2, l1, ..., ln)`. |
85 | 85 | ||
86 | The `//{}` operator is left-associative. | 86 | The `//{}` operator is left-associative. |
87 | 87 | ||
88 | 88 | ||
89 | 89 | ||
90 | #### <a name="re-line"></a><code>relabelrec.calcline (subject, i)</code> | 90 | #### <a name="re-line"></a><code>relabel.calcline (subject, i)</code> |
91 | 91 | ||
92 | Returns line and column information regarding position <i>i</i> of the subject. | 92 | Returns line and column information regarding position <i>i</i> of the subject. |
93 | 93 | ||
94 | 94 | ||
95 | #### <a name="re-setl"></a><code>relabelrec.setlabels (tlabel)</code> | 95 | #### <a name="re-setl"></a><code>relabel.setlabels (tlabel)</code> |
96 | 96 | ||
97 | Allows to specicify a table with labels. They keys of | 97 | Allows to specicify a table with labels. They keys of |
98 | `tlabel` must be integers between 1 and 255, | 98 | `tlabel` must be integers between 1 and 255, |
@@ -118,8 +118,8 @@ table and to return the index associated with each error message. | |||
118 | 118 | ||
119 | 119 | ||
120 | ```lua | 120 | ```lua |
121 | local m = require'lpeglabelrec' | 121 | local m = require'lpeglabel' |
122 | local re = require'relabelrec' | 122 | local re = require'relabel' |
123 | 123 | ||
124 | local terror = {} | 124 | local terror = {} |
125 | 125 | ||
@@ -176,7 +176,7 @@ the <em>regular</em> matching. For example, in the example below | |||
176 | we expect to match rule `A`, but when a failure occur the label 42 | 176 | we expect to match rule `A`, but when a failure occur the label 42 |
177 | is thrown and then we will try to match the recovery pattern `recp`: | 177 | is thrown and then we will try to match the recovery pattern `recp`: |
178 | ```lua | 178 | ```lua |
179 | local m = require'lpeglabelrec' | 179 | local m = require'lpeglabel' |
180 | 180 | ||
181 | local recp = m.P"oast" | 181 | local recp = m.P"oast" |
182 | 182 | ||
@@ -223,8 +223,8 @@ When the matching of an identifier fails, a defaul value ('NONE') | |||
223 | is provided. | 223 | is provided. |
224 | 224 | ||
225 | ```lua | 225 | ```lua |
226 | local m = require'lpeglabelrec' | 226 | local m = require'lpeglabel' |
227 | local re = require'relabelrec' | 227 | local re = require'relabel' |
228 | 228 | ||
229 | local terror = {} | 229 | local terror = {} |
230 | 230 | ||
@@ -311,14 +311,14 @@ print(mymatch(grec, "one\n two123, \nthree,")) | |||
311 | -- Error at line 3 (col 6): expecting an identifier | 311 | -- Error at line 3 (col 6): expecting an identifier |
312 | ``` | 312 | ``` |
313 | 313 | ||
314 | ##### *relabelrec* syntax | 314 | ##### *relabel* syntax |
315 | 315 | ||
316 | Below we describe again a grammar that matches a list of identifiers, | 316 | Below we describe again a grammar that matches a list of identifiers, |
317 | now using the syntax supported by *relabelrec*, where `//{}` is the | 317 | now using the syntax supported by *relabel*, where `//{}` is the |
318 | recovery operator, and `%{}` is the throw operator: | 318 | recovery operator, and `%{}` is the throw operator: |
319 | 319 | ||
320 | ```lua | 320 | ```lua |
321 | local re = require 'relabelrec' | 321 | local re = require 'relabel' |
322 | 322 | ||
323 | local errinfo = { | 323 | local errinfo = { |
324 | {"errUndef", "undefined"}, | 324 | {"errUndef", "undefined"}, |
@@ -428,8 +428,8 @@ task to build manually the recovery grammar `grec`. In the next example | |||
428 | we will show how to build the recovery grammar in a more automatic way. | 428 | we will show how to build the recovery grammar in a more automatic way. |
429 | 429 | ||
430 | ```lua | 430 | ```lua |
431 | local m = require"lpeglabelrec" | 431 | local m = require"lpeglabel" |
432 | local re = require"relabelrec" | 432 | local re = require"relabel" |
433 | 433 | ||
434 | local labels = { | 434 | local labels = { |
435 | {"ExpTermFirst", "expected an expression"}, | 435 | {"ExpTermFirst", "expected an expression"}, |
@@ -566,8 +566,8 @@ In the example below we also throw an error when the grammar | |||
566 | does not match the whole subject. | 566 | does not match the whole subject. |
567 | 567 | ||
568 | ```lua | 568 | ```lua |
569 | local m = require"lpeglabelrec" | 569 | local m = require"lpeglabel" |
570 | local re = require"relabelrec" | 570 | local re = require"relabel" |
571 | 571 | ||
572 | local num = m.R("09")^1 / tonumber | 572 | local num = m.R("09")^1 / tonumber |
573 | local op = m.S("+-") | 573 | local op = m.S("+-") |