Skip to content
Permalink
Browse files

syntax highlight, color settings page

  • Loading branch information...
hsz committed Jun 18, 2014
1 parent a79360f commit 5b8dbab31af5b805fc402d7686a591215072844e
@@ -19,6 +19,7 @@

## Additional for IntelliJ
out/
gen/

# generated by mpeltonen/sbt-idea plugin
.idea_modules/
@@ -28,3 +29,7 @@ atlassian-ide-plugin.xml

# generated by Crashlytics plugin (for Android Studio and Intellij)
com_crashlytics_export_strings.xml

# Flex
idea-flex.skeleton
JFlex.jar
@@ -1,5 +1,5 @@
<idea-plugin version="2">
<id>mobi.hsz.idea.latex</id>
<id>mobi.hsz.idea.gitignore</id>
<name>.gitignore Plugin</name>
<version>0.0.1</version>
<vendor email="jakub@hsz.mobi" url="http://www.hsz.mobi">hsz</vendor>
@@ -27,6 +27,9 @@

<extensions defaultExtensionNs="com.intellij">
<fileTypeFactory implementation="mobi.hsz.idea.gitignore.GitignoreFileTypeFactory" />
<lang.parserDefinition language=".gitignore" implementationClass="mobi.hsz.idea.gitignore.GitignoreParserDefinition" />
<lang.syntaxHighlighterFactory key=".gitignore" implementationClass="mobi.hsz.idea.gitignore.GitignoreSyntaxHighlighterFactory" />
<colorSettingsPage implementation="mobi.hsz.idea.gitignore.GitignoreColorSettingsPage" />
</extensions>

<application-components>
@@ -0,0 +1,20 @@
{
parserClass="mobi.hsz.idea.gitignore.parser.GitignoreParser"

extends="com.intellij.extapi.psi.ASTWrapperPsiElement"

psiClassPrefix="Gitignore"
psiImplClassSuffix="Impl"
psiPackage="mobi.hsz.idea.gitignore.psi"
psiImplPackage="mobi.hsz.idea.gitignore.psi.impl"

elementTypeHolderClass="mobi.hsz.idea.gitignore.psi.GitignoreTypes"
elementTypeClass="mobi.hsz.idea.gitignore.psi.GitignoreElementType"
tokenTypeClass="mobi.hsz.idea.gitignore.psi.GitignoreTokenType"
}

gitignoreFile ::= item_*

private item_ ::= (property|COMMENT|CRLF)

property ::= (KEY? SEPARATOR VALUE?) | KEY
@@ -0,0 +1,46 @@
package mobi.hsz.idea.gitignore;

import com.intellij.lexer.FlexLexer;
import com.intellij.psi.tree.IElementType;
import mobi.hsz.idea.gitignore.psi.GitignoreTypes;
import com.intellij.psi.TokenType;

%%

%class GitignoreLexer
%implements FlexLexer
%unicode
%function advance
%type IElementType
%eof{ return;
%eof}

CRLF= \n|\r|\r\n
WHITE_SPACE=[\ \t\f]
FIRST_VALUE_CHARACTER=[^ \n\r\f\\] | "\\"{CRLF} | "\\".
VALUE_CHARACTER=[^\n\r\f\\] | "\\"{CRLF} | "\\".
END_OF_LINE_COMMENT=("#"|"!")[^\r\n]*
SEPARATOR=[:=]
KEY_CHARACTER=[^:=\ \n\r\t\f\\] | "\\"{CRLF} | "\\".

%state WAITING_VALUE

%%

<YYINITIAL> {END_OF_LINE_COMMENT} { yybegin(YYINITIAL); return GitignoreTypes.COMMENT; }

<YYINITIAL> {KEY_CHARACTER}+ { yybegin(YYINITIAL); return GitignoreTypes.KEY; }

<YYINITIAL> {SEPARATOR} { yybegin(WAITING_VALUE); return GitignoreTypes.SEPARATOR; }

<WAITING_VALUE> {CRLF} { yybegin(YYINITIAL); return GitignoreTypes.CRLF; }

<WAITING_VALUE> {WHITE_SPACE}+ { yybegin(WAITING_VALUE); return TokenType.WHITE_SPACE; }

<WAITING_VALUE> {FIRST_VALUE_CHARACTER}{VALUE_CHARACTER}* { yybegin(YYINITIAL); return GitignoreTypes.VALUE; }

{CRLF} { yybegin(YYINITIAL); return GitignoreTypes.CRLF; }

{WHITE_SPACE}+ { yybegin(YYINITIAL); return TokenType.WHITE_SPACE; }

. { return TokenType.BAD_CHARACTER; }
@@ -0,0 +1,61 @@
package mobi.hsz.idea.gitignore;

import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.fileTypes.SyntaxHighlighter;
import com.intellij.openapi.options.colors.AttributesDescriptor;
import com.intellij.openapi.options.colors.ColorDescriptor;
import com.intellij.openapi.options.colors.ColorSettingsPage;
import mobi.hsz.idea.gitignore.util.GitignoreIcons;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.util.Map;

public class GitignoreColorSettingsPage implements ColorSettingsPage {
private static final AttributesDescriptor[] DESCRIPTORS = new AttributesDescriptor[]{
new AttributesDescriptor("Comment", GitignoreSyntaxHighlighter.COMMENT),
};

@Nullable
@Override
public Icon getIcon() {
return GitignoreIcons.FILE;
}

@NotNull
@Override
public SyntaxHighlighter getHighlighter() {
return new GitignoreSyntaxHighlighter();
}

@NotNull
@Override
public String getDemoText() {
return "foo";
}

@Nullable
@Override
public Map<String, TextAttributesKey> getAdditionalHighlightingTagToDescriptorMap() {
return null;
}

@NotNull
@Override
public AttributesDescriptor[] getAttributeDescriptors() {
return DESCRIPTORS;
}

@NotNull
@Override
public ColorDescriptor[] getColorDescriptors() {
return ColorDescriptor.EMPTY_ARRAY;
}

@NotNull
@Override
public String getDisplayName() {
return "Gitignore";
}
}

0 comments on commit 5b8dbab

Please sign in to comment.
You can’t perform that action at this time.