lua-users home
lua-l archive

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


On Mon, Nov 25, 2013 at 2:30 PM, Andrew Starks <andrew.starks@trms.com> wrote:
>
>
> Let me know if I can make anything clearer! I live to help with lpeg! :)


One way to help is to post working code! There were two errors. I
miss-named  filename_character in one case.

The other is that the illegal names apply to the extension as well.
Here is a tightened and tested version. Sorry for the noise!

```lua
local lpeg = require'lpeg'

--At the moment I am trying the following:
local P,C,S = lpeg.P, lpeg.C, lpeg.S

local filename_character = P(P(1) -S('\\?|"<>'))
local extension = (P('.') * (filename_character - P('.'))^1) * -1
local filename = C(P((filename_character - extension)^1)) * C(extension)

local t1 = "file.name.ext" --> file.name  ext
local t2 = "file.next_ext"      --> file       next_ext
local t3 = "?file.bad"
local t4 = "other.file.?.bad"

print(extension:match(".ext"))
print(filename:match(t1))
print(filename:match(t2))
print(extension:match(t3), extension:match(t4))

```

--Andrew