Skip to content

Commit

Permalink
Parser fix: prevent call expressions from consuming enum extractor ex…
Browse files Browse the repository at this point in the history
…pressions
  • Loading branch information
m0rkeulv committed Sep 1, 2024
1 parent 8672704 commit 50cc850
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/main/java/com/intellij/plugins/haxe/lang/parser/haxe.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,10 @@ callExpressionList ::= forStatement | whileStatement | spreadExpression | (expre
{recoverWhile="expression_list_recover" extends=expressionList methods= [spreadExpression="spreadExpression[0]"]}

expressionList ::= forStatement | whileStatement | (expression (',' expression)*) ','? {recoverWhile="expression_list_recover"}
private expression_list_recover ::= !(')' | ']' | fatArrowOperator) // fatArrowOperator("=>") is here to avoid problems where enum extractors are mis-parsed as callExpressions
//recoverycomments:
// fatArrowOperator("=>") is here to avoid problems where enum extractors are mis-parsed as callExpressions
// '(' is here to prevent call expressions from consuming enum extractor expressions
private expression_list_recover ::= !(')' | ']' |'('| fatArrowOperator)

private expression_recover ::= !('!' | '!=' | '%' | '%=' | '&&' | '&' | '&=' | '(' | ')' | '*' | '*=' | '+' | '++' | '+=' | ',' | '-' | '--' | '-=' | '.' | '...' | '/' | '/=' | ':' | ';' | '<' | '<<' | '<<=' | '<=' | '=' | '==' | '>' | <<shiftRight>> | <<unsignedShiftRight>> | <<gtEq>> | <<shiftRightAssign>> | <<unsignedShiftRightAssign>> | '?' | '[' | ']' | '^' | '^=' | 'break' | 'case' | 'cast' | 'catch' | 'continue' | 'default' | 'do' | 'dynamic' | 'else' | 'extern' | 'false' | 'final' | 'for' | 'function' | 'if' | 'inline' | 'new' | 'null' | 'override' | 'private' | 'public' | 'return' | 'static' | 'super' | 'switch' | 'this' | 'throw' | 'true' | 'try' | 'untyped' | 'var' | 'while' | 'in' |'{' | '|' | '|=' | '||' | '}' | '~' | ID | LITFLOAT | LITHEX | LITINT | LITOCT | OPEN_QUOTE | CLOSING_QUOTE | META_ID | REG_EXP | LONG_TEMPLATE_ENTRY_END | '=>'| '$') !metaKeyWord

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ class PatternMachingTest {
trace("4");
}
}
public function testSwitchEnumExtractor() {
var enumVar:TestExtraction<Float>;
switch (enumVar) {
case SingleParam(_):
trace("0");
case SingleGenericParam(_ => 1.0):
trace("1");
case ComplexValue(_, [_ => {value :SingleParam(v)}], i):
trace("2");
case ComplexValue(_, [ComplexValue(_.get("") => { kind: SingleParam(e) }, _)]):
trace("2");
}
}

public function testSwitchOnStructure() {
var person = { name: "Mark", age: 33, subElement: {id:"abc"} };
Expand All @@ -86,5 +99,10 @@ class PatternMachingTest {
trace("unknown");
}
}
}

enum TestExtraction<T> {
SingleParam(s:String);
SingleGenericParam(s:T);
ComplexValue(t:Map<String, String>, params:Array<{value:TestExtraction<Int>}>, i:Int);
}

0 comments on commit 50cc850

Please sign in to comment.