Skip to content

Commit

Permalink
Added GLSL precision modifier and statement handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkyenus committed Apr 20, 2015
1 parent e37c30a commit 5404788
Show file tree
Hide file tree
Showing 5 changed files with 485 additions and 459 deletions.
6 changes: 6 additions & 0 deletions resources/colorSchemes/GLSLDefault.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
<option name="FONT_TYPE" value="0"/>
</value>
</option>
<option name="GLSL.PRECISION_STATEMENT">
<value>
<option name="FOREGROUND" value="002050"/>
<option name="FONT_TYPE" value="2"/>
</value>
</option>
<option name="GLSL.TEXT">
<value>
<option name="FOREGROUND" value="000000"/>
Expand Down
14 changes: 5 additions & 9 deletions src/glslplugin/GLSLHighlighter.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,31 @@

public class GLSLHighlighter extends SyntaxHighlighterBase {
static final TextAttributesKey GLSL_NUMBER = TextAttributesKey.createTextAttributesKey("GLSL.NUMBER", DefaultLanguageHighlighterColors.NUMBER);
//static final TextAttributesKey GLSL_NUMBER = TextAttributesKey.createTextAttributesKey("GLSL.NUMBER", SyntaxHighlighterColors.NUMBER.getDefaultAttributes());

static final TextAttributesKey GLSL_TYPE_SPECIFIER = TextAttributesKey.createTextAttributesKey("GLSL.TYPE_SPECIFIER", DefaultLanguageHighlighterColors.CLASS_REFERENCE);
//static final TextAttributesKey GLSL_TYPE_SPECIFIER = TextAttributesKey.createTextAttributesKey("GLSL.TYPE_SPECIFIER", new TextAttributes(new Color(0, 128, 128), null, null, null, Font.BOLD));

static final TextAttributesKey GLSL_TYPE_QUALIFIERS = TextAttributesKey.createTextAttributesKey("GLSL.QUALIFIER_TOKENS", DefaultLanguageHighlighterColors.KEYWORD);
//static final TextAttributesKey GLSL_TYPE_QUALIFIERS = TextAttributesKey.createTextAttributesKey("GLSL.QUALIFIER_TOKENS", new TextAttributes(new Color(0, 128, 255), null, null, null, Font.BOLD));

//static final TextAttributesKey GLSL_PARAMETER_QUALIFIERS = TextAttributesKey.createTextAttributesKey("GLSL.PARAMETER_QUALIFIERS", DefaultLanguageHighlighterColors.KEYWORD);
//static final TextAttributesKey GLSL_PARAMETER_QUALIFIERS = TextAttributesKey.createTextAttributesKey("GLSL.PARAMETER_QUALIFIERS", new TextAttributes(new Color(128, 255, 0), null, null, null, Font.ITALIC));

static final TextAttributesKey GLSL_FLOW_KEYWORDS = TextAttributesKey.createTextAttributesKey("GLSL.FLOW_KEYWORDS", DefaultLanguageHighlighterColors.KEYWORD);
//static final TextAttributesKey GLSL_FLOW_KEYWORDS = TextAttributesKey.createTextAttributesKey("GLSL.FLOW_KEYWORDS", new TextAttributes(new Color(255, 128, 0), null, null, null, Font.PLAIN));

static final TextAttributesKey GLSL_COMMENT = TextAttributesKey.createTextAttributesKey("GLSL.COMMENT", DefaultLanguageHighlighterColors.LINE_COMMENT);
//static final TextAttributesKey GLSL_COMMENT = TextAttributesKey.createTextAttributesKey("GLSL.COMMENT", SyntaxHighlighterColors.LINE_COMMENT.getDefaultAttributes());

static final TextAttributesKey GLSL_IDENTIFIER = TextAttributesKey.createTextAttributesKey("GLSL.IDENTIFIER", DefaultLanguageHighlighterColors.IDENTIFIER);
//static final TextAttributesKey GLSL_IDENTIFIER = TextAttributesKey.createTextAttributesKey("GLSL.IDENTIFIER", new TextAttributes(Color.BLACK, null, null, null, Font.PLAIN));

static final TextAttributesKey GLSL_COMPILER_DIRECTIVE = TextAttributesKey.createTextAttributesKey("GLSL.COMPILER_DIRECTIVE",DefaultLanguageHighlighterColors.DOC_COMMENT_MARKUP);
//new TextAttributes(Color.GREEN.darker().darker(), null, null, null, Font.ITALIC)
static final TextAttributesKey GLSL_COMPILER_DIRECTIVE_VERSION = TextAttributesKey.createTextAttributesKey("GLSL.COMPILER_DIRECTIVE_VERSION", GLSL_COMPILER_DIRECTIVE);
static final TextAttributesKey GLSL_COMPILER_DIRECTIVE_EXTENSION = TextAttributesKey.createTextAttributesKey("GLSL.COMPILER_DIRECTIVE_EXTENSION", GLSL_COMPILER_DIRECTIVE);
static final TextAttributesKey GLSL_COMPILER_DIRECTIVE_PRAGMA = TextAttributesKey.createTextAttributesKey("GLSL.COMPILER_DIRECTIVE_PRAGMA", GLSL_COMPILER_DIRECTIVE);
static final TextAttributesKey GLSL_COMPILER_DIRECTIVE_OTHER = TextAttributesKey.createTextAttributesKey("GLSL.COMPILER_DIRECTIVE_OTHER", GLSL_COMPILER_DIRECTIVE);

static final TextAttributesKey GLSL_PRECISION_STATEMENT = TextAttributesKey.createTextAttributesKey("GLSL.PRECISION_STATEMENT", GLSL_COMPILER_DIRECTIVE);

static final TextAttributesKey GLSL_UNKNOWN = TextAttributesKey.createTextAttributesKey("GLSL.UNKNOWN", HighlighterColors.BAD_CHARACTER);
//static final TextAttributesKey GLSL_UNKNOWN = TextAttributesKey.createTextAttributesKey("GLSL.UNKNOWN", new TextAttributes(Color.RED, null, null, null, Font.BOLD));

static final TextAttributesKey GLSL_TEXT = TextAttributesKey.createTextAttributesKey("GLSL.TEXT", DefaultLanguageHighlighterColors.DOT);
//static final TextAttributesKey GLSL_TEXT = TextAttributesKey.createTextAttributesKey("GLSL.TEXT", new TextAttributes(Color.BLACK, null, null, null, Font.PLAIN));

public GLSLHighlighter() {
super();
Expand Down Expand Up @@ -98,6 +92,8 @@ public TextAttributesKey[] getTokenHighlights(IElementType type) {
return new TextAttributesKey[]{GLSL_FLOW_KEYWORDS};
} else if (type == UNKNOWN) {
return new TextAttributesKey[]{GLSL_UNKNOWN};
}else if (type == PRECISION_STATEMENT){
return new TextAttributesKey[]{GLSL_PRECISION_STATEMENT};
}
return new TextAttributesKey[]{GLSL_TEXT};
}
Expand Down
8 changes: 5 additions & 3 deletions src/glslplugin/lang/elements/GLSLTokenTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public class GLSLTokenTypes {
public static final IElementType CENTROID_KEYWORD = new GLSLElementType("CENTROID_KEYWORD");
public static final IElementType INVARIANT_KEYWORD = new GLSLElementType("INVARIANT_KEYWORD");

public static final IElementType PRECISION_KEYWORD = new GLSLElementType("PRECISION_KEYWORD");

public static final IElementType IN_KEYWORD = new GLSLElementType("IN_KEYWORD");
public static final IElementType OUT_KEYWORD = new GLSLElementType("OUT_KEYWORD");
public static final IElementType INOUT_KEYWORD = new GLSLElementType("INOUT_KEYWORD");
Expand Down Expand Up @@ -130,7 +132,7 @@ public class GLSLTokenTypes {
public static final IElementType WHITE_SPACE = TokenType.WHITE_SPACE;
public static final IElementType UNKNOWN = new GLSLElementType("UNKNOWN");

public static final IElementType GLES_PRECISION = new GLSLElementType("PRECISION");
public static final IElementType PRECISION_STATEMENT = new GLSLElementType("PRECISION_STATEMENT");

public static final IElementType COMPILER_DIRECTIVE_VERSION = new GLSLElementType("COMPILER_DIRECTIVE_VERSION");
public static final IElementType COMPILER_DIRECTIVE_EXTENSION = new GLSLElementType("COMPILER_DIRECTIVE_EXTENSION");
Expand All @@ -149,9 +151,9 @@ public class GLSLTokenTypes {
TEXTURE_TYPE_SPECIFIER_NONARRAY, TokenSet.create(STRUCT, NAMED_TYPE));

public static final TokenSet QUALIFIER_TOKENS = TokenSet.create(CONST_KEYWORD, ATTRIBUTE_KEYWORD, VARYING_KEYWORD,
UNIFORM_KEYWORD, CENTROID_KEYWORD, INVARIANT_KEYWORD, IN_KEYWORD, OUT_KEYWORD, INOUT_KEYWORD);
UNIFORM_KEYWORD, CENTROID_KEYWORD, INVARIANT_KEYWORD, IN_KEYWORD, OUT_KEYWORD, INOUT_KEYWORD, PRECISION_KEYWORD);

public static final TokenSet COMMENTS = TokenSet.create(COMMENT_BLOCK, COMMENT_LINE, COMPILER_DIRECTIVE_VERSION, COMPILER_DIRECTIVE_EXTENSION, COMPILER_DIRECTIVE_PRAGMA, COMPILER_DIRECTIVE_OTHER,GLES_PRECISION);
public static final TokenSet COMMENTS = TokenSet.create(COMMENT_BLOCK, COMMENT_LINE, COMPILER_DIRECTIVE_VERSION, COMPILER_DIRECTIVE_EXTENSION, COMPILER_DIRECTIVE_PRAGMA, COMPILER_DIRECTIVE_OTHER, PRECISION_STATEMENT);

public static final TokenSet ITERATION_KEYWORDS = TokenSet.create(WHILE_KEYWORD, DO_KEYWORD, FOR_KEYWORD);
public static final TokenSet JUMP_KEYWORDS = TokenSet.create(BREAK_JUMP_STATEMENT, CONTINUE_JUMP_STATEMENT, RETURN_JUMP_STATEMENT, DISCARD_JUMP_STATEMENT);
Expand Down
9 changes: 6 additions & 3 deletions src/glslplugin/lang/scanner/GLSL.flex
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ LINE_COMMENT = "//"[^\r\n]*
BLOCK_COMMENT = "/*"([^"*"]|("*"+[^"*""/"]))*("*"+"/")?

GLSL_ES_TYPE = void|float|(u?int)|bool|((i|b|u)?vec([2-4]))|(mat[2-4](x[2-4])?)|(samplerCubeShadow|sampler2DShadow|sampler2DArrayShadow)|((i|u)?sampler(2D|3D|Cube|2DArray))
GLSL_ES_TYPE_MODIFIER = (high|medium|low)p
GLSL_ES_PRECISION_MODIFIER = (high|medium|low)p

%%
/**
Expand Down Expand Up @@ -113,7 +113,10 @@ attribute {return ATTRIBUTE_KEYWORD; }
uniform {return UNIFORM_KEYWORD; }
varying {return VARYING_KEYWORD; }
centroid {return CENTROID_KEYWORD; }
invariant {return INVARIANT_KEYWORD;}
invariant {return INVARIANT_KEYWORD; }

/* GLSL ES STORAGE QUALIFIERS */
{GLSL_ES_PRECISION_MODIFIER} {return PRECISION_KEYWORD; }

/* GLSL PARAMETER QUALIFIER */
in {return IN_KEYWORD; }
Expand All @@ -138,7 +141,7 @@ if {return IF_KEYWORD; }
else {return ELSE_KEYWORD; }

/* GLSL ES PRECISION */
precision{WHITE_SPACE}+{GLSL_ES_TYPE_MODIFIER}{WHITE_SPACE}+{GLSL_ES_TYPE}";" {return GLES_PRECISION; }
precision{WHITE_SPACE}+{GLSL_ES_PRECISION_MODIFIER}{WHITE_SPACE}+{GLSL_ES_TYPE}";" {return PRECISION_STATEMENT; }


/* GLSL Symbols */
Expand Down
Loading

0 comments on commit 5404788

Please sign in to comment.