Skip to content

Commit

Permalink
Fix incorrect parsing of TParent type reification (+ reification tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
m0rkeulv committed Aug 31, 2024
1 parent e2e1d71 commit 1e9aa32
Show file tree
Hide file tree
Showing 11 changed files with 1,382 additions and 58 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/intellij/plugins/haxe/lang/parser/haxe.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -610,10 +610,10 @@ macroExpressionReification::= (embeddedMeta)* <<canBeReification>> (| macroArra
macroClassReification ::= 'macro' macroTopLevelDeclaration

// type Reification
private TPath ::= simpleQualifiedReferenceExpression
private TPath ::= type
private TFunction ::= arrowFunctionLiteral
private TAnonymous ::= anonymousTypeBody // TODO mlo: make a better expression
private TParent ::= type
private TParent ::= '(' type ')'
private TExtend ::= '{>' type ',' identifier ',' type '}' // TODO mlo: make a better expression
private TOptional ::= '?' type

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.intellij.plugins.haxe.lang.parser.reification;

import com.intellij.plugins.haxe.lang.parser.statements.StatementTestBase;
import org.junit.Test;

public class ReificationTest extends StatementTestBase {
public ReificationTest() {
super("reification");
}

@Test
public void testBasicExpressionReifications() throws Throwable {
doTest(true);
}
@Test
public void testBasicTypeReifications() throws Throwable {
doTest(true);
}
@Test
public void testReificationsInLoops() throws Throwable {
doTest(true);
}
@Test
public void testDeclarationReifications() throws Throwable {
doTest(true);
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package ;
package;
import haxe.macro.Expr;

class MacroTest {

macro public function macroArrayReification(inputArray:Expr) {
return ($a{ inputArray });
macro public function macroArrayReification(inputArray:Array<String>):ExprOf<Array<String>> {
return macro $a{ inputArray };
}

macro public function macroValueReification():Expr<Int> {
macro public function macroValueReification():ExprOf<Int> {
var value = 1;
return macro { $v{ value } };
}

static public function macroBlockReification(a:Array<Expr>) {
static public function macroBlockReification(a:Int) {
return macro $b{a};
}

Expand All @@ -24,7 +24,7 @@ class MacroTest {
return macro ($p{field});
}

static public function macroExpReification(e:Expr):Dynamic {
static public function macroExpReification(e:Expr):ExprOf<Void -> Dynamic> {
return macro (function() return $e);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,51 @@ Haxe File
TYPE
REFERENCE_EXPRESSION
IDENTIFIER
HaxePsiToken:ID('Expr')
HaxePsiToken:ID('Array')
TYPE_PARAM
HaxePsiToken:<('<')
TYPE_LIST
TYPE_LIST_PART
TYPE_OR_ANONYMOUS
TYPE
REFERENCE_EXPRESSION
IDENTIFIER
HaxePsiToken:ID('String')
HaxePsiToken:>('>')
HaxePsiToken:)(')')
TYPE_TAG
HaxePsiToken::(':')
TYPE_OR_ANONYMOUS
TYPE
REFERENCE_EXPRESSION
IDENTIFIER
HaxePsiToken:ID('ExprOf')
TYPE_PARAM
HaxePsiToken:<('<')
TYPE_LIST
TYPE_LIST_PART
TYPE_OR_ANONYMOUS
TYPE
REFERENCE_EXPRESSION
IDENTIFIER
HaxePsiToken:ID('Array')
TYPE_PARAM
HaxePsiToken:<('<')
TYPE_LIST
TYPE_LIST_PART
TYPE_OR_ANONYMOUS
TYPE
REFERENCE_EXPRESSION
IDENTIFIER
HaxePsiToken:ID('String')
HaxePsiToken:>('>')
HaxePsiToken:>('>')
BLOCK_STATEMENT
HaxePsiToken:{('{')
RETURN_STATEMENT
HaxePsiToken:return('return')
PARENTHESIZED_EXPRESSION
HaxePsiToken:(('(')
MACRO_STATEMENT
HaxePsiToken:macro('macro')
VALUE_EXPRESSION
MACRO_EXPRESSION_REIFICATION
MACRO_ARRAY_REIFICATION
Expand All @@ -62,8 +99,7 @@ Haxe File
IDENTIFIER
HaxePsiToken:ID('inputArray')
HaxePsiToken:}('}')
HaxePsiToken:)(')')
HaxePsiToken:;(';')
HaxePsiToken:;(';')
HaxePsiToken:}('}')
METHOD_DECLARATION
METHOD_MODIFIER
Expand All @@ -84,7 +120,7 @@ Haxe File
TYPE
REFERENCE_EXPRESSION
IDENTIFIER
HaxePsiToken:ID('Expr')
HaxePsiToken:ID('ExprOf')
TYPE_PARAM
HaxePsiToken:<('<')
TYPE_LIST
Expand Down Expand Up @@ -148,17 +184,7 @@ Haxe File
TYPE
REFERENCE_EXPRESSION
IDENTIFIER
HaxePsiToken:ID('Array')
TYPE_PARAM
HaxePsiToken:<('<')
TYPE_LIST
TYPE_LIST_PART
TYPE_OR_ANONYMOUS
TYPE
REFERENCE_EXPRESSION
IDENTIFIER
HaxePsiToken:ID('Expr')
HaxePsiToken:>('>')
HaxePsiToken:ID('Int')
HaxePsiToken:)(')')
BLOCK_STATEMENT
HaxePsiToken:{('{')
Expand Down Expand Up @@ -299,7 +325,26 @@ Haxe File
TYPE
REFERENCE_EXPRESSION
IDENTIFIER
HaxePsiToken:ID('Dynamic')
HaxePsiToken:ID('ExprOf')
TYPE_PARAM
HaxePsiToken:<('<')
TYPE_LIST
TYPE_LIST_PART
FUNCTION_TYPE
FUNCTION_ARGUMENT
TYPE_OR_ANONYMOUS
TYPE
REFERENCE_EXPRESSION
IDENTIFIER
HaxePsiToken:ID('Void')
HaxePsiToken:->('->')
FUNCTION_RETURN_TYPE
TYPE_OR_ANONYMOUS
TYPE
REFERENCE_EXPRESSION
IDENTIFIER
HaxePsiToken:ID('Dynamic')
HaxePsiToken:>('>')
BLOCK_STATEMENT
HaxePsiToken:{('{')
RETURN_STATEMENT
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package;

class MacroTest {

macro public function macroTypeReification() {

// ComplexType.TPath
var path:ComplexType = macro : haxe.ds.Map;

// ComplexType.TFunction
var func:ComplexType = macro : String -> Int -> Float;

// ComplexType.TAnonymous
var anon:ComplexType = macro : {
field:String
};

// ComplexType.TExtend
var extendedAnon:ComplexType = macro : {
> Type, field:Type
};

// ComplexType.TParent
var parent:ComplexType = macro : (Type);

// ComplexType.TOptional
var optional:ComplexType = macro : ?String;

}


}
Loading

0 comments on commit 1e9aa32

Please sign in to comment.