[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lpeg for a filename
- From: Andrew Starks <andrew.starks@...>
- Date: Mon, 25 Nov 2013 14:42:56 -0600
On Mon, Nov 25, 2013 at 2:30 PM, Andrew Starks <firstname.lastname@example.org> 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!
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"