Skip to content

Commit

Permalink
#329 - disable mly parser to avoid exception
Browse files Browse the repository at this point in the history
  • Loading branch information
giraud committed Aug 26, 2021
1 parent 6c844d8 commit 83a5dc6
Show file tree
Hide file tree
Showing 29 changed files with 744 additions and 1,405 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ are solved.
## Unreleased

- :bug: ![o] [#340](https://github.com/reasonml-editor/reasonml-idea-plugin/issues/340) Items missing in structure panel after let ending with match (incorrect object parsing)
- :bug: ![o] [#329](https://github.com/reasonml-editor/reasonml-idea-plugin/issues/329) IllegalArgumentException: Not an OCaml node: Element(OCAML_LAZY_NODE)

## 0.102.1 - 2021/07/06

Expand Down
32 changes: 15 additions & 17 deletions src/com/reason/ide/files/MlyFile.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
package com.reason.ide.files;

import com.intellij.openapi.fileTypes.FileType;
import com.intellij.psi.FileViewProvider;
import com.reason.lang.ocamlyacc.OclYaccLanguage;
import org.jetbrains.annotations.NotNull;
import com.intellij.openapi.fileTypes.*;
import com.intellij.psi.*;
import com.reason.lang.ocamlyacc.*;
import org.jetbrains.annotations.*;

public class MlyFile extends FileBase {
public MlyFile(@NotNull FileViewProvider viewProvider) {
super(viewProvider, OclYaccLanguage.INSTANCE);
}
public MlyFile(@NotNull FileViewProvider viewProvider) {
super(viewProvider, OclYaccLanguage.INSTANCE);
}

@NotNull
@Override
public FileType getFileType() {
return MlyFileType.INSTANCE;
}
@Override
public @NotNull FileType getFileType() {
return MlyFileType.INSTANCE;
}

@NotNull
@Override
public String toString() {
return MlyFileType.INSTANCE.getDescription();
}
@Override
public @NotNull String toString() {
return MlyFileType.INSTANCE.getDescription();
}
}
65 changes: 30 additions & 35 deletions src/com/reason/ide/files/MlyFileType.java
Original file line number Diff line number Diff line change
@@ -1,41 +1,36 @@
package com.reason.ide.files;

import com.intellij.openapi.fileTypes.LanguageFileType;
import com.reason.lang.ocamlyacc.OclYaccLanguage;
import icons.ORIcons;
import com.intellij.openapi.fileTypes.*;
import com.reason.lang.ocamlyacc.*;
import icons.*;
import org.jetbrains.annotations.*;

import javax.swing.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class MlyFileType extends LanguageFileType {
public static final MlyFileType INSTANCE = new MlyFileType();
static final String EXTENSION = "mly";

private MlyFileType() {
super(OclYaccLanguage.INSTANCE);
}

@NotNull
@Override
public String getName() {
return "MlY";
}

@NotNull
@Override
public String getDescription() {
return "OCaml yacc parser";
}

@NotNull
@Override
public String getDefaultExtension() {
return EXTENSION;
}

@Nullable
@Override
public Icon getIcon() {
return ORIcons.OCL_GREEN_FILE;
}
public static final MlyFileType INSTANCE = new MlyFileType();

private MlyFileType() {
super(OclYaccLanguage.INSTANCE);
}

@Override
public @NotNull String getName() {
return "MlY";
}

@Override
public @NotNull String getDescription() {
return "OCaml yacc parser";
}

@Override
public @NotNull String getDefaultExtension() {
return "mly";
}

@Override
public @Nullable Icon getIcon() {
return ORIcons.OCL_GREEN_FILE;
}
}
90 changes: 39 additions & 51 deletions src/com/reason/ide/folding/ORFoldingBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,61 +21,54 @@
import java.util.*;

public class ORFoldingBuilder extends FoldingBuilderEx {
@NotNull
@Override
public FoldingDescriptor[] buildFoldRegions(
@NotNull PsiElement root, @NotNull Document document, boolean quick) {
public @NotNull FoldingDescriptor[] buildFoldRegions(@NotNull PsiElement root, @NotNull Document document, boolean quick) {
List<FoldingDescriptor> descriptors = new ArrayList<>();
ORTypes types = ORUtil.getTypes(root.getLanguage());

PsiTreeUtil.processElements(
root,
element -> {
if (element instanceof PsiLet) {
foldLet(descriptors, (PsiLet) element);
} else if (element instanceof PsiType) {
foldType(descriptors, (PsiType) element);
} else if (element instanceof PsiInnerModule) {
foldModule(descriptors, (PsiInnerModule) element);
} else if (element instanceof PsiFunction) {
foldFunction(descriptors, (PsiFunction) element);
} else if (element instanceof PsiFunctor) {
foldFunctor(descriptors, (PsiFunctor) element);
} else if (element instanceof PsiTag) {
foldTag(descriptors, (PsiTag) element);
} else if (element instanceof PsiPatternMatch) {
foldPatternMatch(descriptors, (PsiPatternMatch) element);
} else if (element instanceof PsiSwitch) {
foldSwitch(descriptors, (PsiSwitch) element);
} else if (element instanceof OclYaccHeader) {
foldHeader(descriptors, (OclYaccHeader) element);
} else if (element instanceof OclYaccRule) {
foldRule(descriptors, (OclYaccRule) element);
} else if (types.MULTI_COMMENT == element.getNode().getElementType()) {
FoldingDescriptor fold = fold(element);
if (fold != null) {
descriptors.add(fold);
}
}

return true;
});
PsiTreeUtil.processElements(root, element -> {
if (element instanceof PsiLet) {
foldLet(descriptors, (PsiLet) element);
} else if (element instanceof PsiType) {
foldType(descriptors, (PsiType) element);
} else if (element instanceof PsiInnerModule) {
foldModule(descriptors, (PsiInnerModule) element);
} else if (element instanceof PsiFunction) {
foldFunction(descriptors, (PsiFunction) element);
} else if (element instanceof PsiFunctor) {
foldFunctor(descriptors, (PsiFunctor) element);
} else if (element instanceof PsiTag) {
foldTag(descriptors, (PsiTag) element);
} else if (element instanceof PsiPatternMatch) {
foldPatternMatch(descriptors, (PsiPatternMatch) element);
} else if (element instanceof PsiSwitch) {
foldSwitch(descriptors, (PsiSwitch) element);
} else if (element instanceof OclYaccHeader) {
foldHeader(descriptors, (OclYaccHeader) element);
} else if (element instanceof OclYaccRule) {
foldRule(descriptors, (OclYaccRule) element);
} else if (types.MULTI_COMMENT == element.getNode().getElementType()) {
FoldingDescriptor fold = fold(element);
if (fold != null) {
descriptors.add(fold);
}
}

return true;
});

return descriptors.toArray(new FoldingDescriptor[0]);
}

private void foldLet(
@NotNull List<FoldingDescriptor> descriptors, @NotNull PsiLet letExpression) {
private void foldLet(@NotNull List<FoldingDescriptor> descriptors, @NotNull PsiLet letExpression) {
FoldingDescriptor fold = fold(letExpression.getBinding());
if (fold != null) {
descriptors.add(fold);
}
}

private void foldType(
@NotNull List<FoldingDescriptor> descriptors, @NotNull PsiType typeExpression) {
PsiElement constrName =
ORUtil.findImmediateFirstChildOfClass(typeExpression, PsiLowerIdentifier.class);
private void foldType(@NotNull List<FoldingDescriptor> descriptors, @NotNull PsiType typeExpression) {
PsiElement constrName = ORUtil.findImmediateFirstChildOfClass(typeExpression, PsiLowerIdentifier.class);
if (constrName != null) {
PsiElement binding = typeExpression.getBinding();
if (binding != null && binding.getTextLength() > 5) {
Expand All @@ -84,8 +77,7 @@ private void foldType(
}
}

private void foldModule(
@NotNull List<FoldingDescriptor> descriptors, @NotNull PsiInnerModule module) {
private void foldModule(@NotNull List<FoldingDescriptor> descriptors, @NotNull PsiInnerModule module) {
FoldingDescriptor foldSignature = fold(module.getModuleType());
if (foldSignature != null) {
descriptors.add(foldSignature);
Expand All @@ -97,8 +89,7 @@ private void foldModule(
}
}

private void foldFunction(
@NotNull List<FoldingDescriptor> descriptors, @NotNull PsiFunction func) {
private void foldFunction(@NotNull List<FoldingDescriptor> descriptors, @NotNull PsiFunction func) {
FoldingDescriptor foldBinding = fold(func.getBody());
if (foldBinding != null) {
descriptors.add(foldBinding);
Expand Down Expand Up @@ -135,16 +126,14 @@ private void foldSwitch(@NotNull List<FoldingDescriptor> descriptors, @NotNull P
}
}

private void foldPatternMatch(
@NotNull List<FoldingDescriptor> descriptors, @NotNull PsiPatternMatch element) {
private void foldPatternMatch(@NotNull List<FoldingDescriptor> descriptors, @NotNull PsiPatternMatch element) {
FoldingDescriptor fold = fold(element.getBody());
if (fold != null) {
descriptors.add(fold);
}
}

private void foldHeader(
@NotNull List<FoldingDescriptor> descriptors, @NotNull OclYaccHeader root) {
private void foldHeader(@NotNull List<FoldingDescriptor> descriptors, @NotNull OclYaccHeader root) {
FoldingDescriptor fold =
fold(ORUtil.findImmediateFirstChildOfType(root, OclYaccLazyTypes.OCAML_LAZY_NODE));
if (fold != null) {
Expand All @@ -153,8 +142,7 @@ private void foldHeader(
}

private void foldRule(@NotNull List<FoldingDescriptor> descriptors, @NotNull OclYaccRule root) {
FoldingDescriptor fold =
fold(ORUtil.findImmediateFirstChildOfClass(root, OclYaccRuleBody.class));
FoldingDescriptor fold = fold(ORUtil.findImmediateFirstChildOfClass(root, OclYaccRuleBody.class));
if (fold != null) {
descriptors.add(fold);
}
Expand Down
30 changes: 0 additions & 30 deletions src/com/reason/ide/structure/StructureViewElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import com.reason.lang.core.psi.PsiType;
import com.reason.lang.core.psi.*;
import com.reason.lang.core.psi.impl.*;
import com.reason.lang.core.psi.ocamlyacc.*;
import com.reason.lang.ocamlyacc.*;
import org.jetbrains.annotations.*;

import javax.swing.*;
Expand Down Expand Up @@ -150,10 +148,6 @@ public Icon getIcon(boolean unused) {
treeElements = buildTypeStructure((PsiType) m_element);
} else if (m_element instanceof PsiClass) {
treeElements = buildClassStructure((PsiClass) m_element);
} else if (m_element instanceof OclYaccHeader) {
treeElements = buildYaccHeaderStructure((OclYaccHeader) m_element);
} else if (m_element instanceof OclYaccTrailer) {
treeElements = buildYaccTrailerStructure((OclYaccTrailer) m_element);
} else if (m_element instanceof PsiStanza) {
treeElements = buildStanzaStructure((PsiStanza) m_element);
} else if (m_element instanceof PsiLet) {
Expand Down Expand Up @@ -251,30 +245,6 @@ public Icon getIcon(boolean unused) {
return treeElements;
}

private @NotNull List<TreeElement> buildYaccHeaderStructure(@NotNull OclYaccHeader root) {
List<TreeElement> treeElements = new ArrayList<>();

PsiElement rootElement =
ORUtil.findImmediateFirstChildOfType(root, OclYaccTypes.OCAML_LAZY_NODE);
if (rootElement != null) {
rootElement.acceptChildren(new ElementVisitor(treeElements, m_level));
}

return treeElements;
}

private @NotNull List<TreeElement> buildYaccTrailerStructure(@NotNull OclYaccTrailer root) {
List<TreeElement> treeElements = new ArrayList<>();

PsiElement rootElement =
ORUtil.findImmediateFirstChildOfType(root, OclYaccTypes.OCAML_LAZY_NODE);
if (rootElement != null) {
rootElement.acceptChildren(new ElementVisitor(treeElements, m_level));
}

return treeElements;
}

static class ElementVisitor extends PsiElementVisitor {
private final List<TreeElement> m_treeElements;
private final int m_elementLevel;
Expand Down
16 changes: 16 additions & 0 deletions src/com/reason/lang/core/psi/PsiOCamlSection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.reason.lang.core.psi;

import com.intellij.extapi.psi.*;
import com.intellij.lang.*;
import org.jetbrains.annotations.*;

public class PsiOCamlSection extends ASTWrapperPsiElement {
public PsiOCamlSection(ASTNode node) {
super(node);
}

@Override
public @NotNull String toString() {
return "OCaml lazy section";
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions src/com/reason/lang/core/psi/ocamlyacc/OclYaccHeader.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions src/com/reason/lang/core/psi/ocamlyacc/OclYaccRule.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 83a5dc6

Please sign in to comment.