-
Notifications
You must be signed in to change notification settings - Fork 0
/
gg-colorer.rkt
30 lines (29 loc) · 1002 Bytes
/
gg-colorer.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#lang br
(require "gg-lexer.rkt" brag/support)
(provide gg-colorer)
(define (gg-colorer port)
(define (handle-lexer-error excn)
(define excn-srclocs (exn:fail:read-srclocs excn))
(srcloc-token (token 'ERROR) (car excn-srclocs)))
(define srcloc-tok
(with-handlers ([exn:fail:read? handle-lexer-error])
(top-lexer port)))
(match srcloc-tok
[(? eof-object?) (values srcloc-tok 'eof #f #f #f)]
[else
(match-define
(srcloc-token
(token-struct type val _ _ _ _ _)
(srcloc _ _ _ posn span)) srcloc-tok)
(define start posn)
(define end (+ start span))
(match-define (list cat paren)
(match val
["(" '(parenthesis |(|)]
[")" '(parenthesis |)|)]
["[" '(parenthesis |[|)]
["]" '(parenthesis |]|)]
["{" '(parenthesis |{|)]
["}" '(parenthesis |}|)]
[else '(no-color #f)]))
(values val cat paren start end)]))