diff --git a/src/glslplugin/annotation/impl/UnreachableAnnotation.java b/src/glslplugin/annotation/impl/UnreachableAnnotation.java index a8a7e66b..ca1c70dd 100755 --- a/src/glslplugin/annotation/impl/UnreachableAnnotation.java +++ b/src/glslplugin/annotation/impl/UnreachableAnnotation.java @@ -29,6 +29,7 @@ import glslplugin.annotation.Annotator; import glslplugin.lang.elements.GLSLElement; import glslplugin.lang.elements.GLSLElementTypes; +import glslplugin.lang.elements.GLSLTokenTypes; import glslplugin.lang.elements.statements.*; import org.jetbrains.annotations.NotNull; @@ -50,7 +51,7 @@ public void annotate(GLSLStatement expr, AnnotationHolder holder) { PsiElement element = expr.getNextSibling(); while (element != null) { - if (element instanceof GLSLElement && element.getNode().getElementType() != GLSLElementTypes.PREPROCESSOR_DIRECTIVE) { + if (element instanceof GLSLElement && !GLSLTokenTypes.PREPROCESSOR_DIRECTIVES.contains(element.getNode().getElementType())) { if (element instanceof GLSLLabelStatement) return; PsiElement child = element.getFirstChild(); @@ -60,7 +61,7 @@ public void annotate(GLSLStatement expr, AnnotationHolder holder) { }else{ do { IElementType type = child.getNode().getElementType(); - if(type != GLSLElementTypes.PREPROCESSOR_DIRECTIVE && type != TokenType.WHITE_SPACE){ + if(!GLSLTokenTypes.PREPROCESSOR_DIRECTIVES.contains(type) && type != TokenType.WHITE_SPACE){ if (child instanceof GLSLLabelStatement) return; Annotation annotation = holder.createWarningAnnotation(child, "Unreachable expression"); annotation.setTextAttributes(unreachableAttributes); diff --git a/src/glslplugin/lang/elements/GLSLElementTypes.java b/src/glslplugin/lang/elements/GLSLElementTypes.java index 9adc3d1d..589ddddb 100755 --- a/src/glslplugin/lang/elements/GLSLElementTypes.java +++ b/src/glslplugin/lang/elements/GLSLElementTypes.java @@ -23,12 +23,10 @@ import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.IFileElementType; import glslplugin.lang.GLSLLanguage; -import glslplugin.lang.elements.expressions.GLSLLiteral; public class GLSLElementTypes { public static final IFileElementType FILE = new IFileElementType(Language.findInstance(GLSLLanguage.class)); - public static final IElementType PREPROCESSOR_DIRECTIVE = new GLSLElementType("PREPROCESSOR_DIRECTIVE"); //Workaround before proper text redefinition of remapped tokens is implemented, see RedefinedTokenElementType below //public static final IElementType REDEFINED_TOKEN = new GLSLElementType("REDEFINED_TOKEN"); diff --git a/src/glslplugin/lang/elements/GLSLTokenTypes.java b/src/glslplugin/lang/elements/GLSLTokenTypes.java index 6f7c5798..e017c3af 100755 --- a/src/glslplugin/lang/elements/GLSLTokenTypes.java +++ b/src/glslplugin/lang/elements/GLSLTokenTypes.java @@ -207,6 +207,9 @@ public class GLSLTokenTypes { public static final IElementType PREPROCESSOR_CONCAT = new GLSLElementType("PREPROCESSOR_CONCAT"); public static final IElementType PREPROCESSOR_STRING = new GLSLElementType("PREPROCESSOR_STRING"); + /** Not returned by lexer but used instead of PREPROCESSOR_[something] when the kind of directive is unknown */ + public static final IElementType PREPROCESSOR_OTHER = new GLSLElementType("PREPROCESSOR_OTHER"); + public static final IElementType RESERVED_KEYWORD = new GLSLElementType("RESERVED_KEYWORD"); public static final TokenSet PREPROCESSOR_DIRECTIVES = TokenSet.create( @@ -226,7 +229,8 @@ public class GLSLTokenTypes { PREPROCESSOR_VERSION, PREPROCESSOR_LINE, PREPROCESSOR_DEFINED, - PREPROCESSOR_CONCAT); + PREPROCESSOR_CONCAT, + PREPROCESSOR_OTHER); // Type specifiers public static final TokenSet FLOAT_TYPE_SPECIFIER_NONARRAY = TokenSet.create( @@ -353,7 +357,6 @@ public class GLSLTokenTypes { QUALIFIER_TOKENS, EXPRESSION_FIRST_SET ); - public static final TokenSet FUNCTION_IDENTIFIER_TOKENS = merge(TokenSet.create(IDENTIFIER), TYPE_SPECIFIER_NONARRAY_TOKENS); public static TokenSet merge(TokenSet... sets) { TokenSet tokenSet = TokenSet.create(); diff --git a/src/glslplugin/lang/parser/GLSLParsing.java b/src/glslplugin/lang/parser/GLSLParsing.java index 885a26d9..a0841475 100755 --- a/src/glslplugin/lang/parser/GLSLParsing.java +++ b/src/glslplugin/lang/parser/GLSLParsing.java @@ -82,9 +82,9 @@ protected final void parsePreprocessor() { //false -> this is not a valid place for more preprocessor directives //false -> don't substitute here (makes re"define"ing and "undef"ing impossible) - IElementType preprocessorType = b.getTokenType(); + IElementType directiveType = b.getTokenType(); - if(b.getTokenType() == PREPROCESSOR_DEFINE){ + if(directiveType == PREPROCESSOR_DEFINE){ //Parse define b.advanceLexer(false, false);//Get past DEFINE @@ -120,7 +120,7 @@ protected final void parsePreprocessor() { b.advanceLexer(); } } - }else if(b.getTokenType() == PREPROCESSOR_UNDEF){ + }else if(directiveType == PREPROCESSOR_UNDEF){ //Parse undefine b.advanceLexer(false, false);//Get past UNDEF @@ -155,7 +155,13 @@ protected final void parsePreprocessor() { } b.advanceLexer(false, false);//Get past PREPROCESSOR_END //false -> don't check for PREPROCESSOR_BEGIN, we will handle that ourselves - preprocessor.done(preprocessorType); + if(directiveType == null || !PREPROCESSOR_DIRECTIVES.contains(directiveType)){ + //Happens when typing new directive at the end of the file + //or when malformed directive is created (eg #foo) + preprocessor.done(PREPROCESSOR_OTHER); + }else{ + preprocessor.done(directiveType); + } b.advanceLexer_remapTokens(); //Remap explicitly after advancing without remapping, makes mess otherwise if (b.getTokenType() == PREPROCESSOR_BEGIN) {