Skip to content

Commit

Permalink
Change the recovery rule for 'new' to use expression_recovery.
Browse files Browse the repository at this point in the history
Fixes tivo/intellij-haxe #229
Added a unit test for the 'new' command.
  • Loading branch information
EBatTiVo committed May 16, 2015
1 parent af34f3b commit f877616
Show file tree
Hide file tree
Showing 5 changed files with 531 additions and 33 deletions.
32 changes: 1 addition & 31 deletions gen/com/intellij/plugins/haxe/lang/parser/HaxeParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3866,7 +3866,7 @@ public static boolean newExpression(PsiBuilder b, int l) {
r = r && report_error_(b, consumeToken(b, PLPAREN));
r = p && report_error_(b, newExpression_3(b, l + 1)) && r;
r = p && consumeToken(b, PRPAREN) && r;
exit_section_(b, l, m, NEW_EXPRESSION, r, p, new_recovery_parser_);
exit_section_(b, l, m, NEW_EXPRESSION, r, p, expression_recover_parser_);
return r || p;
}

Expand Down Expand Up @@ -3931,31 +3931,6 @@ private static boolean newExpressionOrCall_1(PsiBuilder b, int l) {
return true;
}

/* ********************************************************** */
// !(')' | '}' | ';' | '.' | ',')
static boolean new_recovery(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "new_recovery")) return false;
boolean r;
Marker m = enter_section_(b, l, _NOT_, null);
r = !new_recovery_0(b, l + 1);
exit_section_(b, l, m, null, r, false, null);
return r;
}

// ')' | '}' | ';' | '.' | ','
private static boolean new_recovery_0(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "new_recovery_0")) return false;
boolean r;
Marker m = enter_section_(b);
r = consumeToken(b, PRPAREN);
if (!r) r = consumeToken(b, PRCURLY);
if (!r) r = consumeToken(b, OSEMI);
if (!r) r = consumeToken(b, ODOT);
if (!r) r = consumeToken(b, OCOMMA);
exit_section_(b, m, null, r);
return r;
}

/* ********************************************************** */
// '@:nodebug'
public static boolean noDebugMeta(PsiBuilder b, int l) {
Expand Down Expand Up @@ -5964,11 +5939,6 @@ public boolean parse(PsiBuilder b, int l) {
return local_var_declaration_part_recover(b, l + 1);
}
};
final static Parser new_recovery_parser_ = new Parser() {
public boolean parse(PsiBuilder b, int l) {
return new_recovery(b, l + 1);
}
};
final static Parser object_literal_list_recover_parser_ = new Parser() {
public boolean parse(PsiBuilder b, int l) {
return object_literal_list_recover(b, l + 1);
Expand Down
3 changes: 1 addition & 2 deletions grammar/haxe.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,7 @@ superExpression ::= 'super'
{mixin="com.intellij.plugins.haxe.lang.psi.impl.HaxeReferenceImpl" implements="com.intellij.plugins.haxe.lang.psi.HaxeReference"}

newExpression ::= 'new' type '(' (expression (',' expression)*)? ')'
{pin=2 recoverWhile="new_recovery" mixin="com.intellij.plugins.haxe.lang.psi.impl.HaxeReferenceImpl" implements="com.intellij.plugins.haxe.lang.psi.HaxeReference"}
private new_recovery ::= !(')' | '}' | ';' | '.' | ',')
{pin=2 recoverWhile="expression_recover" mixin="com.intellij.plugins.haxe.lang.psi.impl.HaxeReferenceImpl" implements="com.intellij.plugins.haxe.lang.psi.HaxeReference"}

castExpression ::= 'cast' (('(' expression ',' functionTypeWrapper ')') | expression)
{mixin="com.intellij.plugins.haxe.lang.psi.impl.HaxeClassReferenceImpl" implements="com.intellij.plugins.haxe.lang.psi.HaxeReference"}
Expand Down
42 changes: 42 additions & 0 deletions testData/parsing/haxe/expressions/New.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* Tests parsing 'new' in a ternary expression */

package test_tivo_229;

class A {
public function new() {}
}

class B extends A {
public function new() { super(); }
}

class C extends B {
public function new( a:A ) { }
}

class test {
public function getA(want_a:Boolean):A {
var qqq = (want_a == true) ? new A() : new B();
return qqq;
}

public function getB(want_a:Boolean):A {
var qqq = null != new B() ? new A() : new B();
return qqq;
}

public function getC(want_a:Boolean):A {
var qqq = null != new B() ? want_a == true ? new A() : new B() : want_a == false ? new A() : new B();
return qqq;
}

public function compareNew() : Boolean {
return new A() == new B();
}

public function getChain() : C {
return new C( new C( new C( new A() )));
}

}

Loading

0 comments on commit f877616

Please sign in to comment.