diff options
author | Colin Okay <cbeok@protonmail.com> | 2020-04-26 19:32:50 -0500 |
---|---|---|
committer | Colin Okay <cbeok@protonmail.com> | 2020-04-26 19:32:50 -0500 |
commit | 7a0b5932c01779df99f3d87175be9b850031f859 (patch) | |
tree | ffbc00cdafb2827a58c1ab8f3ee609f8421103b2 | |
parent | 9beb6ee949824c3aa19dc458af0590d0389da680 (diff) |
added <<counting, <<counting+, and <whitespace+<
-rw-r--r-- | examples/org-mode-toc.lisp | 2 | ||||
-rw-r--r-- | package.lisp | 3 | ||||
-rw-r--r-- | parzival.lisp | 10 |
3 files changed, 14 insertions, 1 deletions
diff --git a/examples/org-mode-toc.lisp b/examples/org-mode-toc.lisp index 5355b02..d88822e 100644 --- a/examples/org-mode-toc.lisp +++ b/examples/org-mode-toc.lisp @@ -12,7 +12,7 @@ (make-string (* 2 count) :initial-element #\Space) toc-entry toc-entry))) - (<<and <whitespace<+ (<<+ <item<))))) + (<<and <whitespace+< (<<+ <item<))))) "Accepts a valid Org Mode heading and results in an org mode list item with a link to that heading.") diff --git a/package.lisp b/package.lisp index e1ee9a5..efd3e50 100644 --- a/package.lisp +++ b/package.lisp @@ -17,6 +17,8 @@ #:<<char-equal #:<<cons #:<<cons-map + #:<<counting + #:<<counting+ #:<<def #:<<ending #:<<filter @@ -70,6 +72,7 @@ #:<tab< #:<uppercase< #:<whitespace< + #:<whitespace+< #:<word< #:<~alphanum< #:<~digit< diff --git a/parzival.lisp b/parzival.lisp index bedc86f..cc88725 100644 --- a/parzival.lisp +++ b/parzival.lisp @@ -425,6 +425,14 @@ the character C." (<<cons parser (<<* parser))) +(defun <<counting (parser) + "runs PARSER zero or more times, resulting in the number of times PARSER succeeded." + (<<map #'length (<<* parser))) + +(defun <<counting+ (parser) + "Runs PARSER one or more times, resulting in the number of times PARSER succeeded." + (<<map #'length (<<+ parser))) + (defun <<times (n parser) "Builds a parser that will run PARSER exactly N times, returning a list of the results." @@ -505,6 +513,8 @@ the character C." (<<def <whitespace< (<<* (<<or <space< <newline< <return< <linefeed< <tab<)) "Parses zero or more whitespace characters, returning them as a list") +(<<def <whitespace+< (<<+ (<<or <space< <newline< <return< <linefeed< <tab<)) + "Parsers at one or more whitespace characters, returning them as a list") (<<def <word< (<<to-string (<<+ <letter<)) "Parses a sequence of one or more letters characters, resulting in |