comment.ss
#lang scheme/base
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; NET.plt
;;
;; abstraction of common network behaviors and services
;;
;; Bonzai Lab, LLC.  All rights reserved.
;;
;; Licensed under LGPL.
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; comment.ss - parser for rfc2822 comment.
;; yc 2/13/2010 - first version.

(require "depend.ss"
         mzlib/defmacro
         (for-syntax scheme/base
                     )
         )

;; comment as defined is a
(define p:comment (seq #\(
                     chars <- (zero-many (choice (char-not-in '(#\( #\)))
                                                 p:comment))
                     #\)
                     (return (flatten chars))))

(define p:comments (tokens v <- (zero-many (token p:comment))
                         (return v)))

;; comment can occur in many of the positions... what we want is to make it into
;; part of the tokens so it *disappears*...

;; (define comment-tokenizer (token comments))
(define (p:comment-tokenizer parser)
  (token parser p:comments))

(define (p:comment-tokenizer-ci parser)
  (p:comment-tokenizer (literal-ci parser))) 

;; tokens
;; generating a sequence of tokens...
(define-macro (tokens/comment . exps)
  `(tokens/by p:comment-tokenizer . ,exps))

(define-macro (tokens/comment-ci . exps)
  `(tokens/by p:comment-tokenizer-ci . ,exps))

(provide tokens/comment
         tokens/comment-ci
         )

(provide/contract 
 (p:comment-tokenizer (-> Literal-Parser/c Parser/c))
 (p:comment Parser/c)
 (p:comments Parser/c)
 (p:comment-tokenizer-ci (-> Literal-Parser/c Parser/c))
 )