function == lambda. add new syntax for defining functions
This commit is contained in:
parent
530bb1b9ba
commit
292512221e
|
@ -14,16 +14,16 @@
|
|||
(define-honu-syntax honu-function
|
||||
(lambda (code context)
|
||||
(syntax-parse code #:literal-sets (cruft)
|
||||
[(_ name:identifier (#%parens arg:identifier ...)
|
||||
[(_ (#%parens arg:identifier ...)
|
||||
(#%braces code ...)
|
||||
. rest)
|
||||
(values
|
||||
#'(define (name arg ...)
|
||||
#'(lambda (arg ...)
|
||||
(let-syntax ([do-parse (lambda (stx)
|
||||
(parse-all #'(code ...)))])
|
||||
(do-parse)))
|
||||
#'rest
|
||||
#t)])))
|
||||
#f)])))
|
||||
|
||||
(define-syntax-rule (define-binary-operator name precedence operator)
|
||||
(begin
|
||||
|
|
|
@ -98,7 +98,7 @@
|
|||
(define (parse input)
|
||||
(define (do-parse stream precedence left current)
|
||||
(debug "parse ~a precedence ~a left ~a current ~a\n" stream precedence left current)
|
||||
(syntax-parse stream
|
||||
(syntax-parse stream #:literal-sets (cruft)
|
||||
[() (values (left current) #'())]
|
||||
[(head rest ...)
|
||||
(cond
|
||||
|
@ -159,37 +159,40 @@
|
|||
#'(splicing-let-syntax ([more (lambda (stx)
|
||||
(parse #'(rest ...)))])
|
||||
so-far (more)))]
|
||||
[(identifier? #'head)
|
||||
(do-parse #'(rest ...) precedence left #'head)]
|
||||
[else (syntax-parse #'head
|
||||
#:literal-sets (cruft)
|
||||
[x:number (do-parse #'(rest ...)
|
||||
precedence
|
||||
left #'x)]
|
||||
[(#%parens args ...)
|
||||
(debug "function call ~a\n" left)
|
||||
(values (left (with-syntax ([current current]
|
||||
[(parsed-args ...)
|
||||
(if (null? (syntax->list #'(args ...)))
|
||||
'()
|
||||
(list (parse-all #'(args ...))))])
|
||||
#'(current parsed-args ...)))
|
||||
#'(rest ...))
|
||||
#;
|
||||
(do-parse #'(rest ...)
|
||||
0
|
||||
(lambda (x) x)
|
||||
(left (with-syntax ([current current]
|
||||
[(parsed-args ...)
|
||||
(if (null? (syntax->list #'(args ...)))
|
||||
'()
|
||||
(list (parse #'(args ...))))])
|
||||
#'(current parsed-args ...))))
|
||||
#;
|
||||
(error 'parse "function call")]
|
||||
[else (error 'what "dont know ~a" #'head)])]
|
||||
|
||||
)]))
|
||||
[else
|
||||
(syntax-parse #'(head rest ...)
|
||||
[(function:identifier (#%parens args ...) (#%braces code ...) . rest)
|
||||
(values #'(define (function args ...)
|
||||
(let-syntax ([parse-more (lambda (stx)
|
||||
(parse-all #'(code ...)))])
|
||||
(parse-more)))
|
||||
#'rest)]
|
||||
[else (syntax-parse #'head
|
||||
#:literal-sets (cruft)
|
||||
[x:identifier (do-parse #'(rest ...) precedence left #'x)]
|
||||
[x:number (do-parse #'(rest ...) precedence left #'x)]
|
||||
[(#%parens args ...)
|
||||
(debug "function call ~a\n" left)
|
||||
(values (left (with-syntax ([current current]
|
||||
[(parsed-args ...)
|
||||
(if (null? (syntax->list #'(args ...)))
|
||||
'()
|
||||
(list (parse-all #'(args ...))))])
|
||||
#'(current parsed-args ...)))
|
||||
#'(rest ...))
|
||||
#;
|
||||
(do-parse #'(rest ...)
|
||||
0
|
||||
(lambda (x) x)
|
||||
(left (with-syntax ([current current]
|
||||
[(parsed-args ...)
|
||||
(if (null? (syntax->list #'(args ...)))
|
||||
'()
|
||||
(list (parse #'(args ...))))])
|
||||
#'(current parsed-args ...))))
|
||||
#;
|
||||
(error 'parse "function call")]
|
||||
[else (error 'what "dont know ~a" #'head)])])])]))
|
||||
|
||||
(do-parse input 0 (lambda (x) x) #'(void)))
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ function test(t, a, b){
|
|||
}
|
||||
*/
|
||||
|
||||
function test1(){
|
||||
test1(){
|
||||
var x = 3;
|
||||
/*
|
||||
const y = 2;
|
||||
|
@ -26,9 +26,11 @@ function test1(){
|
|||
print(x ^ 2)
|
||||
}
|
||||
|
||||
function test2(x){
|
||||
test2(x){
|
||||
print(x)
|
||||
}
|
||||
|
||||
test1();
|
||||
test2(5);
|
||||
// test1();
|
||||
// test2(5);
|
||||
|
||||
function(z){ print(z) }(12)
|
||||
|
|
Loading…
Reference in New Issue
Block a user