Skip to content

Commit

Permalink
#78 - added support for array literals
Browse files Browse the repository at this point in the history
  • Loading branch information
dparnell committed Nov 16, 2024
1 parent b4be88f commit 52c22d0
Show file tree
Hide file tree
Showing 7 changed files with 1,116 additions and 1,081 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# wgsl plugin Changelog

## Unreleased
- support array literals

## 0.0.34 - 2024-10-26

Expand Down
4 changes: 3 additions & 1 deletion examples/ticket_78.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ fn vs_main(@builtin(vertex_index) in_vertex_index: u32) -> Vertex {
@fragment
fn fs_main(in: Vertex) -> @location(0) vec4f {
return vec4(1.0, 0.0, 0.0, 1.0);
}
}

const pos = array(vec2f(0, -1), vec2f(1, -1), vec2f(0, 0), vec2f(1, 0));
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
pluginGroup = wgslplugin
pluginName = wgsl
# SemVer format -> https://semver.org
pluginVersion = 0.0.34
pluginVersion = 0.0.35

# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
Expand Down
2,150 changes: 1,084 additions & 1,066 deletions src/main/gen/wgslplugin/language/_WgslLexer.java

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions src/main/gen/wgslplugin/language/parser/WgslParser.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 14 additions & 9 deletions src/main/java/wgslplugin/language/WGSLLexer.flex
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import static wgslplugin.language.psi.WGSLTypes.*;
%type IElementType
%unicode

%state ARRAY_SPEC
%state TYPE_SPEC
%state BIND_SPEC
%state ATTRIBUTE
Expand Down Expand Up @@ -76,15 +77,16 @@ IDENT = ([a-zA-Z_][0-9a-zA-Z_][0-9a-zA-Z_]*)|([a-zA-Z][0-9a-zA-Z_]*)
<YYINITIAL, ATTRIBUTE> "true" { return TRUE; }
<YYINITIAL, ATTRIBUTE> "false" { return FALSE; }
<YYINITIAL, ATTRIBUTE> {DECIMAL_FLOAT_LITERAL} { return DECIMAL_FLOAT_LITERAL; }
<YYINITIAL, ATTRIBUTE> {HEX_FLOAT_LITERAL} { return HEX_FLOAT_LITERAL; }
<YYINITIAL> "[[" { pushState(ATTRIBUTE); return ATTR_LEFT; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC, ATTRIBUTE> "," { return COMMA; }
<ATTRIBUTE> "]]" { popState(); return ATTR_RIGHT; }
<YYINITIAL, ATTRIBUTE> "(" { return PAREN_LEFT; }
<TYPE_SPEC> "(" { popState(); return PAREN_LEFT; }
<YYINITIAL, ATTRIBUTE> ")" { return PAREN_RIGHT; }
<YYINITIAL, TYPE_SPEC> "array" { pushState(TYPE_SPEC); return ARRAY; }
<YYINITIAL> "<" { return LESS_THAN; }
<YYINITIAL, ATTRIBUTE> {HEX_FLOAT_LITERAL} { return HEX_FLOAT_LITERAL; }
<YYINITIAL> "[[" { pushState(ATTRIBUTE); return ATTR_LEFT; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC, ATTRIBUTE> "," { return COMMA; }
<ATTRIBUTE> "]]" { popState(); return ATTR_RIGHT; }
<YYINITIAL, ATTRIBUTE> "(" { return PAREN_LEFT; }
<TYPE_SPEC> "(" { popState(); return PAREN_LEFT; }
<YYINITIAL, ATTRIBUTE> ")" { return PAREN_RIGHT; }
<YYINITIAL> "array" { pushState(ARRAY_SPEC); return ARRAY; }
<TYPE_SPEC> "array" { pushState(TYPE_SPEC); return ARRAY; }
<YYINITIAL> "<" { return LESS_THAN; }
<TYPE_SPEC, BIND_SPEC> "<" { return TYPE_LESS_THAN; }
<YYINITIAL> ">" { return GREATER_THAN; }
<TYPE_SPEC, BIND_SPEC> ">" { popState(); return TYPE_GREATER_THAN; }
Expand All @@ -94,6 +96,9 @@ IDENT = ([a-zA-Z_][0-9a-zA-Z_][0-9a-zA-Z_]*)|([a-zA-Z][0-9a-zA-Z_]*)
<YYINITIAL> ";" { return SEMICOLON; }
<YYINITIAL> "@" { return AT; }

<ARRAY_SPEC> "(" { popState(); return PAREN_LEFT; }
<ARRAY_SPEC> "<" { popState(); pushState(TYPE_SPEC); return TYPE_LESS_THAN; }

<PREPROCESSOR, PREPROCESSOR_NESTED> "{" { pushState(PREPROCESSOR_NESTED); return PREPROCESSOR_DECLARATION; }
<PREPROCESSOR, PREPROCESSOR_NESTED> "}" { popState(); return PREPROCESSOR_DECLARATION; }

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/wgslplugin/language/wgsl.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ const_expression ::=
primary_expression ::=
func_call_statement
| variable_reference
| type_decl argument_expression_list
| (type_decl | ARRAY) argument_expression_list
| const_literal
| paren_expression
| BITCAST TYPE_LESS_THAN type_decl TYPE_GREATER_THAN paren_expression
Expand Down

0 comments on commit 52c22d0

Please sign in to comment.