-
Hey not sure if this is the best place for this. If there's an informal irc or something similar shout. I'm just trying out Janet after doing some reading. PEG's are awesome and I'm attempting to build some utility scripts for myself using it. So I've been able to make a simple file name peg to look for some dated emacs org files: (def directory "some/path/here/")
(def files (os/dir directory))
(def file-filter-peg
'{
:file-month (sequence "2023" "11")
:file-extension (sequence ".org")
:main (sequence :file-month :d :d :file-extension)
}
)
(each file files
(if (peg/match file-filter-peg file)
(do (print directory file " == moved to ==> ")
))) Life is great and this works as expected. When I try to replace the hard coded values with a variable things fall apart for example this would error although I would expect it to be equivalent: (def directory "some/path/here/")
(def files (os/dir directory))
(def current-year "2023")
(def file-filter-peg
'{
:file-month (sequence current-year "11")
:file-extension (sequence ".org")
:main (sequence :file-month :d :d :file-extension)
}
)
(each file files
(if (peg/match file-filter-peg file)
(do (print directory file " == moved to ==> ")
))) results in an error: error: grammar error in current-year, unexpected peg source. Can you not use a bound variable within a PEG definition? Is there some trick to doing so? How for example could you use a value from user input or an arg in a PEG otherwise? Any help would be appreciated I'm sure I'm just missing something syntactically in this language. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Possibly using quasiquoting ( (def file-filter-peg
~{
:file-month (sequence ,current-year "11")
:file-extension (sequence ".org")
:main (sequence :file-month :d :d :file-extension)
}
) For other options regarding communication, there are a few mentioned here (Zulip and Gitter / Matrix - I think Zulip is where things might be transitioning to). |
Beta Was this translation helpful? Give feedback.
Possibly using quasiquoting (
~
) and unquoting (,
) might help:For other options regarding communication, there are a few mentioned here (Zulip and Gitter / Matrix - I think Zulip is where things might be transitioning to).