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
568 B
Racket
28 lines
568 B
Racket
#lang racket/base
|
|
|
|
(provide tokenize)
|
|
|
|
;; A simple lexer for simple-line-drawing.
|
|
(require br/ragg/support
|
|
parser-tools/lex)
|
|
|
|
(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)
|
|
|