Skip to content

Commit

Permalink
fix GLShaderEditors error for last ECLIPSE NEON
Browse files Browse the repository at this point in the history
add configuration keyword in config.properties
improve keyword parsing
  • Loading branch information
nicolaichuk committed Sep 26, 2016
1 parent f3bff5e commit f015eb1
Show file tree
Hide file tree
Showing 7 changed files with 421 additions and 138 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/GLShaderEditors/bin
165 changes: 98 additions & 67 deletions GLShaderEditors/src/cgEditor/editors/GLSLScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,87 +3,118 @@
*/
package cgEditor.editors;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
* @author Martinez
*
*/
public class GLSLScanner extends ShaderFileScanner {

static char escChar[] = { '\n', ' ', '.', ';', ',', '(', ')', '[', ']' };
static char escChar[] = { '\n', '\t', ' ', '.', ';', ',', '(', ')', '[', ']' };

static final String language[] = { "std140", "state", "FRAGMENT", "VERTEX", "break", "const", "continue", "discard", "do", "else", "false", "for", "if",
"in", "inout", "out", "return", "true", "uniform", "varying", "void", "while", "#define", "#else", "#elif",
"#shader", "#for", "#endfor", "#include", "#endif", "#error", "#if", "#ifdef", "#ifndef", "#line", "#undef", "#pragma", "class", "enum", "typdef",
"union", "active", "asm", "break", "case", "cast", "centroid", "common", "default", "extern", "external",
"filter", "fixed", "flat", "foreach", "goto", "highp", "inline", "input", "interface", "invariant",
"layout", "lowp", "mediump", "namespace", "noinline", "noperspective", "output", "packed", "partition",
"patch", "precision", "public", "row_major", "sample", "sizeof", "smooth", "static", "struct", "subroutine",
"superp", "switch", "template", "this", "typedef", "using", "volatile" };

static final String language[] = { "break", "const", "continue", "discard",
"do", "else", "false", "for", "if", "in", "inout", "out", "return",
"true", "uniform", "varying", "void", "while", "#define", "#else",
"#elif", "#endif", "#error", "#if", "#ifdef", "#ifndef", "#line",
"#undef", "#pragma", "class", "enum", "typdef", "union" };
static final String types[] = { "float", "vec2", "vec3", "vec4", "sampler1D", "sampler1DShadow", "sampler2D",
"sampler2DShadow", "sampler3D", "samplerCube", "mat2", "mat3", "mat4", "ivec2", "ivec3", "ivec4", "bvec2",
"bvec3", "bvec4", "attribute", "bool", "gl_Color", "gl_FragCoord", "gl_FogCoord", "gl_FrontFacing",
"gl_MultiTexCoord0", "gl_MultiTexCoord1", "gl_MultiTexCoord2", "gl_MultiTexCoord3", "gl_MultiTexCoord4",
"gl_MultiTexCoord5", "gl_MultiTexCoord6", "gl_MultiTexCoord7", "gl_MultiTexCoord8", "gl_MultiTexCoord9",
"gl_MultiTexCoord10", "gl_MultiTexCoord11", "gl_MultiTexCoord12", "gl_MultiTexCoord13",
"gl_MultiTexCoord14", "gl_MultiTexCoord15", "gl_MultiTexCoord16", "gl_MultiTexCoord17",
"gl_MultiTexCoord18", "gl_MultiTexCoord19", "gl_MultiTexCoord20", "gl_MultiTexCoord21",
"gl_MultiTexCoord22", "gl_MultiTexCoord23", "gl_MultiTexCoord24", "gl_MultiTexCoord25",
"gl_MultiTexCoord26", "gl_MultiTexCoord27", "gl_MultiTexCoord28", "gl_MultiTexCoord29",
"gl_MultiTexCoord30", "gl_MultiTexCoord31", "gl_SecondaryColor", "gl_Normal", "gl_Vertex", "gl_PointSize",
"gl_Position", "gl_ClipVertex", "gl_FragColor", "gl_FragDepth", "gl_FrontColor", "gl_BackColor",
"gl_FrontSecondaryColor", "gl_BackSecondaryColor", "gl_TexCoord", "gl_FogFragCoord", "dmat2", "dmat2x2",
"dmat2x3", "dmat2x4", "dmat3", "dmat3x2", "dmat3x3", "dmat3x4", "dmat4", "dmat4x2", "dmat4x3", "dmat4x4",
"double", "dvec2", "dvec3", "dvec4", "fvec2", "fvec3", "fvec4", "half", "hvec2", "hvec3", "hvec4", "int",
"isampler1D", "isampler1DArray", "isampler2D", "isampler2DArray", "isampler2DMS", "isampler2DMSArray",
"isampler2DRect", "isampler3D", "isamplerBuffer", "isamplerCube", "isamplerCubeArray", "long", "mat2x2",
"mat2x3", "mat2x4", "mat3x2", "mat3x3", "mat3x4", "mat4x2", "mat4x3", "mat4x4", "sampler1DArray",
"sampler1DArrayShadow", "sampler2DArray", "sampler2DArrayShadow", "sampler2DMS", "sampler2DMSArray",
"sampler2DRect", "sampler2DRectShadow", "sampler3DRect", "samplerBuffer", "samplerCubeArray",
"samplerCubeArrayShadow", "samplerCubeShadow", "short", "uint", "unsigned", "usampler1D", "usampler1DArray",
"usampler2D", "usampler2DArray", "usampler2DMS", "usampler2DMSArray", "usampler2DRect", "usampler3D",
"usamplerBuffer", "usamplerCube", "usamplerCubeArray", "uvec2", "uvec3", "uvec4" };

static final String types[] = { "float", "vec2", "vec3", "vec4",
"sampler1D", "sampler1DShadow", "sampler2D", "sampler2DShadow",
"sampler3D", "samplerCube", "mat2", "mat3", "mat4", "ivec2",
"ivec3", "ivec4", "bvec2", "bvec3", "bvec4", "attribute", "bool",
"gl_Color", "gl_FragCoord", "gl_FogCoord", "gl_FrontFacing",
"gl_MultiTexCoord0", "gl_MultiTexCoord1", "gl_MultiTexCoord2",
"gl_MultiTexCoord3", "gl_MultiTexCoord4", "gl_MultiTexCoord5",
"gl_MultiTexCoord6", "gl_MultiTexCoord7", "gl_MultiTexCoord8",
"gl_MultiTexCoord9", "gl_MultiTexCoord10", "gl_MultiTexCoord11",
"gl_MultiTexCoord12", "gl_MultiTexCoord13", "gl_MultiTexCoord14",
"gl_MultiTexCoord15", "gl_MultiTexCoord16", "gl_MultiTexCoord17",
"gl_MultiTexCoord18", "gl_MultiTexCoord19", "gl_MultiTexCoord20",
"gl_MultiTexCoord21", "gl_MultiTexCoord22", "gl_MultiTexCoord23",
"gl_MultiTexCoord24", "gl_MultiTexCoord25", "gl_MultiTexCoord26",
"gl_MultiTexCoord27", "gl_MultiTexCoord28", "gl_MultiTexCoord29",
"gl_MultiTexCoord30", "gl_MultiTexCoord31", "gl_SecondaryColor",
"gl_Normal", "gl_Vertex", "gl_PointSize", "gl_Position",
"gl_ClipVertex", "gl_FragColor", "gl_FragDepth", "gl_FrontColor",
"gl_BackColor", "gl_FrontSecondaryColor", "gl_BackSecondaryColor",
"gl_TexCoord", "gl_FogFragCoord" };
static final String functions[] = { "radians", "degrees", "sin", "cos", "tan", "asin", "acos", "atan", "pow",
"exp2", "log2", "sqrt", "inversesqrt", "abs", "sign", "floor", "cei", "fract", "mod", "min", "max", "clamp",
"mix", "step", "smoothstep", "length", "distance", "dot", "cross", "normalize", "ftransform", "faceforward",
"reflect", "matrixcompmult", "lessThan", "lessThanEqual", "greaterThan", "greaterThanEqual", "equal",
"notEqual", "any", "all", "not", "texture1D", "texture1DProj", "texture1DLod", "texture1DProjLod",
"texture2D", "texture2DProj", "texture2DLod", "texture2DProjLod", "texture3D", "texture3DProj",
"texture3DLod", "texture3DProjLod", "textureCube", "textureCubeLod", "shadow1D", "shadow1DProj",
"shadow1DLod", "shadow1DProjLod", "shadow2D", "shadow2DProj", "shadow2DLod", "shadow2DProjLod", "dFdx",
"dFdy", "fwidth", "noise1", "noise2", "noise3", "noise4", "ceil", "exp", "log", "refract", "texelFetch",
"texelFetchOffset", "textureGrad", "textureGradOffset", "textureLod", "textureLodOffset", "textureOffset",
"textureProj", "textureProjGrad", "textureProjGradOffset", "textureProjLod", "textureProjLodOffset",
"textureProjOffset", "textureSize" };

static final String functions[] = { "radians", "degrees", "sin", "cos",
"tan", "asin", "acos", "atan", "pow", "exp2", "log2", "sqrt",
"inversesqrt", "abs", "sign", "floor", "cei", "fract", "mod",
"min", "max", "clamp", "mix", "step", "smoothstep", "length",
"distance", "dot", "cross", "normalize", "ftransform",
"faceforward", "reflect", "matrixcompmult", "lessThan",
"lessThanEqual", "greaterThan", "greaterThanEqual", "equal",
"notEqual", "any", "all", "not", "texture1D", "texture1DProj",
"texture1DLod", "texture1DProjLod", "texture2D", "texture2DProj",
"texture2DLod", "texture2DProjLod", "texture3D", "texture3DProj",
"texture3DLod", "texture3DProjLod", "textureCube",
"textureCubeLod", "shadow1D", "shadow1DProj", "shadow1DLod",
"shadow1DProjLod", "shadow2D", "shadow2DProj", "shadow2DLod",
"shadow2DProjLod", "dFdx", "dFdy", "fwidth", "noise1", "noise2",
"noise3", "noise4" };
static final String semantics[] = { "gl_ModelViewMatrix", "gl_ProjectionMatrix", "gl_ModelViewProjectionMatrix",
"gl_NormalMatrix", "gl_TextureMatrix", "gl_NormalScale", "gl_DepthRangeParameters", "gl_DepthRange",
"gl_ClipPlane", "gl_PointParameters", "gl_Point", "gl_MaterialParameters", "gl_FrontMaterial",
"gl_BackMaterial", "gl_LightSourceParameters", "gl_LightSource", "gl_LightModelParamters", "gl_LightModel",
"gl_LightModelProducts", "gl_FrontLightModelProduct", "gl_BackLightModelProduct", "gl_LightProducts",
"gl_FrontLightProduct", "gl_BackLightProduct", "gl_TextureEnvColor", "gl_EyePlaneS", "gl_EyePlaneT",
"gl_EyePlaneR", "gl_EyePlaneQ", "gl_ObjectPlaneS", "gl_ObjectPlaneT", "gl_ObjectPlaneR", "gl_ObjectPlaneQ",
"gl_FogParameters", "gl_Fog", "gl_MaxLights", "gl_MaxClipPlanes", "gl_MaxTextureUnits",
"gl_MaxTextureCoords", "gl_MaxVertexAttribs", "gl_MaxVertexUniformComponents", "gl_MaxVaryingFloats",
"gl_MaxVectexTextureImageUnits", "gl_MaxTextureImageUnits", "gl_MaxFragmentUniformComponents",
"gl_MaxCombinedTextureImageUnits", "gl_ClipDistance", "gl_FragData", "gl_GlobalInvocationID", "gl_in",
"gl_InstanceID", "gl_InvocationID", "gl_Layer", "gl_LightModelParameters", "gl_LocalInvocationID",
"gl_LocalInvocationIndex", "gl_MaxCombinedTextureImageUnits", "gl_MaxDrawBuffers", "gl_MaxPatchVertices",
"gl_MaxVertexTextureImageUnits", "gl_ModelViewMatrixInverse", "gl_ModelViewMatrixInverseTranspose",
"gl_ModelViewMatrixTranspose", "gl_ModelViewProjectionMatrixInverse",
"gl_ModelViewProjectionMatrixInverseTranspose", "gl_ModelViewProjectionMatrixTranspose", "gl_NumSamples",
"gl_NumWorkGroups", "gl_out", "gl_PatchVerticesIn", "gl_PrimitiveID", "gl_PrimitiveIDIn", "gl_PointCoord",
"gl_ProjectionMatrixInverse", "gl_ProjectionMatrixInverseTranspose", "gl_ProjectionMatrixTranspose",
"gl_SampleID", "gl_SampleMaskIn", "gl_SamplePosition", "gl_TessCoord", "gl_TessLevelInner",
"gl_TessLevelOuter", "gl_TextureMatrixInverse", "gl_TextureMatrixInverseTranspose",
"gl_TextureMatrixTranspose", " gl_ViewportIndex", "gl_WorkGroupID", "gl_WorkGroupSize" };

static final String semantics[] = { "gl_ModelViewMatrix",
"gl_ProjectionMatrix", "gl_ModelViewProjectionMatrix",
"gl_NormalMatrix", "gl_TextureMatrix", "gl_NormalScale",
"gl_DepthRangeParameters", "gl_DepthRange", "gl_ClipPlane",
"gl_PointParameters", "gl_Point", "gl_MaterialParameters",
"gl_FrontMaterial", "gl_BackMaterial", "gl_LightSourceParameters",
"gl_LightSource", "gl_LightModelParamters", "gl_LightModel",
"gl_LightModelProducts", "gl_FrontLightModelProduct",
"gl_BackLightModelProduct", "gl_LightProducts",
"gl_FrontLightProduct", "gl_BackLightProduct",
"gl_TextureEnvColor", "gl_EyePlaneS", "gl_EyePlaneT",
"gl_EyePlaneR", "gl_EyePlaneQ", "gl_ObjectPlaneS",
"gl_ObjectPlaneT", "gl_ObjectPlaneR", "gl_ObjectPlaneQ",
"gl_FogParameters", "gl_Fog", "gl_MaxLights", "gl_MaxClipPlanes",
"gl_MaxTextureUnits", "gl_MaxTextureCoords", "gl_MaxVertexAttribs",
"gl_MaxVertexUniformComponents", "gl_MaxVaryingFloats",
"gl_MaxVectexTextureImageUnits", "gl_MaxTextureImageUnits",
"gl_MaxFragmentUniformComponents",
"gl_MaxCombinedTextureImageUnits" };

/**
*
*/
private static String[] load(final Properties property, final String name, final String[] defVal) {
final String str = property.getProperty(name);
String[] ret = str != null ? str.split(",") : defVal;
for(int i = 0; i < ret.length; i++) {
ret[i] = ret[i].trim();
}
return ret;
}

public GLSLScanner() {
super();

final Properties property = new Properties();
InputStream is = getClass().getClassLoader().getResourceAsStream("/cgEditor/editors/config.properties");
if ( is != null ) {
try {
property.load(is);
} catch (final IOException e) {
e.printStackTrace();
}
try {
is.close();
} catch (final IOException e) {
e.printStackTrace();
}
}

super.language = GLSLScanner.language;
super.types = GLSLScanner.types;
super.functions = GLSLScanner.functions;
super.semantics = GLSLScanner.semantics;
super.language = load(property, "language", GLSLScanner.language);
super.types = load(property, "types", GLSLScanner.types);
super.functions = load(property, "functions", GLSLScanner.functions);
super.semantics = load(property, "semantics", GLSLScanner.semantics);
}

}
77 changes: 65 additions & 12 deletions GLShaderEditors/src/cgEditor/editors/ShaderFileConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,91 @@
*/
package cgEditor.editors;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITypedRegion;
import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.presentation.IPresentationReconciler;
import org.eclipse.jface.text.presentation.PresentationReconciler;
import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
import org.eclipse.jface.text.rules.IPredicateRule;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.ITokenScanner;
import org.eclipse.jface.text.rules.MultiLineRule;
import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewerConfiguration;
import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;

