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

19 lines
556 B
Racket

7 years ago
#lang br
(require brag/support)
7 years ago
7 years ago
(define-lex-abbrev digits (:+ (char-set "0123456789")))
7 years ago
(define basic-lexer
(lexer-srcloc
[(eof) (return-without-srcloc eof)]
7 years ago
[whitespace (token lexeme #:skip? #t)]
7 years ago
[(from/to "rem" "\n") (token 'REM lexeme)]
7 years ago
[(:or "print" "goto" "end" "+" ":") lexeme]
7 years ago
[digits (token 'INTEGER (string->number lexeme))]
[(:or (:seq digits ".") (:seq (:? digits) "." digits))
7 years ago
(token 'DECIMAL (string->number lexeme))]
[(from/to "\"" "\"")
(token 'STRING (trim-ends "\"" lexeme "\""))]))
(provide basic-lexer)