lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello,

One of the changes from lpeg 0.9 to 0.10.2 is the new behaviour of the
and predicate (#) which now no longer keeps its captures. Unfortunately
this broke a big (>150 loc) parser in my application, which uses this 
feature quite a lot.  

Is there a trick or workaround to make LPeg show similar behaviour as it
did in 0.9 ?

Below an example snippet showing the different output from 0.9 to
0.10.2. I'd expect { 'foo', 'bar' } as on 0.9, but now returns { 'bar',
nil } on 0.10.2

Thank you,

Ico


  local _, Ct, Cg, P, R = LPeg.V, lpeg.Ct, lpeg.Cg, lpeg.P, lpeg.R
  
  local pat = P {
     "pair",
     pair = Ct(#_'name' * _'value'),
     name = Cg(_'token'),
     value = _'token' * _'HCOLON' * Cg(_'token'),
     HCOLON = P":",
     token = R("az","AZ") ^ 0,
  }
  
  local a = pat:match "foo:bar"
  print(a[1], a[2])
  
  

-- 
:wq
^X^Cy^K^X^C^C^C^C