parse multiple call arguments
This commit is contained in:
parent
10e79ba2ec
commit
d4ea3b5d79
|
@ -70,6 +70,13 @@
|
||||||
(debug "Semicolon? ~a ~a\n" what is)
|
(debug "Semicolon? ~a ~a\n" what is)
|
||||||
is)
|
is)
|
||||||
|
|
||||||
|
(define (comma? what)
|
||||||
|
(define-literal-set check (honu-comma))
|
||||||
|
(define is (and (identifier? what)
|
||||||
|
((literal-set->predicate check) what)))
|
||||||
|
(debug "Comma? ~a ~a\n" what is)
|
||||||
|
is)
|
||||||
|
|
||||||
(define-literal-set argument-stuff [honu-comma])
|
(define-literal-set argument-stuff [honu-comma])
|
||||||
|
|
||||||
(define (parse-arguments arguments)
|
(define (parse-arguments arguments)
|
||||||
|
@ -88,6 +95,18 @@
|
||||||
(loop (cons #'name out) #'())]
|
(loop (cons #'name out) #'())]
|
||||||
[() (reverse out)])))
|
[() (reverse out)])))
|
||||||
|
|
||||||
|
(define (parse-call-arguments arguments)
|
||||||
|
(if (null? (syntax->list arguments))
|
||||||
|
'()
|
||||||
|
(let loop ([used '()]
|
||||||
|
[rest arguments])
|
||||||
|
(if (empty-syntax? rest)
|
||||||
|
(reverse used)
|
||||||
|
(let-values ([(parsed unparsed)
|
||||||
|
(parse rest)])
|
||||||
|
(loop (cons parsed used)
|
||||||
|
unparsed))))))
|
||||||
|
|
||||||
;; 1 + 1
|
;; 1 + 1
|
||||||
;; ^
|
;; ^
|
||||||
;; left: identity
|
;; left: identity
|
||||||
|
@ -162,6 +181,9 @@
|
||||||
0
|
0
|
||||||
(lambda (x) x)
|
(lambda (x) x)
|
||||||
(left current)))]
|
(left current)))]
|
||||||
|
[(comma? #'head)
|
||||||
|
(values (left current)
|
||||||
|
#'(rest ...))]
|
||||||
[(semicolon? #'head)
|
[(semicolon? #'head)
|
||||||
(values (left current)
|
(values (left current)
|
||||||
#'(rest ...))
|
#'(rest ...))
|
||||||
|
@ -195,9 +217,7 @@
|
||||||
(debug "function call ~a\n" left)
|
(debug "function call ~a\n" left)
|
||||||
(values (left (with-syntax ([current current]
|
(values (left (with-syntax ([current current]
|
||||||
[(parsed-args ...)
|
[(parsed-args ...)
|
||||||
(if (null? (syntax->list #'(args ...)))
|
(parse-call-arguments #'(args ...)) ])
|
||||||
'()
|
|
||||||
(list (parse-all #'(args ...))))])
|
|
||||||
#'(current parsed-args ...)))
|
#'(current parsed-args ...)))
|
||||||
#'(rest ...))
|
#'(rest ...))
|
||||||
#;
|
#;
|
||||||
|
|
|
@ -26,11 +26,12 @@ test1(){
|
||||||
print(x ^ 2)
|
print(x ^ 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
val test2(val x){
|
val test2(val x, val y){
|
||||||
print(x)
|
print(x);
|
||||||
|
print(y)
|
||||||
}
|
}
|
||||||
|
|
||||||
// test1();
|
// test1();
|
||||||
test2(5);
|
test2(5, 9);
|
||||||
|
|
||||||
function(z){ print(z) }(12)
|
// function(z){ print(z) }(12)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user