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.
beautiful-racket/beautiful-racket-demo/basic-demo/tokenizer.rkt

20 lines
613 B
Racket

#lang br
8 years ago
(require brag/support)
8 years ago
(provide (all-defined-out))
8 years ago
(define basic-lexer
8 years ago
(lexer-srcloc
8 years ago
[(eof) eof]
[whitespace (token lexeme #:skip? #t)]
8 years ago
[(from/to "rem" "\n") (token 'REM lexeme)]
[(:or "print" "goto" "end" "+" ":") lexeme]
[(:+ numeric) (token 'INTEGER (string->number lexeme))]
[(:or (:seq (:+ numeric) ".")
(:seq (:* numeric) "." (:+ numeric)))
(token 'DECIMAL (string->number lexeme))]
8 years ago
[(from/to "\"" "\"") (token 'STRING (trim-ends "\"" lexeme "\""))]))
9 years ago
8 years ago
(define (make-tokenizer ip)
8 years ago
(port-count-lines! ip)
8 years ago
(define (next-token) (basic-lexer ip))
next-token)