-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#25 - Add minimal support for .ml4 files: use the same parser than fo…
…r Ocaml
- Loading branch information
Showing
6 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.reason.ide.files; | ||
|
||
import com.intellij.openapi.fileTypes.FileType; | ||
import com.intellij.psi.FileViewProvider; | ||
import com.reason.lang.ocaml.OclLanguage; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class Ml4File extends FileBase { | ||
public Ml4File(@NotNull FileViewProvider viewProvider) { | ||
super(viewProvider, OclLanguage.INSTANCE); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public FileType getFileType() { | ||
return Ml4FileType.INSTANCE; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "OcamlP4 File"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.reason.ide.files; | ||
|
||
import com.intellij.openapi.fileTypes.LanguageFileType; | ||
import com.reason.icons.Icons; | ||
import com.reason.lang.ocaml.OclLanguage; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import javax.swing.*; | ||
|
||
public class Ml4FileType extends LanguageFileType { | ||
public static final Ml4FileType INSTANCE = new Ml4FileType(); | ||
|
||
private Ml4FileType() { | ||
super(OclLanguage.INSTANCE); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String getName() { | ||
return "OcamlP4 file"; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String getDescription() { | ||
return "Ocaml preprocessor file"; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String getDefaultExtension() { | ||
return "ml4"; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Icon getIcon() { | ||
return Icons.OCL_FILE; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/reason/ide/files/Ml4FileTypeFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.reason.ide.files; | ||
|
||
import com.intellij.openapi.fileTypes.FileTypeConsumer; | ||
import com.intellij.openapi.fileTypes.FileTypeFactory; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class Ml4FileTypeFactory extends FileTypeFactory { | ||
@Override | ||
public void createFileTypes(@NotNull FileTypeConsumer fileTypeConsumer) { | ||
fileTypeConsumer.consume(Ml4FileType.INSTANCE, "ml4"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.reason.lang.ocaml; | ||
|
||
import com.intellij.lang.Language; | ||
|
||
public class OclP4Language extends Language { | ||
public static final OclP4Language INSTANCE = new OclP4Language(); | ||
|
||
private OclP4Language() { | ||
super("Ml4"); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/main/java/com/reason/lang/ocaml/OclP4ParserDefinition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.reason.lang.ocaml; | ||
|
||
import com.intellij.lang.ASTNode; | ||
import com.intellij.lang.Language; | ||
import com.intellij.lang.ParserDefinition; | ||
import com.intellij.lang.PsiParser; | ||
import com.intellij.lexer.Lexer; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.psi.FileViewProvider; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.PsiFile; | ||
import com.intellij.psi.TokenType; | ||
import com.intellij.psi.tree.IFileElementType; | ||
import com.intellij.psi.tree.TokenSet; | ||
import com.reason.ide.files.Ml4File; | ||
import com.reason.lang.LexerAdapter; | ||
import com.reason.lang.PsiElementFactory; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class OclP4ParserDefinition implements ParserDefinition { | ||
private static final TokenSet WHITE_SPACES = TokenSet.create(TokenType.WHITE_SPACE); | ||
private static final TokenSet COMMENTS = TokenSet.create(OclTypes.INSTANCE.COMMENT); | ||
private static final TokenSet STRINGS = TokenSet.create(OclTypes.INSTANCE.STRING); | ||
|
||
private static final IFileElementType FILE = new IFileElementType(Language.findInstance(OclP4Language.class)); | ||
|
||
@NotNull | ||
@Override | ||
public Lexer createLexer(Project project) { | ||
return new LexerAdapter(OclTypes.INSTANCE); | ||
} | ||
|
||
@NotNull | ||
public TokenSet getWhitespaceTokens() { | ||
return WHITE_SPACES; | ||
} | ||
|
||
@NotNull | ||
public TokenSet getCommentTokens() { | ||
return COMMENTS; | ||
} | ||
|
||
@NotNull | ||
public TokenSet getStringLiteralElements() { | ||
return STRINGS; | ||
} | ||
|
||
@NotNull | ||
public PsiParser createParser(final Project project) { | ||
return new OclParser(); | ||
} | ||
|
||
@Override | ||
public IFileElementType getFileNodeType() { | ||
return FILE; | ||
} | ||
|
||
public PsiFile createFile(FileViewProvider viewProvider) { | ||
return new Ml4File(viewProvider); | ||
} | ||
|
||
public ParserDefinition.SpaceRequirements spaceExistanceTypeBetweenTokens(ASTNode left, ASTNode right) { | ||
return ParserDefinition.SpaceRequirements.MAY; | ||
} | ||
|
||
@NotNull | ||
public PsiElement createElement(ASTNode node) { | ||
return PsiElementFactory.createElement(OclTypes.INSTANCE, node); | ||
} | ||
} |