edits
parent
f21e0f7c20
commit
28bc51a793
@ -0,0 +1,13 @@
|
|||||||
|
#lang brag
|
||||||
|
|
||||||
|
program : load-expr output-file-expr compare-to-expr output-list-expr test-expr*
|
||||||
|
load-expr : /"load" ID /","
|
||||||
|
output-file-expr : /"output-file" ID /","
|
||||||
|
compare-to-expr : /"compare-to" ID /","
|
||||||
|
output-list-expr : /"output-list" column+ /";"
|
||||||
|
/column : ID FORMAT-STRING
|
||||||
|
@test-expr : step-expr+ /";"
|
||||||
|
@step-expr : (set-expr | eval-expr | output-expr) [/","]
|
||||||
|
set-expr : /"set" ID VAL
|
||||||
|
eval-expr : /"eval"
|
||||||
|
output-expr : /"output"
|
@ -1,14 +1,22 @@
|
|||||||
#lang br
|
#lang br
|
||||||
|
(require "grammar.rkt" brag/support)
|
||||||
|
|
||||||
(module reader br
|
(module+ reader
|
||||||
(require "parser.rkt" "tokenizer.rkt")
|
(provide read-syntax))
|
||||||
(provide read-syntax)
|
|
||||||
(define (read-syntax source-path port)
|
(define tokenize
|
||||||
(define-values (line col pos) (port-next-location port))
|
(lexer-srcloc
|
||||||
(define port+newline (input-port-append #f port (open-input-string "\n")))
|
[(:or (from/to "/*" "*/")
|
||||||
(port-count-lines! port+newline)
|
(from/to "//" #\newline)) (token 'COMMENT lexeme #:skip? #t)]
|
||||||
(set-port-next-location! port+newline line col pos)
|
[whitespace (token lexeme #:skip? #t)]
|
||||||
|
[(:or "load" "output-list" "output-file" "compare-to" "set" "eval" "output" "," ";") lexeme]
|
||||||
|
[(:seq "%" (:+ alphabetic numeric ".")) (token 'FORMAT-STRING lexeme)]
|
||||||
|
[(:+ numeric) (token 'VAL (string->number lexeme))]
|
||||||
|
[(:+ alphabetic numeric "-" ".") (token 'ID lexeme)]))
|
||||||
|
|
||||||
|
(define (read-syntax src ip)
|
||||||
|
(port-count-lines! ip)
|
||||||
(strip-context
|
(strip-context
|
||||||
(with-syntax ([PT (parse source-path (make-tokenizer port+newline))])
|
(with-syntax ([PT (parse src (λ () (tokenize ip)))])
|
||||||
#'(module hdl-mod hdl-tst-demo/expander
|
#'(module hdl-mod hdl-tst-demo/expander
|
||||||
PT)))))
|
PT))))
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
#lang brag
|
|
||||||
|
|
||||||
tst-program : tst-load-expr tst-output-file-expr tst-compare-to-expr tst-output-list-expr /";" tst-test-expr*
|
|
||||||
tst-load-expr : /"load" ID /","
|
|
||||||
tst-output-file-expr : /"output-file" ID /","
|
|
||||||
tst-compare-to-expr : /"compare-to" ID /","
|
|
||||||
tst-output-list-expr : /"output-list" tst-column [tst-column]+
|
|
||||||
/tst-column : ID FORMAT-STRING
|
|
||||||
@tst-test-expr : tst-step-expr+ /";"
|
|
||||||
@tst-step-expr : (tst-set-expr | tst-eval-expr | tst-output-expr) [/","]
|
|
||||||
tst-set-expr : /"set" ID VAL
|
|
||||||
tst-eval-expr : /"eval"
|
|
||||||
tst-output-expr : /"output"
|
|
@ -1,17 +0,0 @@
|
|||||||
#lang br/quicklang
|
|
||||||
(require brag/support)
|
|
||||||
(provide make-tokenizer)
|
|
||||||
|
|
||||||
(define hdl-test-lexer
|
|
||||||
(lexer-srcloc
|
|
||||||
[(:or (from/to "/*" "*/")
|
|
||||||
(from/to "//" #\newline)) (token 'COMMENT lexeme #:skip? #t)]
|
|
||||||
[whitespace (token lexeme #:skip? #t)]
|
|
||||||
[(:or "load" "output-list" "output-file" "compare-to" "set" "eval" "output" "," ";") lexeme]
|
|
||||||
[(:seq "%" (:+ alphabetic numeric ".")) (token 'FORMAT-STRING lexeme)]
|
|
||||||
[(:+ numeric) (token 'VAL (string->number lexeme))]
|
|
||||||
[(:+ alphabetic numeric "-" ".") (token 'ID lexeme)]))
|
|
||||||
|
|
||||||
(define (make-tokenizer ip)
|
|
||||||
(define (next-token) (hdl-test-lexer ip))
|
|
||||||
next-token)
|
|
Loading…
Reference in New Issue