aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2019-01-05 16:50:27 -0800
committerBruce Hill <bruce@bruce-hill.com>2019-01-05 16:50:27 -0800
commit1f4a56fa439cbbde0b5b2769687a70683c402750 (patch)
treebbc095d32f7718def4d44a2a3be83b3119434274
parent4e09df7310729466a33def66880c117c1fba9817 (diff)
Moved PEG inline.
-rwxr-xr-xnowopen31
-rw-r--r--places.peg24
2 files changed, 25 insertions, 30 deletions
diff --git a/nowopen b/nowopen
index 1874d5f..f8ae491 100755
--- a/nowopen
+++ b/nowopen
@@ -42,9 +42,6 @@ Usage: nowopen [-p] [--help] [tags...]
end
end
-local lpeg = require('lpeg')
-local re = require('re')
-
local today = os.date("*t")
local now = os.time(today)
@@ -58,9 +55,31 @@ local function secs(t)
return math.floor(t % 60)
end
-local f = io.open('places.peg')
-local dsl = re.compile(f:read('*a'), {tab="\t"})
-f:close()
+local re = require('re')
+local dsl = re.compile([=[
+ 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)
if err then
print("Failed to parse config file:")
diff --git a/places.peg b/places.peg
deleted file mode 100644
index dbde5e7..0000000
--- a/places.peg
+++ /dev/null
@@ -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]+