straighten out lexing

pull/10/head
Matthew Butterick 8 years ago
parent c35b02c986
commit dfe6ef6ffd

@ -5,19 +5,18 @@
(define-lex-abbrev reserved-terms (:or "print" "goto" "end" "+" ":" ";" "let" "=" "input" "-" "*" "/" "^" "mod" "(" ")" "def" "if" "then" "else" "<" ">" "<>" "and" "or" "not" "gosub" "return" "for" "to" "step" "next" "def" "," "import" "export"))
(define-lex-abbrev id-kapu
(define-lex-abbrev racket-id-kapu
(:or whitespace (char-set "()[]{}\",'`;#|\\")))
(define-lex-abbrev racket-id
(:seq "[" (:~ (:or "-" id-kapu)) (:* (:~ id-kapu)) "]"))
(define basic-lexer
(lexer-srcloc
[(eof) (return-without-srcloc eof)]
["\n" (token 'NEWLINE lexeme)]
[whitespace (token lexeme #:skip? #t)]
[(from/stop-before "rem" "\n") (token 'REM lexeme)]
[racket-id (token 'RACKET-ID (string->symbol (trim-ends "[" lexeme "]")))]
[(:seq "[" (:+ (:~ racket-id-kapu)) "]")
(token 'RACKET-ID
(string->symbol (trim-ends "[" lexeme "]")))]
[reserved-terms (token lexeme lexeme)]
[(:seq alphabetic (:* (:or alphabetic numeric "$")))
(token 'ID (string->symbol lexeme))]

@ -1,7 +1,7 @@
#lang basic-demo-3
10 import math/number-theory
20 print nth-prime(15)
30 print prime?(24)
40 import racket/base
50 print max(f(1), f(2), f(5), f(4))
10 import [math/number-theory]
20 print [nth-prime](15)
30 print [prime?](24)
40 import [racket/base]
50 print [max](f(1), f(2), f(5), f(4))
60 def f(x) = x + x

@ -0,0 +1,5 @@
#lang br
(require basic-demo-3/sample-exporter)
div
x
(div x 10)

@ -1,5 +0,0 @@
#lang br
(require "sample-export.rkt")
div
x
(div x 10)

@ -5,9 +5,9 @@
(define basic-output-port
(make-parameter (open-output-nowhere)))
(define (do-setup!)
(define (do-setup! [where #f])
(basic-output-port (current-output-port))
(current-read-interaction read-one-line))
#;(current-read-interaction read-one-line))
(define repl-parser (make-rule-parser b-repl))

Loading…
Cancel
Save