1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-24 04:07:41 +00:00

Update PEG documentation and peg syntax.

Disable tail calls in the root scope for better
stacktraces, as the root scope may contain a single call
to a failing function, as in the case of the test suite.
This commit is contained in:
Calvin Rose
2019-01-14 20:41:32 -05:00
parent 99f176f37b
commit 90313afd40
4 changed files with 95 additions and 45 deletions

View File

@@ -238,8 +238,8 @@
(def csv
'{:field (+
(* `"` (| (any (+ (- 1 `"`) (/ `""` `"`)))) `"`)
(| (any (- 1 (set ",\n")))))
(* `"` (| (any (+ (if-not `"` 1) (/ `""` `"`)))) `"`)
(| (any (if-not (set ",\n") 1))))
:main (* :field (any (* "," :field)) (+ "\n" -1))})
(defn check-csv
@@ -258,12 +258,12 @@
# Functions in grammar
(def grmr-triple ~(| (any (/ 1 ,(fn [x] (string x x x))))))
(def grmr-triple ~(| (any (/ (<- 1) ,(fn [x] (string x x x))))))
(check-deep grmr-triple "abc" @["aaabbbccc"])
(check-deep grmr-triple "" @[""])
(check-deep grmr-triple " " @[" "])
(def counter ~(/ (group (^ (capture 1) 0)) ,length))
(def counter ~(/ (group (any (<- 1))) ,length))
(check-deep counter "abcdefg" @[7])
# Capture Backtracking
@@ -294,7 +294,7 @@
~{:pad (any "=")
:open (* "[" (capture :pad) "[")
:close (* "]" (cmt (* (backref 0) (capture :pad)) ,=) "]")
:main (* :open (any (if-not 1 :close)) :close -1)})
:main (* :open (any (if-not :close 1)) :close -1)})
(check-match wrapped-string "[[]]" true)
(check-match wrapped-string "[==[a]==]" true)
@@ -309,7 +309,7 @@
(def janet-longstring
~{:open (capture (some "`"))
:close (cmt (* (backref 0) :open) ,=)
:main (* :open (any (if-not 1 :close)) (not (> -1 "`")) :close -1)})
:main (* :open (any (if-not :close 1)) (not (> -1 "`")) :close -1)})
(check-match janet-longstring "`john" false)
(check-match janet-longstring "abc" false)