generated from dannypsnl-fork/racket-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexer.rkt
37 lines (34 loc) · 833 Bytes
/
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
33
34
35
36
37
#lang racket/base
(provide lex)
(require parser-tools/lex
(prefix-in : parser-tools/lex-sre)
racket/string)
(define-empty-tokens symbol
(|(|
|)|
|'|
|,|
|,@|))
(define-tokens datum
(IDENTIFIER
STRING
NUMBER))
(define lex
(lexer-src-pos
[(eof) eof]
[(:or whitespace blank iso-control) (void)]
["(" (token-|(|)]
[")" (token-|)|)]
["'" (token-|'|)]
["," (token-|,|)]
[",@" (token-|,@|)]
[(:: (:or (char-set "+-.*/<=>!?:$%_&~^") alphabetic)
(:* (:or (char-set "+-.*/<=>!?:$%_&~^")
numeric
alphabetic)))
(token-IDENTIFIER (string->symbol lexeme))]
[(:+ numeric)
(token-NUMBER (string->number lexeme))]
[(:seq "\"" (:* (:~ #\")) "\"")
(token-STRING (string-trim lexeme
"\""))]))