Skip to content

Commit

Permalink
Implements PsiFunctionCallParams in ReasonML
Browse files Browse the repository at this point in the history
  • Loading branch information
giraud committed Sep 21, 2018
1 parent f7c090d commit 2e8dd80
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/reason/lang/ParserScopeEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,5 @@ public enum ParserScopeEnum {
executable,
maybeLetFunction,
maybeLetFunctionParameters,
valNamedSymbol, struct, matchException, beginScope, ifElseStatement, bracketGt, moduleDeclaration, moduleInstanciation, tryWith, moduleNamedColonWith, moduleNamedWithType, doLoop, tryWithScope, letBinding, scope, moduleNamedSignatureEq, array, signature, objectScope, clazzDeclaration, clazz, clazzNamed, clazzNamedEq, clazzBody, clazzBodyScope, clazzConstructor, clazzField, clazzFieldNamed, clazzMethod, clazzMethodNamed, clazzNamedParameters, clazzNamedConstructor, record, mixin, name
valNamedSymbol, struct, matchException, beginScope, ifElseStatement, bracketGt, moduleDeclaration, moduleInstanciation, tryWith, moduleNamedColonWith, moduleNamedWithType, doLoop, tryWithScope, letBinding, scope, moduleNamedSignatureEq, array, signature, objectScope, clazzDeclaration, clazz, clazzNamed, clazzNamedEq, clazzBody, clazzBodyScope, clazzConstructor, clazzField, clazzFieldNamed, clazzMethod, clazzMethodNamed, clazzNamedParameters, clazzNamedConstructor, record, mixin, functionCallParams, name
}
2 changes: 2 additions & 0 deletions src/main/java/com/reason/lang/PsiElementFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public static PsiElement createElement(MlTypes types, ASTNode node) {
return new PsiLetBinding(node);
} else if (type == types.FUN_PARAMS) {
return new PsiParametersImpl(types, node);
} else if (type == types.FUN_CALL_PARAMS) {
return new PsiFunctionCallParams(node);
} else if (type == types.MACRO_NAME) {
return new PsiMacroName(node);
} else if (type == types.SCOPED_EXPR) {
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/com/reason/lang/core/psi/PsiFunctionCallParams.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.reason.lang.core.psi;

import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.intellij.lang.ASTNode;

public class PsiFunctionCallParams extends ASTWrapperPsiElement {

public PsiFunctionCallParams(ASTNode node) {
super(node);
}

@Override
public boolean canNavigate() {
return false;
}

@Override
public String toString() {
return "function call params";
}
}
3 changes: 2 additions & 1 deletion src/main/java/com/reason/lang/core/psi/type/MlTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public abstract class MlTypes {
public IElementType GENERIC_EXPR;
public IElementType MACRO_EXPR;
public IElementType MACRO_NAME;
public IElementType MIXIN_FIELD;
public IElementType MODULE_PATH;
public IElementType ASSERT_STMT;
public IElementType SCOPED_EXPR;
Expand All @@ -39,6 +40,7 @@ public abstract class MlTypes {
public IElementType FUN_EXPR;
public IElementType FUN_PARAMS;
public IElementType FUN_BODY;
public IElementType FUN_CALL_PARAMS;
public IElementType RECORD_EXPR;
public IElementType RECORD_FIELD;
public IElementType SWITCH_EXPR;
Expand Down Expand Up @@ -89,7 +91,6 @@ public abstract class MlTypes {
public MlTokenElementType INITIALIZER;
public MlTokenElementType LAZY;
public MlTokenElementType LET;
public MlTokenElementType MIXIN_FIELD;
public MlTokenElementType MODULE;
public MlTokenElementType MUTABLE;
public MlTokenElementType NEW;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/reason/lang/ocaml/OclTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ private OclTypes() {
FUN_EXPR = new MlCompositeElementType("FUN_EXPR", OclLanguage.INSTANCE);
FUN_PARAMS = new MlCompositeElementType("FUN_PARAMS", OclLanguage.INSTANCE);
FUN_BODY = new MlCompositeElementType("FUN_BODY", OclLanguage.INSTANCE);
FUN_CALL_PARAMS = new MlCompositeElementType("FUN_CALL_PARAMS", OclLanguage.INSTANCE);
IF_STMT = new MlCompositeElementType("IF_STMT", OclLanguage.INSTANCE);
LET_BINDING = new MlCompositeElementType("LET_BINDING", OclLanguage.INSTANCE);
TYPE_CONSTR_NAME = new MlCompositeElementType("TYPE_CONSTR_NAME", OclLanguage.INSTANCE);
Expand All @@ -56,6 +57,7 @@ private OclTypes() {
UPPER_SYMBOL = new MlCompositeElementType("UPPER_SYMBOL", OclLanguage.INSTANCE);
LOWER_SYMBOL = new MlCompositeElementType("LOWER_SYMBOL", OclLanguage.INSTANCE);
STRUCT_EXPR = new MlCompositeElementType("STRUCT_EXPR", OclLanguage.INSTANCE);
MIXIN_FIELD = new MlCompositeElementType("MIXIN_FIELD", OclLanguage.INSTANCE);

// Token element types

Expand Down Expand Up @@ -126,7 +128,6 @@ private OclTypes() {
MATCH = new MlTokenElementType("MATCH", OclLanguage.INSTANCE);
MINUS = new MlTokenElementType("MINUS", OclLanguage.INSTANCE);
MINUSDOT = new MlTokenElementType("MINUSDOT", OclLanguage.INSTANCE);
MIXIN_FIELD = new MlTokenElementType("MIXIN_FIELD", OclLanguage.INSTANCE);
MODULE = new MlTokenElementType("MODULE", OclLanguage.INSTANCE);
MUTABLE = new MlTokenElementType("MUTABLE", OclLanguage.INSTANCE);
NONE = new MlTokenElementType("NONE", OclLanguage.INSTANCE);
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/reason/lang/reason/RmlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,11 @@ private void parseLParen(PsiBuilder builder, ParserState state) {
state.add(mark(builder, genericExpression, m_types.LPAREN));
}

state.add(markScope(builder, paren, m_types.SCOPED_EXPR, m_types.LPAREN));
if (state.previousTokenElementType == m_types.LIDENT) {
state.add(markScope(builder, paren, functionCallParams, m_types.FUN_CALL_PARAMS, m_types.LPAREN));
} else {
state.add(markScope(builder, paren, m_types.SCOPED_EXPR, m_types.LPAREN));
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/reason/lang/reason/RmlTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ private RmlTypes() {
EXCEPTION_EXPR = new MlCompositeElementType("EXCEPTION_EXPRESSION", RmlLanguage.INSTANCE);
INCLUDE_STMT = new MlCompositeElementType("INCLUDE_STMT", RmlLanguage.INSTANCE);
MACRO_NAME = new MlCompositeElementType("MACRO_NAME", RmlLanguage.INSTANCE);
MIXIN_FIELD = new MlCompositeElementType("MIXIN_FIELD", RmlLanguage.INSTANCE);
MODULE_STMT = new PsiModuleStubElementType("MODULE_STMT", RmlLanguage.INSTANCE);
MODULE_PATH = new MlCompositeElementType("MODULE_PATH", RmlLanguage.INSTANCE);
CLASS_STMT = new MlCompositeElementType("CLASS_STMT", RmlLanguage.INSTANCE);
Expand All @@ -34,6 +35,7 @@ private RmlTypes() {
FUN_EXPR = new MlCompositeElementType("FUN_EXPR", RmlLanguage.INSTANCE);
FUN_PARAMS = new MlCompositeElementType("FUN_PARAMS", RmlLanguage.INSTANCE);
FUN_BODY = new MlCompositeElementType("FUN_BODY", RmlLanguage.INSTANCE);
FUN_CALL_PARAMS = new MlCompositeElementType("FUN_CALL_PARAMS", RmlLanguage.INSTANCE);
LET_BINDING = new MlCompositeElementType("LET_BINDING", RmlLanguage.INSTANCE);
TYPE_CONSTR_NAME = new MlCompositeElementType("TYPE_CONSTR_NAME", RmlLanguage.INSTANCE);
TYPE_BINDING = new MlCompositeElementType("TYPE_BINDING", RmlLanguage.INSTANCE);
Expand Down Expand Up @@ -123,7 +125,6 @@ private RmlTypes() {
MATCH = new MlTokenElementType("MATCH", RmlLanguage.INSTANCE);
MINUS = new MlTokenElementType("MINUS", RmlLanguage.INSTANCE);
MINUSDOT = new MlTokenElementType("MINUSDOT", RmlLanguage.INSTANCE);
MIXIN_FIELD = new MlTokenElementType("MIXIN_FIELD", RmlLanguage.INSTANCE);
MODULE = new MlTokenElementType("MODULE", RmlLanguage.INSTANCE);
MUTABLE = new MlTokenElementType("MUTABLE", RmlLanguage.INSTANCE);
NONE = new MlTokenElementType("NONE", RmlLanguage.INSTANCE);
Expand Down
17 changes: 17 additions & 0 deletions tests/com/reason/lang/ocaml/FunctionCallTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.reason.lang.ocaml;

import com.reason.lang.BaseParsingTestCase;
import com.reason.lang.reason.RmlParserDefinition;

public class FunctionCallTest extends BaseParsingTestCase {
public FunctionCallTest() {
super("", "re", new RmlParserDefinition());
}

public void testCall() {
//PsiLet e = first(letExpressions(parseCode("let t = string_of_int 1")));
//
//assertNotNull(first(PsiTreeUtil.findChildrenOfType(e, PsiFunctionCallParams.class)));
}

}
19 changes: 19 additions & 0 deletions tests/com/reason/lang/reason/FunctionCallTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.reason.lang.reason;

import com.intellij.psi.util.PsiTreeUtil;
import com.reason.lang.BaseParsingTestCase;
import com.reason.lang.core.psi.PsiFunctionCallParams;
import com.reason.lang.core.psi.PsiLet;

public class FunctionCallTest extends BaseParsingTestCase {
public FunctionCallTest() {
super("", "re", new RmlParserDefinition());
}

public void testCall() {
PsiLet e = first(letExpressions(parseCode("let t = string_of_int(1);")));

assertNotNull(first(PsiTreeUtil.findChildrenOfType(e, PsiFunctionCallParams.class)));
}

}

0 comments on commit 2e8dd80

Please sign in to comment.