cfunction
src/core/peg.c on line 1697, column 1
(peg/match peg text &opt start & args)
Match a Parsing Expression Grammar to a byte string and return an
array of captured values. Returns nil if text does not match the
language defined by peg. The syntax of PEGs is documented on the
Janet website.
# convert a string to an integer
(peg/match '(number :d+) "123")
#=> @[123]
(first (peg/match '(number :d+) "123"))
#=> 123
# more at https://github.com/sogaiu/margaret/tree/master/examples
(peg/match ~{:main (replace (some :header-line)
,(fn [& captures]
(table ;captures)))
:header-line (sequence (capture :header-name) ":"
:s+
(capture :header-value) :crlf)
:header-name (to ":")
:header-value (to :crlf)
:crlf "\r\n"}
(string "Content-Type: text/plain\r\n"
"Content-Length: 1024\r\n"))
# => @[@{"Content-Length" "1024" "Content-Type" "text/plain"}]
(peg/match ~{:main (capture (some :S))}
"hello world")
# => @["hello"]