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/lexer.rkt

23 lines
676 B
Racket

8 years ago
#lang br
(require brag/support)
8 years ago
8 years ago
(define-lex-abbrev digits (:+ (char-set "0123456789")))
8 years ago
(define basic-lexer
(lexer-srcloc
8 years ago
["\n" (token 'NEWLINE lexeme)]
8 years ago
[whitespace (token lexeme #:skip? #t)]
8 years ago
[(from/stop-before "rem" "\n") (token 'REM lexeme)]
[(:or "print" "goto" "end"
"+" ":" ";") (token lexeme lexeme)]
8 years ago
[digits (token 'INTEGER (string->number lexeme))]
8 years ago
[(:or (:seq (:? digits) "." digits)
(:seq digits "."))
8 years ago
(token 'DECIMAL (string->number lexeme))]
8 years ago
[(:or (from/to "\"" "\"") (from/to "'" "'"))
(token 'STRING
(substring lexeme
1 (sub1 (string-length lexeme))))]))
8 years ago
(provide basic-lexer)