JanetDocsPlaygroundI'm feeling luckyGitHub sign in

peg/match



    cfunction
    src/core/peg.c on line 1671, 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.


2 examplesSign in to add an example
Loading...
# 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"}]
sogaiuPlayground
(peg/match ~{:main (capture (some :S))}
           "hello world")
# => @["hello"]
sogaiuPlayground