You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
574 B
Racket
28 lines
574 B
Racket
8 years ago
|
#lang racket/base
|
||
|
|
||
|
(provide tokenize)
|
||
|
|
||
|
;; A simple lexer for simple-line-drawing.
|
||
3 years ago
|
(require yaragg/support
|
||
3 years ago
|
yaragg/parser-tools/lex)
|
||
8 years ago
|
|
||
|
(define (tokenize ip)
|
||
|
(port-count-lines! ip)
|
||
|
(define my-lexer
|
||
|
(lexer-src-pos
|
||
|
[(repetition 1 +inf.0 numeric)
|
||
|
(token 'INTEGER (string->number lexeme))]
|
||
|
[upper-case
|
||
|
(token 'STRING lexeme)]
|
||
|
["b"
|
||
|
(token 'STRING " ")]
|
||
|
[";"
|
||
|
(token ";" lexeme)]
|
||
|
[whitespace
|
||
|
(token 'WHITESPACE lexeme #:skip? #t)]
|
||
|
[(eof)
|
||
|
(void)]))
|
||
|
(define (next-token) (my-lexer ip))
|
||
|
next-token)
|
||
|
|