Skip to content

Commit

Permalink
feature: improve highlighting for keywords (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
levivilet authored Jan 15, 2024
1 parent 9fceb5f commit 8b530de
Show file tree
Hide file tree
Showing 6 changed files with 604 additions and 9 deletions.
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
"test-tokenize": {
"skip": [
"number",
"elm-spa-api-endpoint",
"elm-spa-api",
"elm-spa-article-body",
Expand All @@ -34,18 +35,15 @@
"elm-spa-article",
"elm-spa-asset",
"elm-spa-author",
"elm-spa-avatar",
"elm-spa-commentid",
"elm-spa-email",
"elm-spa-loading",
"elm-spa-main",
"elm-spa-page-article-editor",
"elm-spa-page-article",
"elm-spa-page-blank",
"elm-spa-page-home",
"elm-spa-page-profile",
"elm-spa-page-login",
"elm-spa-page-notfound",
"elm-spa-page-profile",
"elm-spa-page-register",
"elm-spa-page-settings",
"elm-spa-page",
Expand Down
7 changes: 2 additions & 5 deletions src/tokenizeElm.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const RE_LINE_COMMENT = /^\-\-[^\n]*/
const RE_BLOCK_COMMENT_START = /^\{\-/
const RE_BLOCK_COMMENT_END = /^\-\}/
const RE_BLOCK_COMMENT_CONTENT = /^.+(?=\-\})/s
const RE_PUNCTUATION = /^[\(\)\[\]\-\>\.\,\|\=]+/
const RE_PUNCTUATION = /^[\(\)\[\]\-\>\.\,\|\=\{\}\_,;\:\"\'\+\-]+/
const RE_WORD_ALIAS = /^alias/
const RE_ANYTHING_UNTIL_END = /^.+/s

Expand Down Expand Up @@ -180,13 +180,10 @@ export const tokenizeLine = (line, lineState) => {
token = TokenType.KeywordImport
state = State.AfterKeywordModule
break
case 'port':
case 'as':
default:
token = TokenType.Keyword
state = State.TopLevelContent
break
default:
throw new Error('no')
}
break
case State.AfterKeywordType:
Expand Down
300 changes: 300 additions & 0 deletions test/baselines/elm-spa-avatar.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,300 @@
KeywordImport
Whitespace
VariableName
Whitespace
KeywordImport
Whitespace
Punctuation
VariableName
Punctuation
Whitespace
VariableName
Punctuation
Whitespace
VariableName
Punctuation
Whitespace
VariableName
Punctuation
Whitespace
VariableName
Punctuation
NewLine
NewLine
KeywordImport
Whitespace
VariableName
NewLine
KeywordImport
Whitespace
VariableName
Whitespace
KeywordImport
Whitespace
Punctuation
VariableName
Punctuation
NewLine
KeywordImport
Whitespace
VariableName
Punctuation
VariableName
NewLine
KeywordImport
Whitespace
VariableName
Punctuation
VariableName
Whitespace
Keyword
Whitespace
VariableName
Whitespace
KeywordImport
Whitespace
Punctuation
VariableName
Punctuation
NewLine
KeywordImport
Whitespace
VariableName
Punctuation
VariableName
Whitespace
Keyword
Whitespace
VariableName
Whitespace
KeywordImport
Whitespace
Punctuation
VariableName
Punctuation
NewLine
NewLine
NewLine
NewLine
Comment
NewLine
NewLine
NewLine
Keyword
Whitespace
Type
NewLine
Whitespace
Punctuation
Whitespace
Type
Whitespace
Punctuation
Type
Whitespace
Type
Punctuation
NewLine
NewLine
NewLine
NewLine
Comment
NewLine
NewLine
NewLine
VariableName
Whitespace
Punctuation
Whitespace
Type
Whitespace
Type
NewLine
Type
Whitespace
Punctuation
NewLine
Whitespace
Type
Punctuation
Type
Whitespace
Type
Whitespace
Punctuation
Type
Punctuation
Type
Whitespace
Type
Punctuation
Type
Punctuation
NewLine
NewLine
NewLine
NewLine
Punctuation
Whitespace
Type
NewLine
NewLine
NewLine
Type
Whitespace
Punctuation
Whitespace
Type
Whitespace
Punctuation
Whitespace
Type
NewLine
Type
Whitespace
Punctuation
Type
Whitespace
Type
Punctuation
Whitespace
Punctuation
NewLine
Whitespace
Type
Whitespace
Type
Whitespace
Type
NewLine
Whitespace
Type
Whitespace
Type
Whitespace
Punctuation
NewLine
Whitespace
Type
Punctuation
Type
Whitespace
Type
NewLine
NewLine
Whitespace
Type
Whitespace
Punctuation
NewLine
Whitespace
Type
Punctuation
Type
NewLine
NewLine
NewLine
Type
Whitespace
Punctuation
Whitespace
Type
Whitespace
Punctuation
Whitespace
Type
Whitespace
Type
NewLine
Type
Whitespace
Punctuation
Type
Whitespace
Type
Punctuation
Whitespace
Punctuation
NewLine
Whitespace
Type
Whitespace
Type
Whitespace
Type
NewLine
Whitespace
Type
Whitespace
Punctuation
NewLine
Whitespace
Type
Punctuation
Type
Whitespace
Type
Punctuation
Type
NewLine
NewLine
Whitespace
Type
Whitespace
Punctuation
Whitespace
Punctuation
NewLine
Whitespace
Type
Punctuation
Type
Whitespace
Type
Punctuation
Type
NewLine
NewLine
Whitespace
Type
Whitespace
Type
Whitespace
Punctuation
NewLine
Whitespace
Type
Punctuation
Type
Punctuation
Type
Whitespace
Type
NewLine
NewLine
NewLine
Type
Whitespace
Punctuation
Whitespace
Type
Whitespace
Punctuation
Whitespace
Type
Whitespace
Type
NewLine
Type
Whitespace
Punctuation
Type
Whitespace
Type
Punctuation
Whitespace
Punctuation
NewLine
Whitespace
Type
NewLine
Loading

0 comments on commit 8b530de

Please sign in to comment.