diff --git a/kaitai/expr.rkt b/kaitai/expr.rkt index 67a05a3..eceb5be 100644 --- a/kaitai/expr.rkt +++ b/kaitai/expr.rkt @@ -6,8 +6,8 @@ parser-tools/yacc) (define-tokens kaitai-expr [boolean number string identifier]) -(define-empty-tokens kaitai-sym [eof + - * / % < <= > >= == != << >> & pipe ^ not and or ? : - lparen rparen lbracket comma dot rbracket]) +(define-empty-tokens kaitai-sym [eof + - * / % < <= > >= == != << >> & pipe ^ not and or ? : ~ + lparen rparen lbracket comma dot rbracket]) (define (kaitai-numstr->number str) (match (regexp-replace* #px"_" str "") @@ -52,6 +52,7 @@ ["&" (token-&)] ["|" (token-pipe)] ["^" (token-^)] + ["~" (token-~)] ["not" (token-not)] ["and" (token-and)] ["or" (token-or)] @@ -81,7 +82,7 @@ (left & pipe ^) (left < <= > >= != ==) (left << >>) - (left + -) + (left + - ~) (left * / %) (right not) (left dot lparen rparen lbracket rbracket)] @@ -112,6 +113,9 @@ [(exp and exp) (list 'and $1 $3)] [(exp or exp) (list 'or $1 $3)] [(not exp) (list 'not $2)] + [(+ exp) (list '+ $2)] + [(- exp) (list '- $2)] + [(~ exp) (list '~ $2)] [(exp ? exp : exp) (list 'if $1 $3 $5)] [(lparen exp rparen) $2]) (apply-args @@ -119,7 +123,7 @@ [(exp comma apply-args) (cons $1 $3)]) ])) -(define test2 "true and 'a' != 'b' ? 1 : ('hello' + 'world').substring(2, 3)") +(define test2 "true and 'a' != 'b' ? -1 + ~bits : ('hello' + 'world').substring(2, 3)") (let ([input (open-input-string test2)]) (kaitai-parser (lambda () (kaitai-lexer input))))