parser: new class AUnaryopExpr to factorize unary operations
authorJean Privat <jean@pryen.org>
Thu, 23 Apr 2015 08:19:33 +0000 (15:19 +0700)
committerJean Privat <jean@pryen.org>
Thu, 23 Apr 2015 08:19:33 +0000 (15:19 +0700)
Signed-off-by: Jean Privat <jean@pryen.org>

src/parser/nit.sablecc3xx
src/parser/parser_nodes.nit

index a3f4e6f..abccc28 100644 (file)
@@ -915,8 +915,8 @@ expr        = {block} expr* kwend?
        | {starstar} expr [op]:starstar [expr2]:expr
        | {slash} expr [op]:slash [expr2]:expr
        | {percent} expr [op]:percent [expr2]:expr
-       | {uminus} minus expr 
-       | {uplus} plus expr
+       | {uminus} [op]:minus expr
+       | {uplus} [op]:plus expr
        | {new} kwnew type id? [args]:exprs
        | {attr} expr [id]:attrid 
        | {attr_assign} expr [id]:attrid assign [value]:expr 
index 219c396..b883ad4 100644 (file)
@@ -2041,20 +2041,28 @@ class APercentExpr
        redef fun operator do return "%"
 end
 
-# A unary minus expression. eg `-x`
-class AUminusExpr
+# A unary operation on a method
+class AUnaryopExpr
        super ASendExpr
 
-       # The `-` symbol
-       var n_minus: TMinus is writable, noinit
+       # The operator
+       var n_op: Token is writable, noinit
+
+       # The name of the operator (eg '+')
+       fun operator: String is abstract
+end
+
+# A unary minus expression. eg `-x`
+class AUminusExpr
+       super AUnaryopExpr
+       redef fun operator do return "-"
 end
 
 # A unary plus expression. eg `+x`
 class AUplusExpr
-       super ASendExpr
+       super AUnaryopExpr
+       redef fun operator do return "+"
 
-       # The `+` symbol
-       var n_plus: TPlus is writable, noinit
 end
 
 # An explicit instantiation. eg `new T`