lua-users home
lua-l archive

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


Hi,

I've been playing with lpeg (which is totally rad) for the last couple
of days, and to good effect.

This evening, I've been experimenting with moving my grammar from the
full (intense) lpeg syntax to use to use (nicer?) the re.compile [[
... ]] syntax... It's going okay, but I'm having a problem with
newlines.

Consider this (heavily simplified) example:

---
require 'lpeg'
require 're'

gg = re.compile [[
	Chunk      <- ( <Word> <Space> )+ -> {}
	Word       <- { [a-d]+ }
	Space      <- { ( " " / "\n" )* }
]]

t = gg:match( "a b c d" )
for k, v in pairs(t) do
	print( k..": "..v )
end
---

This example works. Strangely, when I change the space between the 'c'
and the 'd' to a newline ("\n"), so the line reads like this:
t = gg.match( "a b\nc d" )

It matches the 'a', then the 'b' and then fails silently. Why?

I have alternatively tried this definition of <Space>:
	Space      <- { [ \n]* }

Which I also think should work, but fails in the same way.

Any insight appreciated.

Thanks,
-Harold