[honu] don't stop parsing the current expression after invoking a macro.
add a file to help test honu.
This commit is contained in:
parent
dc1a97cec7
commit
60aabdc8c5
|
@ -19,6 +19,7 @@
|
|||
[honu-^ ^]
|
||||
[honu-> >] [honu-< <]
|
||||
[honu->= >=] [honu-<= <=]
|
||||
[honu-= =]
|
||||
[honu-flow \|]
|
||||
[honu-dot |.|]
|
||||
[honu-cons ::]
|
||||
|
@ -28,7 +29,6 @@
|
|||
[honu-structure structure]
|
||||
[honu-structure struct]
|
||||
[literal:colon :]
|
||||
[literal:honu-= =]
|
||||
[literal:semicolon |;|]
|
||||
[literal:honu-comma |,|]
|
||||
[literal:#%brackets #%brackets]
|
||||
|
|
|
@ -456,7 +456,7 @@ Then, in the pattern above for 'if', 'then' would be bound to the following synt
|
|||
[(_) #'(void)]
|
||||
[(_ forms ...)
|
||||
(define expanded (honu-expand #'(forms ...)))
|
||||
(debug "expanded ~a\n" expanded)
|
||||
(debug "expanded ~a\n" (syntax->datum expanded))
|
||||
expanded]))
|
||||
|
||||
(define-syntax (#%dynamic-honu-module-begin stx)
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
(define-honu-syntax honu-var
|
||||
(lambda (code context)
|
||||
(syntax-parse code #:literal-sets (cruft)
|
||||
#:literals (honu-=)
|
||||
[(_ name:id honu-= . rest)
|
||||
;; parse one expression
|
||||
(define-values (parsed unparsed)
|
||||
|
@ -46,6 +47,7 @@
|
|||
(define-honu-syntax honu-for
|
||||
(lambda (code context)
|
||||
(syntax-parse code #:literal-sets (cruft)
|
||||
#:literals (honu-=)
|
||||
[(_ iterator:id honu-= start:honu-expression honu-to end:honu-expression
|
||||
honu-do body:honu-expression . rest)
|
||||
(values
|
||||
|
@ -131,6 +133,7 @@
|
|||
(define-binary-operator honu-<= 0.9 'left <=)
|
||||
(define-binary-operator honu-> 0.9 'left >)
|
||||
(define-binary-operator honu->= 0.9 'left >=)
|
||||
(define-binary-operator honu-= 0.9 'left =)
|
||||
(define-binary-operator honu-and 0.5 'left and)
|
||||
(define-binary-operator honu-or 0.5 'left or)
|
||||
(define-binary-operator honu-cons 0.1 'right cons)
|
||||
|
|
|
@ -26,4 +26,4 @@
|
|||
honu-for-syntax
|
||||
honu-for-template)
|
||||
|
||||
(define-literal-set cruft (#%parens #%brackets #%braces semicolon colon honu-= honu-comma))
|
||||
(define-literal-set cruft (#%parens #%brackets #%braces semicolon colon honu-comma))
|
||||
|
|
|
@ -177,11 +177,10 @@
|
|||
(values (left #'parsed)
|
||||
#'rest)
|
||||
(do-parse #'rest precedence
|
||||
(lambda (x) x)
|
||||
left
|
||||
;; (lambda (x) x)
|
||||
#'parsed
|
||||
#;
|
||||
(lambda (x)
|
||||
(with-syntax ([x x])
|
||||
#'(begin parsed x)))
|
||||
(left #'parsed)))
|
||||
#;
|
||||
#'(splicing-let-syntax ([more-parsing (lambda (stx)
|
||||
|
@ -199,7 +198,7 @@
|
|||
(case association
|
||||
[(left) >]
|
||||
[(right) >=]))
|
||||
(debug "new precedence ~a\n" new-precedence)
|
||||
(debug "precedence old ~a new ~a higher? ~a\n" precedence new-precedence (higher new-precedence precedence))
|
||||
(if (higher new-precedence precedence)
|
||||
(do-parse #'(rest ...) new-precedence
|
||||
(lambda (stuff)
|
||||
|
|
85
collects/honu/core/private/test.rkt
Normal file
85
collects/honu/core/private/test.rkt
Normal file
|
@ -0,0 +1,85 @@
|
|||
#lang at-exp racket
|
||||
|
||||
(define (write-to-file input)
|
||||
(define file (make-temporary-file))
|
||||
(with-output-to-file file
|
||||
#:mode 'text
|
||||
#:exists 'truncate
|
||||
(lambda () (printf input)))
|
||||
file)
|
||||
|
||||
(define (execute-racket file)
|
||||
(match-define [list output input id error-port status]
|
||||
(process (format "racket ~a" file)))
|
||||
(status 'wait)
|
||||
(when (not (= 0 (status 'exit-code)))
|
||||
(printf "Error: ~a\n" (read-string 1024 error-port))
|
||||
(error 'run "couldn't run racket. error code ~a" (status 'exit-code)))
|
||||
(define result (read-string 4096 output))
|
||||
(close-input-port output)
|
||||
(close-input-port error-port)
|
||||
(close-output-port input)
|
||||
(delete-file file)
|
||||
result)
|
||||
|
||||
(define (run-honu input)
|
||||
(define file (write-to-file input))
|
||||
(with-handlers ([exn? (lambda (e)
|
||||
(when (file-exists? file)
|
||||
(delete-file file))
|
||||
(raise e))])
|
||||
(execute-racket file)))
|
||||
|
||||
(define (same? actual expected)
|
||||
;; (printf "Expected \n'~a'\n\ngot \n'~a'\n\n" expected actual)
|
||||
(string=? actual expected))
|
||||
|
||||
(define (output . stuff)
|
||||
;; (printf "output '~a'\n" stuff)
|
||||
(apply string-append "" (append stuff (list "\n"))))
|
||||
|
||||
(define (test input output)
|
||||
(same? (run-honu input) output))
|
||||
|
||||
(define (input . stuff)
|
||||
(apply string-append "#lang honu\n" stuff))
|
||||
|
||||
(test
|
||||
@input{
|
||||
5
|
||||
6
|
||||
}
|
||||
|
||||
@output{5
|
||||
6
|
||||
})
|
||||
|
||||
(test
|
||||
@input{
|
||||
1 + 1
|
||||
}
|
||||
|
||||
@output{2
|
||||
})
|
||||
|
||||
(test
|
||||
@input{
|
||||
foo(x){
|
||||
x * 2
|
||||
}
|
||||
foo(5);
|
||||
}
|
||||
|
||||
@output{10
|
||||
})
|
||||
|
||||
(test
|
||||
@input{
|
||||
var n = 5;
|
||||
cond
|
||||
n < 10: 'x1,
|
||||
n > 10: 'x2;
|
||||
}
|
||||
|
||||
@output{'x1
|
||||
})
|
|
@ -24,7 +24,7 @@
|
|||
(define-lex-abbrev digit (:/ #\0 #\9))
|
||||
(define-lex-abbrev identifier-first-character (:or (:/ #\a #\z)
|
||||
(:/ #\A #\Z)
|
||||
":" "_"))
|
||||
"_" "?"))
|
||||
(define-lex-abbrev identifier-character (:or identifier-first-character
|
||||
digit))
|
||||
(define-lex-abbrev identifier (:: identifier-first-character
|
||||
|
@ -34,7 +34,7 @@
|
|||
(:~ #\")))
|
||||
(define-lex-abbrev string (:: #\" (:* string-character) #\"))
|
||||
(define-lex-abbrev operator (:or "+" "=" "*" "/" "-" "^" "||" "|" "&&" "<="
|
||||
">=" "<" ">" "!"))
|
||||
">=" "<" ">" "!" "::"))
|
||||
(define-lex-abbrev block-comment (:: "/*"
|
||||
(complement (:: any-string "*/" any-string))
|
||||
"*/"))
|
||||
|
@ -67,7 +67,7 @@
|
|||
["/*" (token-block-comment)]
|
||||
["." (token-identifier '|.|)]
|
||||
["," (token-identifier '|,|)]
|
||||
["!" (token-identifier '!)]
|
||||
[":" (token-identifier ':)]
|
||||
["'" (token-identifier 'quote)]
|
||||
["`" (token-identifier 'quasiquote)]
|
||||
;; ["=" (token-identifier '=)]
|
||||
|
|
|
@ -17,5 +17,7 @@
|
|||
;;"private/common.honu"
|
||||
)
|
||||
|
||||
(provide sqr sqrt sin max
|
||||
(provide sqr sqrt sin max else
|
||||
number? symbol?
|
||||
null
|
||||
(rename-out [honu-cond cond]))
|
||||
|
|
|
@ -19,4 +19,4 @@
|
|||
#'(cond
|
||||
[clause.result body.result] ...)
|
||||
#'rest
|
||||
#f)])))
|
||||
#t)])))
|
||||
|
|
Loading…
Reference in New Issue
Block a user