lua-users home
lua-l archive

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


> > Quick comparison:
> > -----------------------------------------------------------
> > local P = lpeg.P"hello world"    -- pattern in a Lua variable
> > (P * P * P):ptree()
> > -- tree has 66 lines
> > 
> > local P = lpeg.V"P"         -- pattern in a grammar rule
> > lpeg.P{P * P * P, P = lpeg.P"hello world"}:ptree()
> > -- tree has 32 lines
> > -----------------------------------------------------------
> 
>   I see.  Although, when I tried the above as-is, I got:
> 
> lua: ll.lua:3: attempt to perform arithmetic on a nil value (global 'P')
> stack traceback:
> 	ll.lua:3: in main chunk
> 	[C]: in ?

Sorry. Line 3 should start with a ';', otherwise Lua is reading it
as an argument in a call from the previous line:

  local P = lpeg.P"hello world"(P * P * P):ptree()

-- Roberto