[honu] add postfix keyword for unary definitions
This commit is contained in:
parent
afdd5c4393
commit
8210acc696
|
@ -76,6 +76,7 @@
|
|||
[honu-equal =]
|
||||
[honu-+= +=] [honu--= -=]
|
||||
[honu-*= *=] [honu-/= /=]
|
||||
[literal:postfix postfix]
|
||||
[literal:honu-prefix prefix]
|
||||
[literal:honu-then then]
|
||||
[literal:colon %colon]
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
"debug.rkt"
|
||||
"contexts.rkt"
|
||||
"util.rkt"
|
||||
"ops.rkt"
|
||||
;; "ops.rkt"
|
||||
"syntax.rkt"
|
||||
;; "parse.rkt"
|
||||
"parse2.rkt"
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
honu-in
|
||||
honu-in-lines
|
||||
honu-prefix
|
||||
postfix
|
||||
semicolon
|
||||
honu-comma
|
||||
define-literal)
|
||||
|
@ -156,10 +157,15 @@
|
|||
(provide define-make-honu-unary-operator)
|
||||
(define-honu-syntax define-make-honu-unary-operator
|
||||
(lambda (code)
|
||||
(syntax-parse code
|
||||
[(_ name:id level:honu-expression postfix?:honu-expression function:honu-expression . rest)
|
||||
(define out (racket-syntax
|
||||
(define-unary-operator name level.result postfix?.result function.result)))
|
||||
(syntax-parse code #:literals (postfix)
|
||||
[(_ name:id level:honu-expression
|
||||
(~optional (~and postfix postfix?)
|
||||
#:defaults ([postfix? #f]))
|
||||
function:honu-expression . rest)
|
||||
(define out
|
||||
(with-syntax ([postfix? (if (attribute postfix?) #t #f)])
|
||||
(racket-syntax
|
||||
(define-unary-operator name level.result postfix? function.result))))
|
||||
(values out #'rest #t)])))
|
||||
|
||||
;; equals can have a compile time property that allows it to do something like set!
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
honu-$
|
||||
;; FIXME: in-lines should probably not be here
|
||||
honu-in-lines
|
||||
postfix
|
||||
%racket)
|
||||
|
||||
(define-syntax-rule (define-literal+set set literal ...)
|
||||
|
|
|
@ -63,4 +63,26 @@
|
|||
}
|
||||
foo(5)
|
||||
}
|
||||
10))
|
||||
10)
|
||||
|
||||
(check-equal? @honu{
|
||||
unary_operator u1 4 function(x){ x * 2}
|
||||
u1 8
|
||||
}
|
||||
|
||||
(* 8 2))
|
||||
|
||||
(check-equal? @honu{
|
||||
unary_operator u1 4 function(x){ x * 2}
|
||||
2 + u1 8 * 3
|
||||
}
|
||||
|
||||
(+ 2 (* 3 (* 8 2))))
|
||||
|
||||
(check-equal? @honu{
|
||||
binary_operator b1 4 'left function(left, right){ left + right * 2}
|
||||
2 b1 4
|
||||
}
|
||||
|
||||
(+ 2 (* 2 4)))
|
||||
)
|
||||
|
|
|
@ -17,12 +17,12 @@ binary_operator b1 2 'left
|
|||
|
||||
3 b1 8
|
||||
|
||||
unary_operator u1 4 true function(x){ x - 2 }
|
||||
unary_operator u1 4 function(x){ x - 2 }
|
||||
|
||||
2 + u1 u1 5
|
||||
|
||||
unary_operator u2 5 true function(x){ x + 8 }
|
||||
unary_operator u3 5 true function(x){ x * 2 };
|
||||
unary_operator u2 5 postfix function(x){ x + 8 }
|
||||
unary_operator u3 5 postfix function(x){ x * 2 };
|
||||
|
||||
7 u3;
|
||||
u2 7 u3;
|
||||
|
|
Loading…
Reference in New Issue
Block a user