add optional val before functions and arguments
This commit is contained in:
parent
292512221e
commit
1b914ead61
|
@ -10,6 +10,7 @@
|
||||||
(rename-out [#%dynamic-honu-module-begin #%module-begin]
|
(rename-out [#%dynamic-honu-module-begin #%module-begin]
|
||||||
[honu-function function]
|
[honu-function function]
|
||||||
[honu-var var]
|
[honu-var var]
|
||||||
|
[honu-val val]
|
||||||
[honu-+ +]
|
[honu-+ +]
|
||||||
[honu-- -]
|
[honu-- -]
|
||||||
[honu-* *]
|
[honu-* *]
|
||||||
|
|
|
@ -448,19 +448,6 @@ Then, in the pattern above for 'if', 'then' would be bound to the following synt
|
||||||
(define-for-syntax (honu-compile forms)
|
(define-for-syntax (honu-compile forms)
|
||||||
#'(void))
|
#'(void))
|
||||||
|
|
||||||
(provide honu-var)
|
|
||||||
(honu:define-honu-syntax honu-var
|
|
||||||
(lambda (code context)
|
|
||||||
(syntax-parse code #:literal-sets (cruft)
|
|
||||||
[(_ name:id honu-= . rest)
|
|
||||||
(define-values (parsed unparsed)
|
|
||||||
(parse #'rest))
|
|
||||||
(values
|
|
||||||
(with-syntax ([parsed parsed])
|
|
||||||
#'(define name parsed))
|
|
||||||
(with-syntax ([unparsed unparsed])
|
|
||||||
#'unparsed)
|
|
||||||
#t)])))
|
|
||||||
|
|
||||||
(define-syntax (honu-unparsed-begin stx)
|
(define-syntax (honu-unparsed-begin stx)
|
||||||
(emit-remark "Honu unparsed begin!" stx)
|
(emit-remark "Honu unparsed begin!" stx)
|
||||||
|
|
|
@ -25,6 +25,30 @@
|
||||||
#'rest
|
#'rest
|
||||||
#f)])))
|
#f)])))
|
||||||
|
|
||||||
|
(provide honu-var)
|
||||||
|
(define-honu-syntax honu-var
|
||||||
|
(lambda (code context)
|
||||||
|
(syntax-parse code #:literal-sets (cruft)
|
||||||
|
[(_ name:id honu-= . rest)
|
||||||
|
;; parse one expression
|
||||||
|
(define-values (parsed unparsed)
|
||||||
|
(parse #'rest))
|
||||||
|
(values
|
||||||
|
(with-syntax ([parsed parsed])
|
||||||
|
#'(define name parsed))
|
||||||
|
(with-syntax ([unparsed unparsed])
|
||||||
|
#'unparsed)
|
||||||
|
#t)])))
|
||||||
|
|
||||||
|
(provide honu-val)
|
||||||
|
(define-honu-syntax honu-val
|
||||||
|
(lambda (code context)
|
||||||
|
(syntax-parse code
|
||||||
|
[(_ rest ...)
|
||||||
|
(define-values (parsed unparsed)
|
||||||
|
(parse #'(rest ...)))
|
||||||
|
(values parsed unparsed #t)])))
|
||||||
|
|
||||||
(define-syntax-rule (define-binary-operator name precedence operator)
|
(define-syntax-rule (define-binary-operator name precedence operator)
|
||||||
(begin
|
(begin
|
||||||
(provide name)
|
(provide name)
|
||||||
|
|
|
@ -70,6 +70,24 @@
|
||||||
(debug "Semicolon? ~a ~a\n" what is)
|
(debug "Semicolon? ~a ~a\n" what is)
|
||||||
is)
|
is)
|
||||||
|
|
||||||
|
(define-literal-set argument-stuff [honu-comma])
|
||||||
|
|
||||||
|
(define (parse-arguments arguments)
|
||||||
|
(define-syntax-class val
|
||||||
|
[pattern x:identifier #:when (equal? 'val (syntax-e #'x))])
|
||||||
|
(let loop ([out '()]
|
||||||
|
[arguments arguments])
|
||||||
|
(syntax-parse arguments #:literal-sets (argument-stuff)
|
||||||
|
[(x:val name:identifier honu-comma more ...)
|
||||||
|
(loop (cons #'name out) #'(more ...))]
|
||||||
|
[(name:identifier honu-comma more ...)
|
||||||
|
(loop (cons #'name out) #'(more ...))]
|
||||||
|
[(x:val name:identifier)
|
||||||
|
(loop (cons #'name out) #'())]
|
||||||
|
[(name:identifier)
|
||||||
|
(loop (cons #'name out) #'())]
|
||||||
|
[() (reverse out)])))
|
||||||
|
|
||||||
;; 1 + 1
|
;; 1 + 1
|
||||||
;; ^
|
;; ^
|
||||||
;; left: identity
|
;; left: identity
|
||||||
|
@ -162,10 +180,12 @@
|
||||||
[else
|
[else
|
||||||
(syntax-parse #'(head rest ...)
|
(syntax-parse #'(head rest ...)
|
||||||
[(function:identifier (#%parens args ...) (#%braces code ...) . rest)
|
[(function:identifier (#%parens args ...) (#%braces code ...) . rest)
|
||||||
(values #'(define (function args ...)
|
(values (with-syntax ([(parsed-arguments ...)
|
||||||
|
(parse-arguments #'(args ...))])
|
||||||
|
#'(define (function parsed-arguments ...)
|
||||||
(let-syntax ([parse-more (lambda (stx)
|
(let-syntax ([parse-more (lambda (stx)
|
||||||
(parse-all #'(code ...)))])
|
(parse-all #'(code ...)))])
|
||||||
(parse-more)))
|
(parse-more))))
|
||||||
#'rest)]
|
#'rest)]
|
||||||
[else (syntax-parse #'head
|
[else (syntax-parse #'head
|
||||||
#:literal-sets (cruft)
|
#:literal-sets (cruft)
|
||||||
|
|
|
@ -26,11 +26,11 @@ test1(){
|
||||||
print(x ^ 2)
|
print(x ^ 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
test2(x){
|
val test2(val x){
|
||||||
print(x)
|
print(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
// test1();
|
// test1();
|
||||||
// test2(5);
|
test2(5);
|
||||||
|
|
||||||
function(z){ print(z) }(12)
|
function(z){ print(z) }(12)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user