diff --git a/META-INF/plugin.xml b/META-INF/plugin.xml index a91c58038..f02d8947b 100644 --- a/META-INF/plugin.xml +++ b/META-INF/plugin.xml @@ -196,6 +196,7 @@ + diff --git a/src/com/haskforce/cabal/CabalParser.java b/src/com/haskforce/cabal/CabalParser.java index 5c1498379..324b46a72 100644 --- a/src/com/haskforce/cabal/CabalParser.java +++ b/src/com/haskforce/cabal/CabalParser.java @@ -1,23 +1,6 @@ package com.haskforce.cabal; -import com.intellij.lang.ASTNode; -import com.intellij.lang.PsiBuilder; -import com.intellij.lang.PsiParser; -import com.intellij.psi.tree.IElementType; -import org.jetbrains.annotations.NotNull; +import com.haskforce.utils.parser.SimplePsiParser; -/** - * Simple parser which basically returns the result from the syntax highlighting lexer. - */ -public class CabalParser implements PsiParser { - @NotNull - @Override - public ASTNode parse(IElementType root, PsiBuilder builder) { - PsiBuilder.Marker marker = builder.mark(); - while (!builder.eof()) { - builder.advanceLexer(); - } - marker.done(root); - return builder.getTreeBuilt(); - } +public class CabalParser extends SimplePsiParser { } diff --git a/src/com/haskforce/utils/parser/SimplePsiParser.java b/src/com/haskforce/utils/parser/SimplePsiParser.java new file mode 100644 index 000000000..93263c476 --- /dev/null +++ b/src/com/haskforce/utils/parser/SimplePsiParser.java @@ -0,0 +1,23 @@ +package com.haskforce.utils.parser; + +import com.intellij.lang.ASTNode; +import com.intellij.lang.PsiBuilder; +import com.intellij.lang.PsiParser; +import com.intellij.psi.tree.IElementType; +import org.jetbrains.annotations.NotNull; + +/** + * Simple parser which basically returns the result from the syntax highlighting lexer. + */ +public class SimplePsiParser implements PsiParser { + @NotNull + @Override + public ASTNode parse(IElementType root, PsiBuilder builder) { + PsiBuilder.Marker marker = builder.mark(); + while (!builder.eof()) { + builder.advanceLexer(); + } + marker.done(root); + return builder.getTreeBuilt(); + } +} diff --git a/src/com/haskforce/yesod/shakespeare/hamlet/HamletFileType.java b/src/com/haskforce/yesod/shakespeare/hamlet/HamletFileType.java index d59bf6473..902d62138 100644 --- a/src/com/haskforce/yesod/shakespeare/hamlet/HamletFileType.java +++ b/src/com/haskforce/yesod/shakespeare/hamlet/HamletFileType.java @@ -1,6 +1,5 @@ package com.haskforce.yesod.shakespeare.hamlet; -import com.intellij.icons.AllIcons; import com.intellij.openapi.fileTypes.LanguageFileType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -35,6 +34,6 @@ public String getDefaultExtension() { @Nullable @Override public Icon getIcon() { - return AllIcons.FileTypes.Html; + return HamletIcons.FILE; } } diff --git a/src/com/haskforce/yesod/shakespeare/hamlet/HamletIcons.java b/src/com/haskforce/yesod/shakespeare/hamlet/HamletIcons.java new file mode 100644 index 000000000..89b2f7c76 --- /dev/null +++ b/src/com/haskforce/yesod/shakespeare/hamlet/HamletIcons.java @@ -0,0 +1,9 @@ +package com.haskforce.yesod.shakespeare.hamlet; + +import com.intellij.icons.AllIcons; + +import javax.swing.*; + +public class HamletIcons { + public static final Icon FILE = AllIcons.FileTypes.Html; +} diff --git a/src/com/haskforce/yesod/shakespeare/hamlet/HamletParser.java b/src/com/haskforce/yesod/shakespeare/hamlet/HamletParser.java new file mode 100644 index 000000000..eda1f3598 --- /dev/null +++ b/src/com/haskforce/yesod/shakespeare/hamlet/HamletParser.java @@ -0,0 +1,6 @@ +package com.haskforce.yesod.shakespeare.hamlet; + +import com.haskforce.utils.parser.SimplePsiParser; + +public class HamletParser extends SimplePsiParser { +} diff --git a/src/com/haskforce/yesod/shakespeare/hamlet/HamletParserDefinition.java b/src/com/haskforce/yesod/shakespeare/hamlet/HamletParserDefinition.java new file mode 100644 index 000000000..4379033f1 --- /dev/null +++ b/src/com/haskforce/yesod/shakespeare/hamlet/HamletParserDefinition.java @@ -0,0 +1,73 @@ +package com.haskforce.yesod.shakespeare.hamlet; + +import com.haskforce.yesod.shakespeare.hamlet.highlighting.HamletSyntaxHighlightingLexer; +import com.haskforce.yesod.shakespeare.hamlet.psi.HamletFile; +import com.haskforce.yesod.shakespeare.hamlet.psi.HamletTypes; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +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 org.jetbrains.annotations.NotNull; + +public class HamletParserDefinition implements ParserDefinition { + public static final IFileElementType FILE = new IFileElementType(Language.findInstance(HamletLanguage.class)); + + @NotNull + @Override + public Lexer createLexer(Project project) { + return new HamletSyntaxHighlightingLexer(); + } + + @Override + public PsiParser createParser(Project project) { + return new HamletParser(); + } + + @Override + public IFileElementType getFileNodeType() { + return FILE; + } + + @NotNull + @Override + public TokenSet getWhitespaceTokens() { + return TokenSet.create(TokenType.WHITE_SPACE); + } + + @NotNull + @Override + public TokenSet getCommentTokens() { + return TokenSet.create(HamletTypes.LINE_COMMENT); + } + + @NotNull + @Override + public TokenSet getStringLiteralElements() { + return TokenSet.create(); + } + + @NotNull + @Override + public PsiElement createElement(ASTNode node) { + return new ASTWrapperPsiElement(node); + } + + @Override + public PsiFile createFile(FileViewProvider viewProvider) { + return new HamletFile(viewProvider); + } + + @Override + public SpaceRequirements spaceExistanceTypeBetweenTokens(ASTNode left, ASTNode right) { + return SpaceRequirements.MAY; + } +} diff --git a/src/com/haskforce/yesod/shakespeare/hamlet/highlighting/HamletSyntaxHighlightingLexer.java b/src/com/haskforce/yesod/shakespeare/hamlet/highlighting/HamletSyntaxHighlightingLexer.java index 2f7f03035..bf03c4ac4 100644 --- a/src/com/haskforce/yesod/shakespeare/hamlet/highlighting/HamletSyntaxHighlightingLexer.java +++ b/src/com/haskforce/yesod/shakespeare/hamlet/highlighting/HamletSyntaxHighlightingLexer.java @@ -7,7 +7,7 @@ public class HamletSyntaxHighlightingLexer extends MergingLexerAdapter { public static final TokenSet mergeMe = TokenSet.create(HamletTypes.HASKELL_CODE); - HamletSyntaxHighlightingLexer() { + public HamletSyntaxHighlightingLexer() { super(new FlexAdapter(new _HamletSyntaxHighlightingLexer()), mergeMe); } } diff --git a/src/com/haskforce/yesod/shakespeare/hamlet/psi/HamletFile.java b/src/com/haskforce/yesod/shakespeare/hamlet/psi/HamletFile.java new file mode 100644 index 000000000..3ea9c2df8 --- /dev/null +++ b/src/com/haskforce/yesod/shakespeare/hamlet/psi/HamletFile.java @@ -0,0 +1,35 @@ +package com.haskforce.yesod.shakespeare.hamlet.psi; + +import com.haskforce.yesod.shakespeare.hamlet.HamletFileType; +import com.haskforce.yesod.shakespeare.hamlet.HamletIcons; +import com.haskforce.yesod.shakespeare.hamlet.HamletLanguage; +import com.intellij.extapi.psi.PsiFileBase; +import com.intellij.openapi.fileTypes.FileType; +import com.intellij.psi.FileViewProvider; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; + +public class HamletFile extends PsiFileBase { + public HamletFile(@NotNull FileViewProvider viewProvider) { + super(viewProvider, HamletLanguage.INSTANCE); + } + + @NotNull + @Override + public FileType getFileType() { + return HamletFileType.INSTANCE; + } + + @Override + public String toString() { + return "Hamlet File"; + } + + @Nullable + @Override + public Icon getIcon(int flags) { + return HamletIcons.FILE; + } +}