(use comparse) (define whitespace (any-of (is #\space) (is #\tab))) (define nl (is #\newline)) (define headline-marks (sequence (one-or-more (is #\*)) (one-or-more whitespace))) (define tag-delim (is #\:)) (define tags (preceded-by tag-delim (one-or-more (none-of* (any-of whitespace tag-delim) item)))) (define last-tag (enclosed-by tag-delim (one-or-more (none-of* (any-of whitespace tag-delim) item)) tag-delim)) (define header-tags (followed-by tag-delim (one-or-more tags))) (define headline-text (repeated item until: (one-or-more header-tags))) (define headline (sequence headline-marks headline-text (zero-or-more header-tags) (none-of item) )) ;; Examples: ;; ;; * Hi this is a simple headline ;; * Another one with a :tag: ;; * Two tags :one:two: ;; * This should not be a tag :haha: as its inside the title ;; * Nor is this a tag as it contains whitespaces :aha :