Skip to content

Commit

Permalink
feature: improve highlighting for structs (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
levivilet authored Jul 28, 2023
1 parent be81d89 commit efde08c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
22 changes: 22 additions & 0 deletions src/tokenizeWgsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
export const State = {
TopLevelContent: 1,
AfterKeywordDeclaration: 2,
AfterKeywordStruct: 3,
}

/**
Expand Down Expand Up @@ -153,6 +154,10 @@ export const tokenizeLine = (line, lineState) => {
token = TokenType.Type
state = State.TopLevelContent
break
case 'struct':
token = TokenType.Keyword
state = State.AfterKeywordStruct
break
default:
token = TokenType.Keyword
state = State.TopLevelContent
Expand Down Expand Up @@ -189,6 +194,23 @@ export const tokenizeLine = (line, lineState) => {
throw new Error('no')
}
break
case State.AfterKeywordStruct:
if ((next = part.match(RE_WHITESPACE))) {
token = TokenType.Whitespace
state = State.AfterKeywordStruct
} else if ((next = part.match(RE_PUNCTUATION))) {
token = TokenType.Punctuation
state = State.TopLevelContent
} else if ((next = part.match(RE_VARIABLE_NAME))) {
token = TokenType.Type
state = State.TopLevelContent
} else if ((next = part.match(RE_ANYTHING))) {
token = TokenType.Unknown
state = State.TopLevelContent
} else {
throw new Error('no')
}
break
default:
throw new Error('no')
}
Expand Down
2 changes: 1 addition & 1 deletion test/baselines/struct.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Keyword
Whitespace
VariableName
Type
Whitespace
Punctuation
NewLine
Expand Down
8 changes: 4 additions & 4 deletions test/baselines/vscode-wgsl-test.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Keyword
Whitespace
VariableName
Type
Whitespace
Punctuation
NewLine
Expand Down Expand Up @@ -54,7 +54,7 @@ NewLine
NewLine
Keyword
Whitespace
VariableName
Type
Whitespace
Punctuation
NewLine
Expand All @@ -80,7 +80,7 @@ NewLine
NewLine
Keyword
Whitespace
VariableName
Type
Punctuation
NewLine
Whitespace
Expand Down Expand Up @@ -153,7 +153,7 @@ NewLine
NewLine
Keyword
Whitespace
VariableName
Type
Whitespace
Punctuation
NewLine
Expand Down

0 comments on commit efde08c

Please sign in to comment.