|
|
|
@ -5,23 +5,22 @@
|
|
|
|
|
(module+ reader
|
|
|
|
|
(provide read-syntax))
|
|
|
|
|
|
|
|
|
|
(define-lex-abbrev regex-chars (char-set "()*+?.^$|<!=[]"))
|
|
|
|
|
(define-lex-abbrev reserved-chars (char-set "()*+?.^$|<!=[]"))
|
|
|
|
|
|
|
|
|
|
(define tokenize
|
|
|
|
|
(lexer
|
|
|
|
|
[(:+ "\n") (token 'NEWLINE lexeme)]
|
|
|
|
|
[(from/stop-before ";" "\n") (token 'COMMENT #:skip? #t)]
|
|
|
|
|
[(:+ whitespace) (token 'SP lexeme #:skip? #t)]
|
|
|
|
|
[regex-chars lexeme]
|
|
|
|
|
[reserved-chars lexeme]
|
|
|
|
|
[alphabetic (token 'LITERAL lexeme)]))
|
|
|
|
|
|
|
|
|
|
(define (read-syntax src ip)
|
|
|
|
|
(define parse-tree (parse (λ () (tokenize ip))))
|
|
|
|
|
(strip-context
|
|
|
|
|
(with-syntax ([PT parse-tree])
|
|
|
|
|
#'(module regexcellent-mod regexcellent-demo
|
|
|
|
|
(for ([line (in-list PT)])
|
|
|
|
|
(displayln line))))))
|
|
|
|
|
#'(module mod-name regexcellent-demo
|
|
|
|
|
(for-each displayln PT)))))
|
|
|
|
|
|
|
|
|
|
(define-macro (top . LINES) #'(list . LINES))
|
|
|
|
|
|
|
|
|
@ -31,15 +30,16 @@
|
|
|
|
|
(define (pat . xs)
|
|
|
|
|
(if (= (length xs) 1)
|
|
|
|
|
(car xs)
|
|
|
|
|
(format "a sequence starting with ~a" (string-join xs ", followed by "))))
|
|
|
|
|
(format "a sequence (~a)" (string-join xs ", followed by "))))
|
|
|
|
|
|
|
|
|
|
(define (lookbehind pat)
|
|
|
|
|
(format "a lookbehind assertion of ~a" pat))
|
|
|
|
|
|
|
|
|
|
(define (lookahead pat)
|
|
|
|
|
(format "a lookahead assertion of ~a" pat))
|
|
|
|
|
|
|
|
|
|
(define (choice . pats)
|
|
|
|
|
(format "a choice of ~a" (string-join pats "; or ")))
|
|
|
|
|
(format "a choice of ~a" (string-join pats " or ")))
|
|
|
|
|
|
|
|
|
|
(define (repeat thing [quantifier #f] [maybe-non-greedy? #f])
|
|
|
|
|
(string-join
|
|
|
|
@ -58,9 +58,9 @@
|
|
|
|
|
|
|
|
|
|
(define (any) "any character")
|
|
|
|
|
(define (start) "the start of the input")
|
|
|
|
|
(define (end) "the end of the input")
|
|
|
|
|
(define (end) "the end of the input")
|
|
|
|
|
|
|
|
|
|
(define (literal str) (~v str))
|
|
|
|
|
|
|
|
|
|
(define (literals . strs)
|
|
|
|
|
(format "the literal string ~v" (string-join strs "")))
|
|
|
|
|
(define (chars . lits)
|
|
|
|
|
(format "any member of the character set {~a}" (string-join (map ~v lits) ", ")))
|
|
|
|
|
(format "any member of the character set {~a}" (string-join (map ~a lits) " ")))
|