Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Luau.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@ fileTypes: [luau]

variables:
matchingParentheses: (\(([^\(\)]|(\(([^\(\)]|\([^\(\)]*\))*\)))*\))
lookAheadEndOfType: '(?=[),}\]](?!\s*[&|]))|(?=\s*;)|(?=\s*\b(?:break|const|continue|do|else|elseif|end|for|function|if|in|local|repeat|return|then|until|while)\b)|(?=^\s*$)|(?=^\s*(?:@|\b(?:export\s+)?type\b))|(?=^\s*{{identifier}}(?:\.{{identifier}})*\s*(?:(?:[+\-*/%^]|\.\.)?=(?!=)|\(|\[|:))'
identifier: "[a-zA-Z_][a-zA-Z0-9_]*"
# Arithmetic/comparison operators that are valid in expressions but cannot appear at the
# top level of a Luau type expression, so their presence signals the end of a type.
# Exclusions: -> (function return type arrow), -- (comment), ... (variadic pack)
nonTypeOperators: '[*+%^]|\/\/?|(?<!\.)\.\.(?!\.)|-(?![->`])|~=|=='
# Keywords that are valid outside a type expression (as binary operators or statement
# starters) but cannot appear within one, so their presence signals the end of a type.
nonTypeKeywords: 'and|or|break|const|continue|do|else|elseif|end|for|function|if|in|local|repeat|return|then|until|while'
lookAheadEndOfType: '(?=[),}\]](?!\s*[&|]))|(?=\s*;)|(?=\s*(?:{{nonTypeOperators}}))|(?=\s*\b(?:{{nonTypeKeywords}})\b)|(?=^\s*$)|(?=^\s*(?:@|\b(?:export\s+)?type\b))|(?=^\s*{{identifier}}(?:\.{{identifier}})*\s*(?:(?:[+\-*/%^]|\.\.)?=(?!=)|\(|\[|:))'

