diff options
Diffstat (limited to 'examples/recovery.lua')
-rw-r--r-- | examples/recovery.lua | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/examples/recovery.lua b/examples/recovery.lua index 7af8455..3272ae7 100644 --- a/examples/recovery.lua +++ b/examples/recovery.lua | |||
@@ -15,10 +15,10 @@ local labels = { | |||
15 | {"MisClose", "missing a closing ')' after the expression"}, | 15 | {"MisClose", "missing a closing ')' after the expression"}, |
16 | } | 16 | } |
17 | 17 | ||
18 | -- The `labelIndex` function gives us the index of a label in the | 18 | -- The `labelindex` function gives us the index of a label in the |
19 | -- `labels` table, which serves as the integer representation of the label. | 19 | -- `labels` table, which serves as the integer representation of the label. |
20 | -- We need this because LPegLabel requires us to use integers for the labels. | 20 | -- We need this because LPegLabel requires us to use integers for the labels. |
21 | local function labelIndex(labname) | 21 | local function labelindex(labname) |
22 | for i, elem in ipairs(labels) do | 22 | for i, elem in ipairs(labels) do |
23 | if elem[1] == labname then | 23 | if elem[1] == labname then |
24 | return i | 24 | return i |
@@ -35,12 +35,12 @@ local errors = {} | |||
35 | -- Before throwing the label, it records the label to be thrown along with | 35 | -- Before throwing the label, it records the label to be thrown along with |
36 | -- the position of the failure (index in input string) into the `errors` table. | 36 | -- the position of the failure (index in input string) into the `errors` table. |
37 | local function expect(patt, labname) | 37 | local function expect(patt, labname) |
38 | local i = labelIndex(labname) | 38 | local i = labelindex(labname) |
39 | function recordError(input, pos) | 39 | function recorderror(input, pos) |
40 | table.insert(errors, {i, pos}) | 40 | table.insert(errors, {i, pos}) |
41 | return true | 41 | return true |
42 | end | 42 | end |
43 | return patt + Cmt("", recordError) * T(i) | 43 | return patt + Cmt("", recorderror) * T(i) |
44 | end | 44 | end |
45 | 45 | ||
46 | local num = R("09")^1 / tonumber | 46 | local num = R("09")^1 / tonumber |
@@ -76,15 +76,15 @@ local g = P { | |||
76 | "Exp", | 76 | "Exp", |
77 | Exp = Ct(V"Term" * (C(op) * V"OpRecov")^0) / compute; | 77 | Exp = Ct(V"Term" * (C(op) * V"OpRecov")^0) / compute; |
78 | -- `OpRecov` handles missing terms/operands by returning a dummy (zero). | 78 | -- `OpRecov` handles missing terms/operands by returning a dummy (zero). |
79 | OpRecov = Lc(V"Operand", Cc(0), labelIndex("ExpTerm")); | 79 | OpRecov = Lc(V"Operand", Cc(0), labelindex("ExpTerm")); |
80 | Operand = expect(V"Term", "ExpTerm"); | 80 | Operand = expect(V"Term", "ExpTerm"); |
81 | Term = num + V"Group"; | 81 | Term = num + V"Group"; |
82 | -- `Group` handles missing closing parenthesis by simply ignoring it. | 82 | -- `Group` handles missing closing parenthesis by simply ignoring it. |
83 | -- Like all the others, the error is still recorded of course. | 83 | -- Like all the others, the error is still recorded of course. |
84 | Group = "(" * V"InnerExp" * Lc(expect(")", "MisClose"), P"", labelIndex("MisClose")); | 84 | Group = "(" * V"InnerExp" * Lc(expect(")", "MisClose"), P"", labelindex("MisClose")); |
85 | -- `InnerExp` handles missing expressions by skipping to the next closing | 85 | -- `InnerExp` handles missing expressions by skipping to the next closing |
86 | -- parenthesis. A dummy (zero) is returned in place of the expression. | 86 | -- parenthesis. A dummy (zero) is returned in place of the expression. |
87 | InnerExp = Lc(expect(V"Exp", "ExpExp"), (P(1) - ")")^0 * Cc(0), labelIndex("ExpExp")); | 87 | InnerExp = Lc(expect(V"Exp", "ExpExp"), (P(1) - ")")^0 * Cc(0), labelindex("ExpExp")); |
88 | } | 88 | } |
89 | 89 | ||
90 | g = expect(g, "NoExp") * expect(-P(1), "Extra") | 90 | g = expect(g, "NoExp") * expect(-P(1), "Extra") |