diff options
author | Andre Murbach Maidl <andremm@gmail.com> | 2015-10-07 17:39:13 -0300 |
---|---|---|
committer | Andre Murbach Maidl <andremm@gmail.com> | 2015-10-07 17:39:13 -0300 |
commit | a949129c2f3d24c7614093376083082f5beb83da (patch) | |
tree | 9265b16b235dbfbf2c11f75b0fb95ac6342f176a | |
parent | e8e389b9ddebe6ced19d5f4bc112b309ffe1a8ff (diff) | |
download | lpeglabel-a949129c2f3d24c7614093376083082f5beb83da.tar.gz lpeglabel-a949129c2f3d24c7614093376083082f5beb83da.tar.bz2 lpeglabel-a949129c2f3d24c7614093376083082f5beb83da.zip |
Adding labels and messages for malformed expressions
-rwxr-xr-x | examples/typedlua/test.lua | 10 | ||||
-rw-r--r-- | examples/typedlua/tlerror.lua | 14 | ||||
-rw-r--r-- | examples/typedlua/tlparser.lua | 30 |
3 files changed, 34 insertions, 20 deletions
diff --git a/examples/typedlua/test.lua b/examples/typedlua/test.lua index ffdbd70..aa78856 100755 --- a/examples/typedlua/test.lua +++ b/examples/typedlua/test.lua | |||
@@ -1757,7 +1757,7 @@ a = 3 / / 2 | |||
1757 | test.lua:1:9: syntax error, unexpected '/', expecting '(', 'Name', '{', 'function', '...', 'true', 'false', 'nil', 'String', 'Number', '#', '~', '-', 'not' | 1757 | test.lua:1:9: syntax error, unexpected '/', expecting '(', 'Name', '{', 'function', '...', 'true', 'false', 'nil', 'String', 'Number', '#', '~', '-', 'not' |
1758 | ]=] | 1758 | ]=] |
1759 | e = [=[ | 1759 | e = [=[ |
1760 | test.lua:1:9: unexpected '/', expecting '(', 'Name', '{', 'function', '...', 'true', 'false', 'nil', 'String', 'Number', '#', '~', '-', 'not' | 1760 | test.lua:1:9: malformed multiplication expression |
1761 | ]=] | 1761 | ]=] |
1762 | 1762 | ||
1763 | r, m = parse(s) | 1763 | r, m = parse(s) |
@@ -1772,7 +1772,7 @@ b = 1 && 1 | |||
1772 | test.lua:1:8: syntax error, unexpected '&', expecting '(', 'Name', '{', 'function', '...', 'true', 'false', 'nil', 'String', 'Number', '#', '~', '-', 'not' | 1772 | test.lua:1:8: syntax error, unexpected '&', expecting '(', 'Name', '{', 'function', '...', 'true', 'false', 'nil', 'String', 'Number', '#', '~', '-', 'not' |
1773 | ]=] | 1773 | ]=] |
1774 | e = [=[ | 1774 | e = [=[ |
1775 | test.lua:1:8: unexpected '&', expecting '(', 'Name', '{', 'function', '...', 'true', 'false', 'nil', 'String', 'Number', '#', '~', '-', 'not' | 1775 | test.lua:1:8: malformed '&' expression |
1776 | ]=] | 1776 | ]=] |
1777 | 1777 | ||
1778 | r, m = parse(s) | 1778 | r, m = parse(s) |
@@ -1785,7 +1785,7 @@ b = 1 <> 0 | |||
1785 | test.lua:1:8: syntax error, unexpected '>', expecting '(', 'Name', '{', 'function', '...', 'true', 'false', 'nil', 'String', 'Number', '#', '~', '-', 'not' | 1785 | test.lua:1:8: syntax error, unexpected '>', expecting '(', 'Name', '{', 'function', '...', 'true', 'false', 'nil', 'String', 'Number', '#', '~', '-', 'not' |
1786 | ]=] | 1786 | ]=] |
1787 | e = [=[ | 1787 | e = [=[ |
1788 | test.lua:1:8: unexpected '>', expecting '(', 'Name', '{', 'function', '...', 'true', 'false', 'nil', 'String', 'Number', '#', '~', '-', 'not' | 1788 | test.lua:1:8: malformed relational expression |
1789 | ]=] | 1789 | ]=] |
1790 | 1790 | ||
1791 | r, m = parse(s) | 1791 | r, m = parse(s) |
@@ -1798,7 +1798,7 @@ b = 1 < < 0 | |||
1798 | test.lua:1:9: syntax error, unexpected '<', expecting '(', 'Name', '{', 'function', '...', 'true', 'false', 'nil', 'String', 'Number', '#', '~', '-', 'not' | 1798 | test.lua:1:9: syntax error, unexpected '<', expecting '(', 'Name', '{', 'function', '...', 'true', 'false', 'nil', 'String', 'Number', '#', '~', '-', 'not' |
1799 | ]=] | 1799 | ]=] |
1800 | e = [=[ | 1800 | e = [=[ |
1801 | test.lua:1:9: unexpected '<', expecting '(', 'Name', '{', 'function', '...', 'true', 'false', 'nil', 'String', 'Number', '#', '~', '-', 'not' | 1801 | test.lua:1:9: malformed relational expression |
1802 | ]=] | 1802 | ]=] |
1803 | 1803 | ||
1804 | r, m = parse(s) | 1804 | r, m = parse(s) |
@@ -1973,7 +1973,7 @@ end | |||
1973 | test.lua:7:1: syntax error, unexpected 'end', expecting '(', 'Name', '{', 'function', '...', 'true', 'false', 'nil', 'String', 'Number', '#', '~', '-', 'not' | 1973 | test.lua:7:1: syntax error, unexpected 'end', expecting '(', 'Name', '{', 'function', '...', 'true', 'false', 'nil', 'String', 'Number', '#', '~', '-', 'not' |
1974 | ]=] | 1974 | ]=] |
1975 | e = [=[ | 1975 | e = [=[ |
1976 | test.lua:7:1: missing 'end' to close if statement | 1976 | test.lua:7:1: expecting <exp> after 'elseif' |
1977 | ]=] | 1977 | ]=] |
1978 | 1978 | ||
1979 | r, m = parse(s) | 1979 | r, m = parse(s) |
diff --git a/examples/typedlua/tlerror.lua b/examples/typedlua/tlerror.lua index 6881b6b..c51a53b 100644 --- a/examples/typedlua/tlerror.lua +++ b/examples/typedlua/tlerror.lua | |||
@@ -38,6 +38,20 @@ new_error("Label2", "expecting '::' to close label declaration") | |||
38 | new_error("LocalAssign", "expecting expression list after '='") | 38 | new_error("LocalAssign", "expecting expression list after '='") |
39 | new_error("ForGen", "expecting 'in'") | 39 | new_error("ForGen", "expecting 'in'") |
40 | new_error("LocalFunc", "expecting <name> in local function declaration") | 40 | new_error("LocalFunc", "expecting <name> in local function declaration") |
41 | new_error("Exp", "malformed expression") | ||
42 | new_error("ElseIf", "expecting <exp> after 'elseif'") | ||
43 | new_error("SubExpr_1", "malformed 'or' expression") | ||
44 | new_error("SubExpr_2", "malformed 'and' expression") | ||
45 | new_error("SubExpr_3", "malformed relational expression") | ||
46 | new_error("SubExpr_4", "malformed '|' expression") | ||
47 | new_error("SubExpr_5", "malformed '~' expression") | ||
48 | new_error("SubExpr_6", "malformed '&' expression") | ||
49 | new_error("SubExpr_7", "malformed shift expression") | ||
50 | new_error("SubExpr_8", "malformed '..' expression") | ||
51 | new_error("SubExpr_9", "malformed addition expression") | ||
52 | new_error("SubExpr_10", "malformed multiplication expression") | ||
53 | new_error("SubExpr_11", "malformed unary expression") | ||
54 | new_error("SubExpr_12", "malformed '^' expression") | ||
41 | 55 | ||
42 | local labels = {} | 56 | local labels = {} |
43 | for k, v in ipairs(errors) do | 57 | for k, v in ipairs(errors) do |
diff --git a/examples/typedlua/tlparser.lua b/examples/typedlua/tlparser.lua index 2180812..67a06a4 100644 --- a/examples/typedlua/tlparser.lua +++ b/examples/typedlua/tlparser.lua | |||
@@ -7,7 +7,7 @@ local tllexer = require "tllexer" | |||
7 | local tlerror = require "tlerror" | 7 | local tlerror = require "tlerror" |
8 | 8 | ||
9 | local function chainl1 (pat, sep, label) | 9 | local function chainl1 (pat, sep, label) |
10 | return pat * (sep * pat)^0 | 10 | return pat * (sep * tllexer.try(pat, label))^0 |
11 | end | 11 | end |
12 | 12 | ||
13 | local G = lpeg.P { "TypedLua"; | 13 | local G = lpeg.P { "TypedLua"; |
@@ -102,7 +102,7 @@ local G = lpeg.P { "TypedLua"; | |||
102 | tllexer.symb("<") + | 102 | tllexer.symb("<") + |
103 | tllexer.symb(">"); | 103 | tllexer.symb(">"); |
104 | BOrOp = tllexer.symb("|"); | 104 | BOrOp = tllexer.symb("|"); |
105 | BXorOp = tllexer.symb("~"); | 105 | BXorOp = tllexer.symb("~") * -lpeg.P("="); |
106 | BAndOp = tllexer.symb("&"); | 106 | BAndOp = tllexer.symb("&"); |
107 | ShiftOp = tllexer.symb("<<") + | 107 | ShiftOp = tllexer.symb("<<") + |
108 | tllexer.symb(">>"); | 108 | tllexer.symb(">>"); |
@@ -119,20 +119,20 @@ local G = lpeg.P { "TypedLua"; | |||
119 | tllexer.symb("#"); | 119 | tllexer.symb("#"); |
120 | PowOp = tllexer.symb("^"); | 120 | PowOp = tllexer.symb("^"); |
121 | Expr = lpeg.V("SubExpr_1"); | 121 | Expr = lpeg.V("SubExpr_1"); |
122 | SubExpr_1 = chainl1(lpeg.V("SubExpr_2"), lpeg.V("OrOp")); | 122 | SubExpr_1 = chainl1(lpeg.V("SubExpr_2"), lpeg.V("OrOp"), "SubExpr_1"); |
123 | SubExpr_2 = chainl1(lpeg.V("SubExpr_3"), lpeg.V("AndOp")); | 123 | SubExpr_2 = chainl1(lpeg.V("SubExpr_3"), lpeg.V("AndOp"), "SubExpr_2"); |
124 | SubExpr_3 = chainl1(lpeg.V("SubExpr_4"), lpeg.V("RelOp")); | 124 | SubExpr_3 = chainl1(lpeg.V("SubExpr_4"), lpeg.V("RelOp"), "SubExpr_3"); |
125 | SubExpr_4 = chainl1(lpeg.V("SubExpr_5"), lpeg.V("BOrOp")); | 125 | SubExpr_4 = chainl1(lpeg.V("SubExpr_5"), lpeg.V("BOrOp"), "SubExpr_4"); |
126 | SubExpr_5 = chainl1(lpeg.V("SubExpr_6"), lpeg.V("BXorOp")); | 126 | SubExpr_5 = chainl1(lpeg.V("SubExpr_6"), lpeg.V("BXorOp"), "SubExpr_5"); |
127 | SubExpr_6 = chainl1(lpeg.V("SubExpr_7"), lpeg.V("BAndOp")); | 127 | SubExpr_6 = chainl1(lpeg.V("SubExpr_7"), lpeg.V("BAndOp"), "SubExpr_6"); |
128 | SubExpr_7 = chainl1(lpeg.V("SubExpr_8"), lpeg.V("ShiftOp")); | 128 | SubExpr_7 = chainl1(lpeg.V("SubExpr_8"), lpeg.V("ShiftOp"), "SubExpr_7"); |
129 | SubExpr_8 = lpeg.V("SubExpr_9") * lpeg.V("ConOp") * lpeg.V("SubExpr_8") + | 129 | SubExpr_8 = lpeg.V("SubExpr_9") * lpeg.V("ConOp") * tllexer.try(lpeg.V("SubExpr_8"), "SubExpr_8") + |
130 | lpeg.V("SubExpr_9"); | 130 | lpeg.V("SubExpr_9"); |
131 | SubExpr_9 = chainl1(lpeg.V("SubExpr_10"), lpeg.V("AddOp")); | 131 | SubExpr_9 = chainl1(lpeg.V("SubExpr_10"), lpeg.V("AddOp"), "SubExpr_9"); |
132 | SubExpr_10 = chainl1(lpeg.V("SubExpr_11"), lpeg.V("MulOp")); | 132 | SubExpr_10 = chainl1(lpeg.V("SubExpr_11"), lpeg.V("MulOp"), "SubExpr_10"); |
133 | SubExpr_11 = lpeg.V("UnOp") * lpeg.V("SubExpr_11") + | 133 | SubExpr_11 = lpeg.V("UnOp") * tllexer.try(lpeg.V("SubExpr_11"), "SubExpr_11") + |
134 | lpeg.V("SubExpr_12"); | 134 | lpeg.V("SubExpr_12"); |
135 | SubExpr_12 = lpeg.V("SimpleExp") * (lpeg.V("PowOp") * lpeg.V("SubExpr_11"))^-1; | 135 | SubExpr_12 = lpeg.V("SimpleExp") * (lpeg.V("PowOp") * tllexer.try(lpeg.V("SubExpr_11"), "SubExpr_12"))^-1; |
136 | SimpleExp = tllexer.token(tllexer.Number, "Number") + | 136 | SimpleExp = tllexer.token(tllexer.Number, "Number") + |
137 | tllexer.token(tllexer.String, "String") + | 137 | tllexer.token(tllexer.String, "String") + |
138 | tllexer.kw("nil") + | 138 | tllexer.kw("nil") + |
@@ -151,7 +151,7 @@ local G = lpeg.P { "TypedLua"; | |||
151 | tllexer.symb("(") * lpeg.V("Expr") * tllexer.try(tllexer.symb(")"), "MissingCP"); | 151 | tllexer.symb("(") * lpeg.V("Expr") * tllexer.try(tllexer.symb(")"), "MissingCP"); |
152 | Block = lpeg.V("StatList") * lpeg.V("RetStat")^-1; | 152 | Block = lpeg.V("StatList") * lpeg.V("RetStat")^-1; |
153 | IfStat = tllexer.kw("if") * lpeg.V("Expr") * tllexer.try(tllexer.kw("then"), "Then") * lpeg.V("Block") * | 153 | IfStat = tllexer.kw("if") * lpeg.V("Expr") * tllexer.try(tllexer.kw("then"), "Then") * lpeg.V("Block") * |
154 | (tllexer.kw("elseif") * lpeg.V("Expr") * tllexer.try(tllexer.kw("then"), "Then") * lpeg.V("Block"))^0 * | 154 | (tllexer.kw("elseif") * tllexer.try(lpeg.V("Expr"), "ElseIf") * tllexer.try(tllexer.kw("then"), "Then") * lpeg.V("Block"))^0 * |
155 | (tllexer.kw("else") * lpeg.V("Block"))^-1 * | 155 | (tllexer.kw("else") * lpeg.V("Block"))^-1 * |
156 | tllexer.try(tllexer.kw("end"), "IfEnd"); | 156 | tllexer.try(tllexer.kw("end"), "IfEnd"); |
157 | WhileStat = tllexer.kw("while") * lpeg.V("Expr") * | 157 | WhileStat = tllexer.kw("while") * lpeg.V("Expr") * |