patterns:
- include: "#function-definition"
Expand Down
4 changes: 2 additions & 2 deletions Luau.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@
<key>begin</key>
<string>(?&lt;![^.]\.|:)\b(?:(export)\s+)?(type)\b(?=\s+(?!function\b)[a-zA-Z_][a-zA-Z0-9_]*)</string>
<key>end</key>
<string>(?=[),}\]](?!\s*[&amp;|]))|(?=\s*;)|(?=\s*\b(?:break|const|continue|do|else|elseif|end|for|function|if|in|local|repeat|return|then|until|while)\b)|(?=^\s*$)|(?=^\s*(?:@|\b(?:export\s+)?type\b))|(?=^\s*[a-zA-Z_][a-zA-Z0-9_]*(?:\.[a-zA-Z_][a-zA-Z0-9_]*)*\s*(?:(?:[+\-*/%^]|\.\.)?=(?!=)|\(|\[|:))</string>
<string>(?=[),}\]](?!\s*[&amp;|]))|(?=\s*;)|(?=\s*(?:[*+%^]|\/\/?|(?&lt;!\.)\.\.(?!\.)|-(?![-&gt;`])|~=|==))|(?=\s*\b(?:and|or|break|const|continue|do|else|elseif|end|for|function|if|in|local|repeat|return|then|until|while)\b)|(?=^\s*$)|(?=^\s*(?:@|\b(?:export\s+)?type\b))|(?=^\s*[a-zA-Z_][a-zA-Z0-9_]*(?:\.[a-zA-Z_][a-zA-Z0-9_]*)*\s*(?:(?:[+\-*/%^]|\.\.)?=(?!=)|\(|\[|:))</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
Expand Down Expand Up @@ -1173,7 +1173,7 @@
</dict>
</dict>
<key>end</key>
<string>(?=[),}\]](?!\s*[&amp;|]))|(?=\s*;)|(?=\s*\b(?:break|const|continue|do|else|elseif|end|for|function|if|in|local|repeat|return|then|until|while)\b)|(?=^\s*$)|(?=^\s*(?:@|\b(?:export\s+)?type\b))|(?=^\s*[a-zA-Z_][a-zA-Z0-9_]*(?:\.[a-zA-Z_][a-zA-Z0-9_]*)*\s*(?:(?:[+\-*/%^]|\.\.)?=(?!=)|\(|\[|:))</string>
<string>(?=[),}\]](?!\s*[&amp;|]))|(?=\s*;)|(?=\s*(?:[*+%^]|\/\/?|(?&lt;!\.)\.\.(?!\.)|-(?![-&gt;`])|~=|==))|(?=\s*\b(?:and|or|break|const|continue|do|else|elseif|end|for|function|if|in|local|repeat|return|then|until|while)\b)|(?=^\s*$)|(?=^\s*(?:@|\b(?:export\s+)?type\b))|(?=^\s*[a-zA-Z_][a-zA-Z0-9_]*(?:\.[a-zA-Z_][a-zA-Z0-9_]*)*\s*(?:(?:[+\-*/%^]|\.\.)?=(?!=)|\(|\[|:))</string>
<key>patterns</key>
<array>
<dict>
Expand Down
4 changes: 2 additions & 2 deletions Luau.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@
},
"type-alias-declaration": {
"begin": "(?<![^.]\\.|:)\\b(?:(export)\\s+)?(type)\\b(?=\\s+(?!function\\b)[a-zA-Z_][a-zA-Z0-9_]*)",
"end": "(?=[),}\\]](?!\\s*[&|]))|(?=\\s*;)|(?=\\s*\\b(?:break|const|continue|do|else|elseif|end|for|function|if|in|local|repeat|return|then|until|while)\\b)|(?=^\\s*$)|(?=^\\s*(?:@|\\b(?:export\\s+)?type\\b))|(?=^\\s*[a-zA-Z_][a-zA-Z0-9_]*(?:\\.[a-zA-Z_][a-zA-Z0-9_]*)*\\s*(?:(?:[+\\-*/%^]|\\.\\.)?=(?!=)|\\(|\\[|:))",
"end": "(?=[),}\\]](?!\\s*[&|]))|(?=\\s*;)|(?=\\s*(?:[*+%^]|\\/\\/?|(?<!\\.)\\.\\.(?!\\.)|-(?![->`])|~=|==))|(?=\\s*\\b(?:and|or|break|const|continue|do|else|elseif|end|for|function|if|in|local|repeat|return|then|until|while)\\b)|(?=^\\s*$)|(?=^\\s*(?:@|\\b(?:export\\s+)?type\\b))|(?=^\\s*[a-zA-Z_][a-zA-Z0-9_]*(?:\\.[a-zA-Z_][a-zA-Z0-9_]*)*\\s*(?:(?:[+\\-*/%^]|\\.\\.)?=(?!=)|\\(|\\[|:))",
"beginCaptures": {
"1": {
"name": "storage.modifier.visibility.luau"
Expand Down Expand Up @@ -771,7 +771,7 @@
"name": "keyword.operator.typecast.luau"
}
},
"end": "(?=[),}\\]](?!\\s*[&|]))|(?=\\s*;)|(?=\\s*\\b(?:break|const|continue|do|else|elseif|end|for|function|if|in|local|repeat|return|then|until|while)\\b)|(?=^\\s*$)|(?=^\\s*(?:@|\\b(?:export\\s+)?type\\b))|(?=^\\s*[a-zA-Z_][a-zA-Z0-9_]*(?:\\.[a-zA-Z_][a-zA-Z0-9_]*)*\\s*(?:(?:[+\\-*/%^]|\\.\\.)?=(?!=)|\\(|\\[|:))",
"end": "(?=[),}\\]](?!\\s*[&|]))|(?=\\s*;)|(?=\\s*(?:[*+%^]|\\/\\/?|(?<!\\.)\\.\\.(?!\\.)|-(?![->`])|~=|==))|(?=\\s*\\b(?:and|or|break|const|continue|do|else|elseif|end|for|function|if|in|local|repeat|return|then|until|while)\\b)|(?=^\\s*$)|(?=^\\s*(?:@|\\b(?:export\\s+)?type\\b))|(?=^\\s*[a-zA-Z_][a-zA-Z0-9_]*(?:\\.[a-zA-Z_][a-zA-Z0-9_]*)*\\s*(?:(?:[+\\-*/%^]|\\.\\.)?=(?!=)|\\(|\\[|:))",
"patterns": [
{
"include": "#type_literal"
Expand Down
46 changes: 46 additions & 0 deletions tests/baselines/issue-24.baseline.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
original file
-----------------------------------
local a = tonumber("1")::number * 1000

-----------------------------------

>local a = tonumber("1")::number * 1000
^^^^^
source.luau storage.modifier.local.luau
^
source.luau
^
source.luau variable.other.readwrite.luau
^
source.luau
^
source.luau keyword.operator.assignment.luau
^
source.luau
^^^^^^^^
source.luau support.function.luau
^
source.luau punctuation.arguments.begin.luau
^
source.luau string.quoted.double.luau
^
source.luau string.quoted.double.luau
^
source.luau string.quoted.double.luau
^
source.luau punctuation.arguments.end.luau
^^
source.luau keyword.operator.typecast.luau
^^^^^^
source.luau support.type.primitive.luau
^
source.luau
^
source.luau keyword.operator.arithmetic.luau
^
source.luau
^^^^
source.luau constant.numeric.decimal.luau
>
^
source.luau
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,14 @@ exports.separateDisplayNameAndHOCs =
source.luau
^^^
source.luau support.type.primitive.luau
^^^^
^
source.luau
^^
source.luau keyword.operator.comparison.luau
^
source.luau
^^^
source.luau support.type.primitive.luau
source.luau constant.language.nil.luau
^
source.luau
^^
Expand Down
1 change: 1 addition & 0 deletions tests/cases/issue-24.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
local a = tonumber("1")::number * 1000
Loading