From 62255eb7699bf7afb91f6b732307bb5cc8592601 Mon Sep 17 00:00:00 2001 From: Alexandros Naskos Date: Sun, 29 Apr 2012 11:35:16 +0300 Subject: [PATCH 1/2] Added => operator with no conflict to case :D --- grammar/nagaqueen.leg | 19 +++++++++++++++++-- source/nagaqueen/OocListener.ooc | 2 +- source/nagaqueen/callbacks.ooc | 2 ++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/grammar/nagaqueen.leg b/grammar/nagaqueen.leg index 8bc8755..0ccbb4c 100644 --- a/grammar/nagaqueen.leg +++ b/grammar/nagaqueen.leg @@ -287,6 +287,7 @@ void *nq_onFloatLiteral(void *this, char *value); void *nq_onBoolLiteral(void *this, bool value); void *nq_onNull(void *this); +void *nq_onDoubleArrow(void *this, coid *left, void *right); void *nq_onTernary(void *this, void *condition, void *ifTrue, void *ifFalse); void *nq_onAssignAnd(void *this, void *left, void *right); void *nq_onAssignOr(void *this, void *left, void *right); @@ -508,7 +509,7 @@ GenericArguments = OperatorDecl = OPERATOR_KW { tokenPos; } - - - < ( "<=>"| ">>="| "<<="| ">>" | "<<" + - < ( "=>" | "<=>"| ">>="| "<<="| ">>" | "<<" | ">=" | "<=" | "!=" | "==" | ">" | "<" | "!" | "+=" | "-=" | "*=" | "**="| "/=" | "+" | "-" | "**" | "/" | "*" | "=" | "[]="| "[]" | "&&" | "||" | "%" | "as" | "implicit as" @@ -1096,7 +1097,7 @@ Else = ( ) { $$=nq_onElseEnd(core->this); } Case = CASE_KW { tokenPos; nq_onCaseStart(core->this); } - (- v:Expr { nq_onCaseExpr(core->this, v); })? + (- v:CaseExpr { nq_onCaseExpr(core->this, v); })? WS DOUBLE_ARROW (WS (s:Stmt { nq_onStatement(core->this, s) }) @@ -1158,9 +1159,23 @@ Return = (RETURN_KW &([^A-Za-z_]) { tokenPos; } - e:Expr { $$=nq_onReturn(core- Expr = v:VariableDecl - + | d:DoubleArrow - | b:BinaryOperation - (- '.' { tokenPos; } WS call:FunctionCall { $$=b=nq_onFunctionCallChain(core->this, b, call); })* | AnonymousFunctionDecl +CaseExpr = ( v:VariableDecl - + | b:BinaryOperation - (- '.' { tokenPos; } WS call:FunctionCall { $$=b=nq_onFunctionCallChain(core->this, b, call); })* + | AnonymousFunctionDecl + ) + | + ( '(' - + Expr - + ')' + ) + +DoubleArrow = l:Assignment + DOUBLE_ARROW { tokenPos; } WS r:Expr ~{ missingOp("=>") } { $$=l=nq_onDoubleArrow(core->this, l, r); } + #operators BinaryOperation = Assignment diff --git a/source/nagaqueen/OocListener.ooc b/source/nagaqueen/OocListener.ooc index b29acfb..34c307e 100644 --- a/source/nagaqueen/OocListener.ooc +++ b/source/nagaqueen/OocListener.ooc @@ -667,7 +667,7 @@ UnOpType: enum { * Binary operators */ BinOpType: enum { - equals, notEquals, lessThan, moreThan, cmp, lessThanOrEqual, moreThanOrEqual + doubleArrow, equals, notEquals, lessThan, moreThan, cmp, lessThanOrEqual, moreThanOrEqual assAnd, assOr, assXor, assRShift, assLShift, assDiv, assMul, assExp, assSub, assAdd, ass diff --git a/source/nagaqueen/callbacks.ooc b/source/nagaqueen/callbacks.ooc index 7949f3d..ecafd6a 100644 --- a/source/nagaqueen/callbacks.ooc +++ b/source/nagaqueen/callbacks.ooc @@ -244,6 +244,8 @@ nq_onCatchEnd: unmangled func (l: OocListener) { l onCatchEnd() } /* Various operators */ +nq_onDoubleArrow: unmangled func (l: OocListener, left, right: Object) -> Object { l onBinOp(BinOpType doubleArrow, left, right) } + nq_onLogicalNot: unmangled func (l: OocListener, inner: Object) -> Object { l onUnOp(UnOpType not, inner) } nq_onBinaryNot: unmangled func (l: OocListener, inner: Object) -> Object { l onUnOp(UnOpType bNot, inner) } nq_onUnaryMinus: unmangled func (l: OocListener, inner: Object) -> Object { l onUnOp(UnOpType uMinus, inner) } From 3e7be7f4f2e05003e4b58bc870e17df3aa187fe1 Mon Sep 17 00:00:00 2001 From: Alexandros Naskos Date: Sun, 29 Apr 2012 11:52:10 +0300 Subject: [PATCH 2/2] Fixed typo. coid -> void --- grammar/nagaqueen.leg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grammar/nagaqueen.leg b/grammar/nagaqueen.leg index 0ccbb4c..0541885 100644 --- a/grammar/nagaqueen.leg +++ b/grammar/nagaqueen.leg @@ -287,7 +287,7 @@ void *nq_onFloatLiteral(void *this, char *value); void *nq_onBoolLiteral(void *this, bool value); void *nq_onNull(void *this); -void *nq_onDoubleArrow(void *this, coid *left, void *right); +void *nq_onDoubleArrow(void *this, void *left, void *right); void *nq_onTernary(void *this, void *condition, void *ifTrue, void *ifFalse); void *nq_onAssignAnd(void *this, void *left, void *right); void *nq_onAssignOr(void *this, void *left, void *right);