|
|
@ -1,5 +1,5 @@
|
|
|
|
#lang racket/base
|
|
|
|
#lang racket/base
|
|
|
|
(require brag/support (submod brag/rules/lexer lex-abbrevs) brag/support racket/match)
|
|
|
|
(require brag/support (submod brag/rules/lexer lex-abbrevs) racket/match)
|
|
|
|
(provide color-brag)
|
|
|
|
(provide color-brag)
|
|
|
|
|
|
|
|
|
|
|
|
(define brag-syntax-lexer
|
|
|
|
(define brag-syntax-lexer
|
|
|
@ -8,32 +8,22 @@
|
|
|
|
[whitespace (return-without-srcloc (brag-syntax-lexer input-port))]
|
|
|
|
[whitespace (return-without-srcloc (brag-syntax-lexer input-port))]
|
|
|
|
[(:or (from/to "'" "'") (from/to "\"" "\"")) (token 'LIT lexeme)]
|
|
|
|
[(:or (from/to "'" "'") (from/to "\"" "\"")) (token 'LIT lexeme)]
|
|
|
|
[(:or (char-set "()[]|+*:") hide-char splice-char) (token 'MISC lexeme)]
|
|
|
|
[(:or (char-set "()[]|+*:") hide-char splice-char) (token 'MISC lexeme)]
|
|
|
|
[(:seq (:or "#" ";")
|
|
|
|
[(:seq (:or "#" ";") (complement (:seq (:* any-char) NL (:* any-char))) (:or NL "")) (token 'COMMENT lexeme)]
|
|
|
|
(complement (:seq (:* any-char) NL (:* any-char)))
|
|
|
|
|
|
|
|
(:or NL ""))
|
|
|
|
|
|
|
|
(token 'COMMENT lexeme)]
|
|
|
|
|
|
|
|
[id (token 'ID lexeme)]
|
|
|
|
[id (token 'ID lexeme)]
|
|
|
|
[any-char (token 'OTHER lexeme)]))
|
|
|
|
[any-char (token 'OTHER lexeme)]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (color-brag port)
|
|
|
|
(define (color-brag port)
|
|
|
|
(define srcloc-tok
|
|
|
|
(define srcloc-tok (brag-syntax-lexer port))
|
|
|
|
(with-handlers
|
|
|
|
|
|
|
|
([exn:fail:read?
|
|
|
|
|
|
|
|
(λ (exn) (srcloc-token (token 'ERROR) (car (exn:fail:read-srclocs exn))))])
|
|
|
|
|
|
|
|
(brag-syntax-lexer port)))
|
|
|
|
|
|
|
|
(if (eof-object? srcloc-tok)
|
|
|
|
(if (eof-object? srcloc-tok)
|
|
|
|
(values srcloc-tok 'eof #f #f #f)
|
|
|
|
(values srcloc-tok 'eof #f #f #f)
|
|
|
|
(match-let* ([(srcloc-token
|
|
|
|
(match-let* ([(srcloc-token (token-struct type val _ _ _ _ _) (srcloc _ _ _ posn span)) srcloc-tok]
|
|
|
|
(token-struct type val _ _ _ _ _)
|
|
|
|
|
|
|
|
(srcloc _ _ _ posn span)) srcloc-tok]
|
|
|
|
|
|
|
|
[(cons start end) (cons posn (+ posn span))]
|
|
|
|
[(cons start end) (cons posn (+ posn span))]
|
|
|
|
[(cons _ cat) (or (assq type
|
|
|
|
[(cons _ cat) (or (assq type
|
|
|
|
'((ID . symbol)
|
|
|
|
'((ID . symbol)
|
|
|
|
(LIT . string)
|
|
|
|
(LIT . string)
|
|
|
|
(MISC . parenthesis)
|
|
|
|
(MISC . parenthesis)
|
|
|
|
(COMMENT . comment)
|
|
|
|
(COMMENT . comment)))
|
|
|
|
(ERROR . error)))
|
|
|
|
|
|
|
|
(cons 'OTHER 'no-color))])
|
|
|
|
(cons 'OTHER 'no-color))])
|
|
|
|
(values val cat #f start end))))
|
|
|
|
(values val cat #f start end))))
|
|
|
|
|
|
|
|
|
|
|
|