From c5574a9e8396498769e1f2a91609d08cbb0f86eb Mon Sep 17 00:00:00 2001 From: Sérgio Queiroz Date: Tue, 19 Dec 2017 13:13:10 -0300 Subject: Updating relabel's parser after removing /{} and //{} --- relabel.lua | 38 +++----------------------------------- testrelabelparser.lua | 41 +++++++++++------------------------------ 2 files changed, 14 insertions(+), 65 deletions(-) diff --git a/relabel.lua b/relabel.lua index 6a676b9..3188163 100644 --- a/relabel.lua +++ b/relabel.lua @@ -31,7 +31,7 @@ local errinfo = { {"NoPatt", "no pattern found"}, {"ExtraChars", "unexpected characters after the pattern"}, - {"ExpPatt1", "expected a pattern after '/' and '//{...}', or the label(s) after '/{' and '//{'"}, + {"ExpPatt1", "expected a pattern after '/'"}, {"ExpPatt2", "expected a pattern after '&'"}, {"ExpPatt3", "expected a pattern after '!'"}, @@ -52,8 +52,7 @@ local errinfo = { {"ExpName2", "expected the name of a rule after '=' (no space)"}, {"ExpName3", "expected the name of a rule after '<' (no space)"}, - {"ExpLab1", "expected at least one label after '{'"}, - {"ExpLab2", "expected a label after the comma"}, + {"ExpLab1", "expected a label after '{'"}, {"ExpNameOrLab", "expected a name or label after '%' (no space)"}, @@ -216,41 +215,10 @@ local function NT (n, b) end end -local function choicerec (...) - local t = { ... } - local n = #t - local p = t[1] - local i = 2 - - while i + 2 <= n do - -- t[i] is '/' or '//' - -- t[i+1] == false when there are no labels - -- t[i+2] is a pattern - if t[i] == '/' then - if not t[i+1] then - p = mt.__add(p, t[i+2]) - else - p = mm.Lc(p, t[i+2], unpack(t[i+1])) - end - else -- t[i] is '//' - p = mm.Rec(p, t[i+2], unpack(t[i+1])) - end - i = i + 3 - end - - return p -end - local exp = m.P{ "Exp", Exp = S * ( m.V"Grammar" - + (m.V"Seq" * (S * ((m.C(m.P"//" + "/") * m.Ct(m.V"Labels")) + (m.C"/" * m.Cc(false))) - * expect(S * m.V"Seq", "ExpPatt1") - )^0 - ) / choicerec); - Labels = m.P"{" * expect(S * m.V"Label", "ExpLab1") - * (S * "," * expect(S * m.V"Label", "ExpLab2"))^0 - * expect(S * "}", "MisClose7"); + + m.Cf(m.V"Seq" * (S * "/" * expect(S * m.V"Seq", "ExpPatt1"))^0, mt.__add) ); Seq = m.Cf(m.Cc(m.P"") * m.V"Prefix" * (S * m.V"Prefix")^0, mt.__mul); Prefix = "&" * expect(S * m.V"Prefix", "ExpPatt2") / mt.__len + "!" * expect(S * m.V"Prefix", "ExpPatt3") / mt.__unm diff --git a/testrelabelparser.lua b/testrelabelparser.lua index 2ca8528..0399ff6 100644 --- a/testrelabelparser.lua +++ b/testrelabelparser.lua @@ -53,26 +53,14 @@ L1:C5: unexpected characters after the pattern -- testing ExpPatt1 -testerror([['p' //{1}]], [[ -L1:C10: expected a pattern after '/' and '//{...}', or the label(s) after '/{' and '//{' -'p' //{1} - ^ -]]) - -testerror([['p' //{1} //{2} 'q']], [[ -L1:C10: expected a pattern after '/' and '//{...}', or the label(s) after '/{' and '//{' -'p' //{1} //{2} 'q' - ^ -]]) - testerror([['p' /]], [[ -L1:C6: expected a pattern after '/' and '//{...}', or the label(s) after '/{' and '//{' +L1:C6: expected a pattern after '/' 'p' / ^ ]]) testerror([['p' / / 'q']], [[ -L1:C6: expected a pattern after '/' and '//{...}', or the label(s) after '/{' and '//{' +L1:C6: expected a pattern after '/' 'p' / / 'q' ^ ]]) @@ -249,22 +237,22 @@ L1:C2: expected a pattern or closing '}' after '{' ^ ]]) --- testing ExpNum +-- testing ExpNumName testerror([['p' ^ n]], [[ -L1:C6: expected a number after '^', '+' or '-' (no space) +L1:C6: expected a number, '+', '-' or a name (no space) after '^' 'p' ^ n ^ ]]) testerror([['p'^+(+1)]], [[ -L1:C5: expected a number after '^', '+' or '-' (no space) +L1:C5: expected a number, '+', '-' or a name (no space) after '^' 'p'^+(+1) ^ ]]) testerror([['p'^-/'q']], [[ -L1:C5: expected a number after '^', '+' or '-' (no space) +L1:C5: expected a number, '+', '-' or a name (no space) after '^' 'p'^-/'q' ^ ]]) @@ -351,25 +339,18 @@ L1:C2: expected the name of a rule after '<' (no space) -- testing ExpLab1 -testerror([['p' //{} 'q']], [[ -L1:C8: expected at least one label after '{' -'p' //{} 'q' - ^ +testerror([['p' %{} 'q']], [[ +L1:C7: expected a label after '{' +'p' %{} 'q' + ^ ]]) testerror([[%{ 'label' }]], [[ -L1:C3: expected at least one label after '{' +L1:C3: expected a label after '{' %{ 'label' } ^ ]]) --- testing ExpLab2 - -testerror([['p' //{1,2,3,} 'q']], [[ -L1:C14: expected a label after the comma -'p' //{1,2,3,} 'q' - ^ -]]) -- testing ExpNameOrLab -- cgit v1.2.3-55-g6feb