Skip to content

Commit

Permalink
vscode: Improve regex-based highlighting
Browse files Browse the repository at this point in the history
Do not match keywords in identifiers and update the easing types while
at it.

Fixes: slint-ui#2762
  • Loading branch information
hunger committed Jan 26, 2024
1 parent 6a79867 commit ea81f6b
Showing 1 changed file with 172 additions and 13 deletions.
185 changes: 172 additions & 13 deletions editors/vscode/slint.tmLanguage.json
Original file line number Diff line number Diff line change
@@ -13,32 +13,153 @@
"include": "#general"
},
{
"match": "\\b(import|from|export|struct|enum|global|component|inherits)\\b",
"match": "(?<!-)\\b(from|export)\\b(?!-)",
"name": "keyword"
},
{
"match": "\\b(property|callback|animate|states|transitions|private|public|pure|function|in|out|in-out)\\b",
"match": "(?<!-)\\b(animate|states|transitions|private|public|pure|function|in|out|in-out)\\b(?!-)",
"name": "keyword.other"
},
{
"match": "\\b(if|for|return)\\b",
"match": "(?<!-)\\b(if|for|return)\\b(?!-)",
"name": "keyword.control"
},
{
"match": "\\b(root|parent|this|self)\\b",
"match": "(?<!-)\\b(root|parent|this|self)\\b(?!-)",
"name": "variable.language"
},
{
"match": "[a-zA-Z_][a-zA-Z_\\-0-9]* *:",
"name": "variable.parameter"
"match": "(?<!-)\\b(import)\\s*\\{\\s*(([a-zA-Z_][a-zA-Z0-9_-]*)(\\s*,\\s*([a-zA-Z_][a-zA-Z0-9_-]*))*)\\s*\\}",
"captures": {
"1": {
"name": "keyword.other"
},
"3": {
"name": "storage.type"
},
"5": {
"name": "storage.type"
}
}
},
{
"match": "(?<!-)\\b([a-zA-Z_][a-zA-Z0-9_-]*)\\s*:",
"captures": {
"1": {
"name": "variable.language"
}
}
},
{
"match": "(?<!-)\\b([a-zA-Z_][a-zA-Z0-9_-]*)\\s*\\(.*\\)\\s*=>",
"captures": {
"1": {
"name": "support.function"
}
}
},
{
"match": "[a-zA-Z_][a-zA-Z_\\-0-9]* *:=",
"name": "storage.type"
"match": "(?<!-)\\b(callback)\\s+([a-zA-Z_][a-zA-Z0-9_-]*)\\s*",
"captures": {
"1": {
"name": "support.function"
},
"2": {
"name": "storage.type"
}
}
},
{
"match": "\\b(blue|red|green|yellow|red|black|ease|ease_in|ease_out|ease_in_out)\\b",
"begin": "(?<!-)\\b(struct)\\s+([a-zA-Z_][a-zA-Z0-9_-]*)\\s*\\{",
"end": "\\}",
"beginCaptures": {
"1": {
"name": "keyword.other"
},
"2": {
"name": "storage.type"
}
},
"patterns": [
{
"match": "([a-zA-Z_][a-zA-Z0-9_-]*)\\s*:\\s*([a-zA-Z_][a-zA-Z0-9_-]*)\\s*,?",
"captures": {
"1": {
"name": "variable.parameter"
},
"2": {
"name": "storage.type"
}
}
}
]
},
{
"begin": "(?<!-)\\b(global)\\s+([a-zA-Z_][a-zA-Z0-9_-]*)\\s*\\{",
"end": "\\}",
"beginCaptures": {
"1": {
"name": "keyword.other"
},
"2": {
"name": "storage.type"
}
},
"patterns": [
{
"include": "#property"
}
]
},
{
"begin": "(?<!-)\\b(enum)\\s+([a-zA-Z_][a-zA-Z0-9_-]*)\\s*\\{",
"end": "\\}",
"beginCaptures": {
"1": {
"name": "keyword.other"
},
"2": {
"name": "storage.type"
}
},
"patterns": [
{
"match": "([a-zA-Z_][a-zA-Z0-9_-]*)\\s*,?",
"name": "storage.type"
}
]
},
{
"match": "(?<!-)\\b(component|inherits)\\s+([a-zA-Z_][a-zA-Z0-9_-]*)",
"captures": {
"1": {
"name": "keyword.control"
},
"2": {
"name": "storage.type"
}
}
},
{
"match": "([a-zA-Z_][a-zA-Z0-9_-])*\\s*(:=)\\s*([a-zA-Z_][a-zA-Z0-9_-]*)",
"captures": {
"1": {
"name": "variable.parameter"
},
"2": {
"name": "keyword.operator"
},
"3": {
"name": "storage.type"
}
}
},
{
"match": "(?<!-)\\b(blue|red|green|yellow|red|black|linear|ease-in-quad|ease-out-quad|ease-in-out-quad|ease|ease-in|ease-out|ease-in-out|ease-in-quart|ease-out-quart|ease-in-out-quart|ease-in-quint|ease-out-quint|ease-in-out-quint|ease-in-expo|ease-out-expo|ease-in-out-expo|ease-in-sine|ease-out-sine|ease-in-out-sine|ease-in-back|ease-out-back|ease-in-out-back|ease-in-circ|ease-out-circ|ease-in-out-circ|ease-in-elastic|ease-out-elastic|ease-in-out-elastic|ease-in-bounce|ease-out-bounce|ease-in-out-bounce|cubic-bezier)\\b(?!-)",
"name": "support.constant"
},
{
"include": "#property"
}
]
},
@@ -52,19 +173,57 @@
"name": "comment.line"
},
{
"match": "\"[^\"]*\"",
"name": "string"
"name": "string.quoted.double",
"begin": "\"",
"end": "\"",
"patterns": [
{
"name": "constant.character.escape.untitled",
"match": "\\\\(n|\\\\|u\\{\\d+\\}|\\{[^\\}]+\\})"
}
]
},
{
"match": "\\b#[0-9a-fA-F]+",
"match": "#([a-fA-F0-9]){3,8}",
"name": "constant.other"
},
{
"match": "\\b\\d+(\\.\\d+)?\\w*",
"match": "\\b\\d+(\\.\\d*)?(%|px|phx|pt|in|mm|cm|ms|s|deg|rad|turn)?\\b",
"name": "constant.numeric"
}
]
},
"property": {
"patterns": [
{
"begin": "\\b(property)\\b",
"end": ";",
"beginCaptures": {
"1": {
"name": "keyword.other"
}
},
"patterns": [
{
"match": "<([a-zA-Z_][a-zA-Z0-9_-]*)>",
"captures": {
"1": {
"name": "storage.type"
}
}
},
{
"match": "[a-zA-Z_][a-zA-Z0-9_-]*",
"name": "variable.parameter"
},
{
"match": "\\b(<=>|:)\\b",
"name": "keyword.operator"
}
]
}
]
},
"block-comments": {
"patterns": [
{

0 comments on commit ea81f6b

Please sign in to comment.