-
Notifications
You must be signed in to change notification settings - Fork 0
/
color-lexer.rkt
33 lines (30 loc) · 989 Bytes
/
color-lexer.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
31
32
#lang racket/base
(require parser-tools/lex
"lexer.rkt")
(provide color-lexer)
(define (color-lexer in offset mode)
;; Get next token:
(define tok (lex in))
;; Package classification with srcloc:
(define (ret mode paren [eof? #f])
(values (if eof?
eof
(token->string (position-token-token tok)
(token-value (position-token-token tok))))
mode
paren
(position-offset (position-token-start-pos tok))
(position-offset (position-token-end-pos tok))
0
#f))
;; Convert token to classification:
(case (token-name (position-token-token tok))
[(EOF) (ret 'eof #f #t)]
[(WHITESPACE) (ret 'white-space #f)]
[(OPPUSHDATA) (ret 'keyword #f)]
[(OPCODE) (ret 'keyword #f)]
[(HEX) (ret 'string #f)]
[(DEC) (ret 'string #f)]
[(COMMENT) (ret 'comment #f)]
[(ERROR) (ret 'error #f)]
[else (ret 'other #f)]))