From ed485c71c9cac1855e6f48febd286b141242e980 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Thu, 23 Apr 2015 15:19:33 +0700 Subject: [PATCH] parser: new class AUnaryopExpr to factorize unary operations Signed-off-by: Jean Privat --- src/parser/nit.sablecc3xx | 4 ++-- src/parser/parser_nodes.nit | 22 +++++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/parser/nit.sablecc3xx b/src/parser/nit.sablecc3xx index a3f4e6f..abccc28 100644 --- a/src/parser/nit.sablecc3xx +++ b/src/parser/nit.sablecc3xx @@ -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 diff --git a/src/parser/parser_nodes.nit b/src/parser/parser_nodes.nit index 219c396..b883ad4 100644 --- a/src/parser/parser_nodes.nit +++ b/src/parser/parser_nodes.nit @@ -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` -- 1.7.9.5