Skip to content

Commit

Permalink
Add parsing support for strings, closes #164
Browse files Browse the repository at this point in the history
Took 37 minutes
  • Loading branch information
Jan Polák committed Apr 5, 2022
1 parent b2a59ea commit 63e7147
Show file tree
Hide file tree
Showing 4 changed files with 1,605 additions and 1,301 deletions.
6 changes: 4 additions & 2 deletions src/main/java/glslplugin/lang/elements/GLSLTokenTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class GLSLTokenTypes {
public static final IElementType FLOAT_CONSTANT = new GLSLElementType("FLOAT_CONSTANT");
public static final IElementType DOUBLE_CONSTANT = new GLSLElementType("DOUBLE_CONSTANT");
public static final IElementType BOOL_CONSTANT = new GLSLElementType("BOOL_CONSTANT");
/** As specified in https://github.com/KhronosGroup/GLSL/blob/master/extensions/ext/GLSL_EXT_debug_printf.txt */
public static final IElementType STRING_CONSTANT = new GLSLElementType("STRING_CONSTANT");

public static final IElementType VOID_TYPE = new GLSLElementType("VOID_TYPE");
public static final IElementType FLOAT_TYPE = new GLSLElementType("FLOAT_TYPE");
Expand Down Expand Up @@ -339,10 +341,10 @@ public class GLSLTokenTypes {
BIT_WISE_OPERATORS, LOGICAL_OPERATORS, ASSIGNMENT_OPERATORS);

public static final TokenSet CONSTANT_TOKENS = TokenSet.create(
BOOL_CONSTANT, INTEGER_CONSTANT, UINT_CONSTANT, FLOAT_CONSTANT, DOUBLE_CONSTANT);
BOOL_CONSTANT, INTEGER_CONSTANT, UINT_CONSTANT, FLOAT_CONSTANT, DOUBLE_CONSTANT, STRING_CONSTANT);

public static final TokenSet EXPRESSION_FIRST_SET = merge(TokenSet.create(
INTEGER_CONSTANT, FLOAT_CONSTANT, BOOL_CONSTANT, // constants
INTEGER_CONSTANT, FLOAT_CONSTANT, BOOL_CONSTANT, STRING_CONSTANT, // constants
INC_OP, DEC_OP, PLUS, DASH, BANG, TILDE, // unary operators
IDENTIFIER, // function call, variable name, typename
LEFT_PAREN, // group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,20 @@ public enum Type {
FLOAT("Float", GLSLTypes.FLOAT),
DOUBLE("Double", GLSLTypes.DOUBLE),
INTEGER("Integer", GLSLTypes.INT),
UINT("Unsigned integer", GLSLTypes.UINT);
UINT("Unsigned integer", GLSLTypes.UINT),
// https://github.com/KhronosGroup/GLSL/blob/master/extensions/ext/GLSL_EXT_debug_printf.txt
// does not define any GLSL type, just the literal.
STRING("String", null),
;


Type(String name, GLSLType type) {
Type(String name, @Nullable GLSLType type) {
this.textRepresentation = name;
this.type = type;
}

final String textRepresentation;
@Nullable
final GLSLType type;
}

Expand All @@ -63,7 +68,7 @@ public Type getLiteralType() {
IElementType type = getNode().getFirstChildNode().getElementType();

Type result = getLiteralType(type);
if(result != null)return result;
if(result != null) return result;

Logger.getLogger("GLSLLiteral").warning("Unsupported literal type. ("+type+")");
return null;
Expand All @@ -76,16 +81,17 @@ public static Type getLiteralType(IElementType type){
if (type == GLSLTokenTypes.UINT_CONSTANT) return Type.UINT;
if (type == GLSLTokenTypes.FLOAT_CONSTANT) return Type.FLOAT;
if (type == GLSLTokenTypes.DOUBLE_CONSTANT) return Type.DOUBLE;
if (type == GLSLTokenTypes.STRING_CONSTANT) return Type.STRING;
return null;
}

@NotNull
@Override
public GLSLType getType() {
Type literalType = getLiteralType();
if(literalType != null){
if (literalType != null && literalType.type != null) {
return literalType.type;
}else{
} else {
return GLSLTypes.UNKNOWN_TYPE;
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/glslplugin/lang/scanner/GLSL.flex
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ FLOATING_CONSTANT3 = ({DIGIT})+({EXPONENT_PART})
FLOATING_CONSTANT4 = ({DIGIT})+
EXPONENT_PART = [Ee]["+""-"]?({DIGIT})*

/* See https://github.com/KhronosGroup/GLSL/blob/master/extensions/ext/GLSL_EXT_debug_printf.txt */
STRING_CONSTANT = \"([^\"\\]|\\[\"\'?\\abfnrtv]|\\x{HEX_DIGIT}{HEX_DIGIT}?|\\{OCTAL_DIGIT}{OCTAL_DIGIT}?{OCTAL_DIGIT}?)*\"

LINE_COMMENT = "//"[^\r\n]*
BLOCK_COMMENT = "/*"([^"*"]|("*"+[^"*""/"]))*("*"+"/")?

Expand Down Expand Up @@ -319,6 +322,7 @@ using { return RESERVED_KEYWORD; }
{INTEGER_CONSTANT} {return INTEGER_CONSTANT; }
{FLOATING_CONSTANT}{DOUBLE_SUFFIX} {return DOUBLE_CONSTANT; }
{FLOATING_CONSTANT}{FLOAT_SUFFIX}? {return FLOAT_CONSTANT; }
{STRING_CONSTANT} {return STRING_CONSTANT; }
{LINE_COMMENT} {return COMMENT_LINE; }
{BLOCK_COMMENT} {return COMMENT_BLOCK; }
. {return UNKNOWN; }
Loading

0 comments on commit 63e7147

Please sign in to comment.