reorg
parent
acf9e65315
commit
f49f42003a
@ -1,22 +1,30 @@
|
|||||||
#lang br
|
#lang br
|
||||||
(require "lexer.rkt" brag/support)
|
(require "lexer.rkt" brag/support)
|
||||||
(provide color-basic)
|
(provide basic-colorer)
|
||||||
|
|
||||||
(define (color-basic port)
|
(define (basic-colorer port)
|
||||||
(define srcloc-tok (basic-lexer port))
|
(define next-char (peek-char port))
|
||||||
(match srcloc-tok
|
(define (handle-read-error exn)
|
||||||
[(? eof-object?) (values srcloc-tok 'eof #f #f #f)]
|
(define exn-srclocs (exn:fail:read-srclocs exn))
|
||||||
[else ; reverse-engineer with `match-define`
|
(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 _ _ _ _ _)
|
(match-define (srcloc-token (token-struct type val _ _ _ _ _)
|
||||||
(srcloc _ _ _ pos span)) srcloc-tok)
|
(srcloc _ _ _ pos span)) srcloc-tok)
|
||||||
(define (color cat [paren #f])
|
(match-define (list cat paren)
|
||||||
(values (or val "") cat paren pos (+ pos span)))
|
(match type
|
||||||
(match type
|
['STRING '(string #f)]
|
||||||
['STRING (color 'string)]
|
['REM '(comment #f)]
|
||||||
['REM (color 'comment)]
|
['ERROR '(error #f)]
|
||||||
[else (match val
|
[else (match val
|
||||||
[(? number?) (color 'constant)]
|
[(? number?)'(constant #f)]
|
||||||
[(? symbol?) (color 'symbol)]
|
[(? symbol?) '(symbol #f)]
|
||||||
["(" (color 'parenthesis '|(|)]
|
["(" '(parenthesis |(|)]
|
||||||
[")" (color 'parenthesis '|)|)]
|
[")" '(parenthesis |)|)]
|
||||||
[else (color 'no-color)])])]))
|
[else '(no-color #f)])]))
|
||||||
|
(values (or val "") cat paren pos (+ pos span))]))
|
||||||
|
|
||||||
|
(apply-colorer basic-colorer "foo")
|
@ -1,3 +1,3 @@
|
|||||||
#lang br
|
#lang br
|
||||||
(require "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" "for.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
|
#lang basic-demo-2
|
||||||
10 for a = 1 to 3
|
10 for a = 1 to 3
|
||||||
20 print a
|
21 for b = 9 to 7 step -1
|
||||||
21 for b = 103 to 101 step -1
|
22 print a ; b
|
||||||
22 print b
|
|
||||||
23 next b
|
23 next b
|
||||||
30 next a
|
30 next a
|
||||||
40 print "yay"
|
|
Loading…
Reference in New Issue