Moved PEG inline.
This commit is contained in:
parent
4e09df7310
commit
1f4a56fa43
31
nowopen
31
nowopen
@ -42,9 +42,6 @@ Usage: nowopen [-p] [--help] [tags...]
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local lpeg = require('lpeg')
|
|
||||||
local re = require('re')
|
|
||||||
|
|
||||||
local today = os.date("*t")
|
local today = os.date("*t")
|
||||||
local now = os.time(today)
|
local now = os.time(today)
|
||||||
|
|
||||||
@ -58,9 +55,31 @@ local function secs(t)
|
|||||||
return math.floor(t % 60)
|
return math.floor(t % 60)
|
||||||
end
|
end
|
||||||
|
|
||||||
local f = io.open('places.peg')
|
local re = require('re')
|
||||||
local dsl = re.compile(f:read('*a'), {tab="\t"})
|
local dsl = re.compile([=[
|
||||||
f:close()
|
file <- {| (place / ws? comment? %nl)* |} {.+}?
|
||||||
|
place <- {|
|
||||||
|
{:name: {word (ws word)*} :}
|
||||||
|
ws? ("(" ws? {:tags: {| {tag} (ws? "," ws? {tag})* ws? |} :} ")")? ws? ":"
|
||||||
|
({:times: {|
|
||||||
|
((ws? comment? %nl)+ (%tab / " "^+2) ws?
|
||||||
|
{| days ws? ("closed" / {:open: time :} "-" {:close: time :}) |})+
|
||||||
|
|} :})
|
||||||
|
|}
|
||||||
|
comment <- "#" [^%nl]*
|
||||||
|
days <-
|
||||||
|
({:from: {word} :} "-" {:to: {word} :} ":")
|
||||||
|
/({:from: {word} :} ":")
|
||||||
|
/({:from:''->'sun':} {:to:''->'sat':})
|
||||||
|
time <- {|
|
||||||
|
{:hour: {[0-9]+} :} (":" {:minute: {[0-9]+} :})? {:ampm: { "am" / "pm"} :}
|
||||||
|
/ ("noon" {:hour: {~''->'12'~} :} {:ampm: {~''->'pm'~} :})
|
||||||
|
/ ("midnight" {:hour: {~''->'12'~} :} {:ampm: {~''->'am'~} :})
|
||||||
|
|}
|
||||||
|
tag <- word (" "+ word)*
|
||||||
|
word <- [^%nl%tab (),:#0-9-]+
|
||||||
|
ws <- [ %tab]+
|
||||||
|
]=], {tab="\t"})
|
||||||
local places,err = dsl:match(place_text)
|
local places,err = dsl:match(place_text)
|
||||||
if err then
|
if err then
|
||||||
print("Failed to parse config file:")
|
print("Failed to parse config file:")
|
||||||
|
24
places.peg
24
places.peg
@ -1,24 +0,0 @@
|
|||||||
file <- {| (place / ws? comment? %nl)* |} {.+}?
|
|
||||||
place <- {|
|
|
||||||
{:name: {word (ws word)*} :}
|
|
||||||
ws? ("(" ws? {:tags: {| {tag} (ws? "," ws? {tag})* ws? |} :} ")")? ws? ":"
|
|
||||||
({:times: {|
|
|
||||||
((ws? comment? %nl)+ (%tab / " "^+2) ws? {| days ws? ("closed" / {:open: time :} "-" {:close: time :}) |})+
|
|
||||||
|} :})
|
|
||||||
|}
|
|
||||||
|
|
||||||
comment <- "#" [^%nl]*
|
|
||||||
|
|
||||||
days <-
|
|
||||||
({:from: {word} :} "-" {:to: {word} :} ":")
|
|
||||||
/({:from: {word} :} ":")
|
|
||||||
/({:from:''->'sun':} {:to:''->'sat':})
|
|
||||||
|
|
||||||
time <- {|
|
|
||||||
{:hour: {[0-9]+} :} (":" {:minute: {[0-9]+} :})? {:ampm: { "am" / "pm"} :}
|
|
||||||
/ ("noon" {:hour: {~''->'12'~} :} {:ampm: {~''->'pm'~} :})
|
|
||||||
/ ("midnight" {:hour: {~''->'12'~} :} {:ampm: {~''->'am'~} :})
|
|
||||||
|}
|
|
||||||
tag <- word (" "+ word)*
|
|
||||||
word <- [^%nl%tab (),:#0-9-]+
|
|
||||||
ws <- [ %tab]+
|
|
Loading…
Reference in New Issue
Block a user