Welcome to the CHICKEN Scheme pasting service

parser for headlines pasted by C-Keen on Fri Aug 31 13:46:13 2012

(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 :

Some assistance! pasted by DerGuteMoritz on Fri Aug 31 14:04:50 2012

(use comparse)

(define whitespace
  (in #\space #\tab))

(define nl (is #\newline))

(define end-of-input
  (none-of item))

(define headline-marks
  (sequence* ((marks (one-or-more (is #\*)))
              (_ (one-or-more whitespace)))
    (result (length marks))))


(define tag-delim (is #\:))

(define tag
  (preceded-by tag-delim
               (as-string (repeated item until: (any-of whitespace tag-delim)))))

(define headline-text
  (as-string (repeated item until: (any-of (one-or-more tag) nl end-of-input))))

(define headline
  (sequence* ((level headline-marks)
              (text headline-text)
              (tags (zero-or-more tag)))
    (let* ((value `(headline (level ,level)
                             (text ,text)))
           (value (if (null? tags)
                      value
                      (append value `((tags . ,tags))))))
      (result value))))

;; 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 :

(use test)

(define-syntax test-parser
  (syntax-rules ()
    ((_ parser in out)
     (test out (parse parser in)))))

(test-parser whitespace " " #\space)

(test-parser headline
             "* Hi this is a simple headline"
             '(headline (level 1)
                        (text "Hi this is a simple headline")))

(test-parser headline
             "* Another one with a :tag:"
             '(headline (level 1)
                        (text "Another one with a ")
                        (tags "tag")))

almost there pasted by DerGuteMoritz on Fri Aug 31 14:27:10 2012

(use comparse)

(define whitespace
  (in #\space #\tab))

(define nl (is #\newline))

(define end-of-input
  (none-of item))

(define headline-marks
  (sequence* ((marks (one-or-more (is #\*)))
              (_ (one-or-more whitespace)))
    (result (length marks))))


(define tag-delim (is #\:))

(define tag
  (preceded-by tag-delim
               (as-string
                (repeated (none-of* whitespace item)
                          until: tag-delim))))

(define header-tags
  (sequence* ((tags (zero-or-more tag))
              (_ tag-delim)
              (_ (zero-or-more whitespace))
              (_ (any-of nl end-of-input)))
    (result tags)))

(define headline-text
  (as-string
   (repeated item until: (any-of header-tags nl end-of-input))))

(define headline
  (sequence* ((level headline-marks)
              (text headline-text)
              (tags (maybe header-tags)))
    (let* ((value `(headline (level ,level)
                             (text ,text)))
           (value (if (pair? tags)
                      (append value `((tags . ,tags)))
                      value)))
      (result value))))

;; 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 :

(use test)

(define-syntax test-parser
  (syntax-rules ()
    ((_ parser in out)
     (test out (parse parser in)))))

(test-parser whitespace " " #\space)

(test-parser headline
             "* Hi this is a simple headline"
             '(headline (level 1)
                        (text "Hi this is a simple headline")))

(test-parser headline
             "* Another one with a :tag:"
             '(headline (level 1)
                        (text "Another one with a ")
                        (tags "tag")))

(test-parser headline
             "* Two tags :one:two:"
             '(headline (level 1)
                        (text "Two tags ")
                        (tags "one" "two")))

(test-parser headline
             "* This should not be a tag :haha: as its inside the title"
             '(headline (level 1)
                        (text "This should not be a tag :haha: as its inside the title")))

(test-parser headline
             "* Nor is this a tag as it contains whitespaces :aha :"
             '(headline (level 1)
                        (text "Nor is this a tag as it contains whitespaces :aha :")))

HA! found it added by DerGuteMoritz on Fri Aug 31 14:29:44 2012

(define header-tags
  (sequence* ((tags (one-or-more tag))
              (_ tag-delim)
              (_ (zero-or-more whitespace))
              (_ (any-of nl end-of-input)))
    (result tags)))

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
What type of object does `for-each' expect as second argument?
Visually impaired? Let me spell it for you (wav file) download WAV