(module syntax-color mzscheme
(require (lib "lex.ss" "parser-tools")
(prefix : (lib "lex-sre.ss" "parser-tools"))
"syntax/regexps.ss"
"config.ss")
(define (syn-val lex a b c d)
(values lex a b (position-offset c) (position-offset d)))
(define (colorize-string delimiter my-start-pos)
(define lxr
(lexer
[(:or #\' #\")
(if (string=? lexeme delimiter)
(syn-val "" 'string #f my-start-pos end-pos)
(lxr input-port))]
[(eof) (syn-val "" 'error #f my-start-pos end-pos)]
[(:seq #\\ (:or #\' #\")) (lxr input-port)]
[any-char (lxr input-port)]))
lxr)
(define (colorize-block-comment my-start-pos)
(define lxr
(lexer
[(:seq #\* #\/)
(syn-val "" 'comment #f my-start-pos end-pos)]
[(eof) (syn-val "" 'error #f my-start-pos end-pos)]
[any-char (lxr input-port)]))
lxr)
(define get-syntax-token
(lexer
[(:or "true" "false" "null")
(syn-val lexeme 'literal #f start-pos end-pos)]
[lex:integer
(syn-val lexeme 'literal #f start-pos end-pos)]
[lex:float
(syn-val lexeme 'literal #f start-pos end-pos)]
[(:or "[" "]" "{" "}" "(" ")")
(syn-val lexeme 'parenthesis (string->symbol lexeme) start-pos end-pos)]
[(:or "," ":" ";" "=" ".")
(syn-val lexeme 'default #f start-pos end-pos)]
[(:seq #\/ #\*)
((colorize-block-comment start-pos) input-port)]
[lex:line-comment
(syn-val lexeme 'comment #f start-pos end-pos)]
[lex:assignment-operator
(syn-val lexeme 'keyword #f start-pos end-pos)]
[lex:operator
(syn-val lexeme 'keyword #f start-pos end-pos)]
[lex:identifier
(if (memq (string->symbol lexeme) (lexical-keywords))
(syn-val lexeme 'keyword #f start-pos end-pos)
(syn-val lexeme 'identifier #f start-pos end-pos))]
[(:or #\' #\")
((colorize-string lexeme start-pos) input-port)]
[(:+ lex:whitespace)
(syn-val lexeme 'whitespace #f start-pos end-pos)]
[(eof)
(syn-val lexeme 'eof #f start-pos end-pos)]
[any-char
(syn-val lexeme 'error #f start-pos end-pos)]
))
(provide get-syntax-token))