import cgEditor.preferences.PreferenceConstants;

/**
* @author Martinez
*
*/
public abstract class ShaderFileConfiguration extends SourceViewerConfiguration {
public abstract class ShaderFileConfiguration extends TextSourceViewerConfiguration {

public ShaderFileScanner scanner;
/**
*
*/

public ShaderFileConfiguration() {
super();
// TODO Auto-generated constructor stub
}

@Override
public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
return new String[] {
IDocument.DEFAULT_CONTENT_TYPE,
PreferenceConstants.COMMENTSTRING,
PreferenceConstants.DEFAULTSTRING,
PreferenceConstants.LANGUAGESSTRING,
PreferenceConstants.FUNCTIONSSTRING,
PreferenceConstants.TYPESSTRING,
PreferenceConstants.SEMANTICSSTRING
};
}

private class MyTagDamagerRepairer extends DefaultDamagerRepairer {

public MyTagDamagerRepairer(ITokenScanner scanner) {
super(scanner);
}

// TODO This method works with 3.0 and 3.1.2 but does't work well with Eclipse 3.1.1.
public IRegion getDamageRegion(ITypedRegion partition, DocumentEvent e, boolean documentPartitioningChanged) {
if (!documentPartitioningChanged) {
String source = fDocument.get();
int start = source.substring(0, e.getOffset()).lastIndexOf("/*");
if(start == -1){
start = 0;
}
int end = source.indexOf("*/", e.getOffset());
int end2 = e.getOffset() + (e.getText() == null ? e.getLength() : e.getText().length());
if(end == -1){
end = source.length();
} else if(end2 > end){
end = end2;
} else {
end+=2;
}

return new Region(start, end - start);
}
return partition;
}

}

@Override
public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
PresentationReconciler reconciler = new PresentationReconciler();
DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getTagScanner());
DefaultDamagerRepairer dr = new MyTagDamagerRepairer(getTagScanner());
reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
return reconciler;
}

protected abstract ShaderFileScanner getTagScanner();
}


protected abstract ShaderFileScanner getTagScanner();
}
Loading

0 comments on commit f015eb1

Please sign in to comment.