reorg
parent
acf9e65315
commit
f49f42003a
@ -1,22 +1,30 @@
|
||||
#lang br
|
||||
(require "lexer.rkt" brag/support)
|
||||
(provide color-basic)
|
||||
(provide basic-colorer)
|
||||
|
||||
(define (color-basic port)
|
||||
(define srcloc-tok (basic-lexer port))
|
||||
(match srcloc-tok
|
||||
[(? eof-object?) (values srcloc-tok 'eof #f #f #f)]
|
||||
[else ; reverse-engineer with `match-define`
|
||||
(define (basic-colorer port)
|
||||
(define next-char (peek-char port))
|
||||
(define (handle-read-error exn)
|
||||
(define exn-srclocs (exn:fail:read-srclocs exn))
|
||||
(srcloc-token (token 'ERROR (string next-char)) (car exn-srclocs)))
|
||||
(define srcloc-tok (with-handlers ([exn:fail:read? handle-read-error])
|
||||
(basic-lexer port)))
|
||||
(cond
|
||||
[(eof-object? srcloc-tok) (values srcloc-tok 'eof #f #f #f)]
|
||||
[else
|
||||
(match-define (srcloc-token (token-struct type val _ _ _ _ _)
|
||||
(srcloc _ _ _ pos span)) srcloc-tok)
|
||||
(define (color cat [paren #f])
|
||||
(values (or val "") cat paren pos (+ pos span)))
|
||||
(match type
|
||||
['STRING (color 'string)]
|
||||
['REM (color 'comment)]
|
||||
[else (match val
|
||||
[(? number?) (color 'constant)]
|
||||
[(? symbol?) (color 'symbol)]
|
||||
["(" (color 'parenthesis '|(|)]
|
||||
[")" (color 'parenthesis '|)|)]
|
||||
[else (color 'no-color)])])]))
|
||||
(match-define (list cat paren)
|
||||
(match type
|
||||
['STRING '(string #f)]
|
||||
['REM '(comment #f)]
|
||||
['ERROR '(error #f)]
|
||||
[else (match val
|
||||
[(? number?)'(constant #f)]
|
||||
[(? symbol?) '(symbol #f)]
|
||||
["(" '(parenthesis |(|)]
|
||||
[")" '(parenthesis |)|)]
|
||||
[else '(no-color #f)])]))
|
||||
(values (or val "") cat paren pos (+ pos span))]))
|
||||
|
||||
(apply-colorer basic-colorer "foo")
|
@ -1,3 +1,3 @@
|
||||
#lang br
|
||||
(require "line.rkt" "go.rkt" "if.rkt" "expr.rkt" "for.rkt" "misc.rkt")
|
||||
(provide (all-from-out "line.rkt" "go.rkt" "if.rkt" "expr.rkt" "for.rkt" "misc.rkt"))
|
||||
(require "line.rkt" "go.rkt" "if.rkt" "expr.rkt" "misc.rkt")
|
||||
(provide (all-from-out "line.rkt" "go.rkt" "if.rkt" "expr.rkt" "misc.rkt"))
|
@ -1,30 +0,0 @@
|
||||
#lang br
|
||||
(require "misc.rkt" "line.rkt")
|
||||
(provide b-for b-next)
|
||||
|
||||
(define thunk-table (make-hasheq))
|
||||
|
||||
(define-macro-cases b-for
|
||||
[(_ LOOP-ID START END) #'(b-for LOOP-ID START END 1)]
|
||||
[(_ LOOP-ID START END STEP)
|
||||
#'(b-let LOOP-ID (let/cc loop-cc
|
||||
(hash-set! thunk-table
|
||||
'LOOP-ID
|
||||
(λ ()
|
||||
(define next-val (+ LOOP-ID STEP))
|
||||
(if (next-val . in-closed-interval? . START END)
|
||||
(loop-cc next-val)
|
||||
(hash-remove! thunk-table 'LOOP-ID))))
|
||||
START))])
|
||||
|
||||
(define (in-closed-interval? x start end)
|
||||
(if (< start end)
|
||||
(<= start x end)
|
||||
(<= end x start)))
|
||||
|
||||
(define-macro (b-next LOOP-ID)
|
||||
#'(begin
|
||||
(unless (hash-has-key? thunk-table 'LOOP-ID)
|
||||
(raise-line-error "next without for"))
|
||||
(define thunk (hash-ref thunk-table 'LOOP-ID))
|
||||
(thunk)))
|
@ -1,8 +1,6 @@
|
||||
#lang basic-demo-2
|
||||
10 for a = 1 to 3
|
||||
20 print a
|
||||
21 for b = 103 to 101 step -1
|
||||
22 print b
|
||||
21 for b = 9 to 7 step -1
|
||||
22 print a ; b
|
||||
23 next b
|
||||
30 next a
|
||||
40 print "yay"
|
||||
30 next a
|
Loading…
Reference in New Issue