Skip to content

Commit

Permalink
feat(solidity): add support for custom types
Browse files Browse the repository at this point in the history
  • Loading branch information
sambacha authored Jul 6, 2024
1 parent 368a140 commit acb342c
Showing 1 changed file with 116 additions and 59 deletions.
175 changes: 116 additions & 59 deletions syntaxes/solidity.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
"sol"
],
"name": "Solidity",
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"patterns": [
{
"include": "#natspec"
},
{
"include": "#declaration-userType"
},
{
"include": "#comment"
},
Expand All @@ -29,6 +31,9 @@
{
"include": "#type-primitive"
},
{
"include": "#type-user"
},
{
"include": "#type-modifier-extended-scope"
},
Expand Down Expand Up @@ -72,9 +77,6 @@
},
"natspec-tags": {
"patterns": [
{
"include": "#comment-todo"
},
{
"include": "#natspec-tag-title"
},
Expand All @@ -87,6 +89,9 @@
{
"include": "#natspec-tag-dev"
},
{
"include": "#natspec-tag-inheritdoc"
},
{
"include": "#natspec-tag-param"
},
Expand Down Expand Up @@ -114,9 +119,9 @@
"match": "(@dev)\\b",
"name": "storage.type.dev.natspec"
},
"natspec-tag-custom": {
"match": "(@custom:)\\b",
"name": "storage.type.custom.natspec"
"natspec-tag-inheritdoc": {
"match": "(@inheritdoc)\\b",
"name": "storage.type.dev.natspec"
},
"natspec-tag-param": {
"match": "(@param)(\\s+([A-Za-z_]\\w*))?\\b",
Expand All @@ -130,7 +135,7 @@
}
},
"natspec-tag-return": {
"match": "(@return)(\\s+([A-Za-z_]\\w*))?\\b",
"match": "(@return)(\\s+(_?[a-z]\\w*))?\\b",
"captures": {
"1": {
"name": "storage.type.return.natspec"
Expand All @@ -140,6 +145,10 @@
}
}
},
"natspec-tag-custom": {
"match": "(@custom:[a-z]+(-[a-z]+)*)\\b",
"name": "storage.type.custom.natspec"
},
"comment": {
"patterns": [
{
Expand All @@ -150,29 +159,15 @@
}
]
},
"comment-todo": {
"match": "(?i)\\b(FIXME|TODO|CHANGED|XXX|IDEA|HACK|NOTE|REVIEW|NB|BUG|QUESTION|COMBAK|TEMP|SUPPRESS|LINT|\\w+-disable|\\w+-suppress)\\b(?-i)",
"name": "keyword.comment.todo"
},
"comment-line": {
"begin": "(?<!tp:)//",
"end": "$",
"name": "comment.line",
"patterns": [
{
"include": "#comment-todo"
}
]
"name": "comment.line"
},
"comment-block": {
"begin": "/\\*",
"end": "\\*/",
"name": "comment.block",
"patterns": [
{
"include": "#comment-todo"
}
]
"name": "comment.block"
},
"operator": {
"patterns": [
Expand All @@ -194,15 +189,15 @@
]
},
"operator-logic": {
"match": "(==|\\!=|<(?!<)|<=|>(?!>)|>=|\\&\\&|\\|\\||\\:(?!=)|\\?|\\!)",
"match": "(!|==|!=|<(?!<)|<=|>(?!>)|>=|\\&\\&|\\|\\||\\:(?!=)|\\?)",
"name": "keyword.operator.logic"
},
"operator-mapping": {
"match": "(=>)",
"name": "keyword.operator.mapping"
},
"operator-arithmetic": {
"match": "(\\+|\\-|\\/|\\*)",
"match": "(\\+|\\-|\\/|\\%|\\*)",
"name": "keyword.operator.arithmetic"
},
"operator-binary": {
Expand Down Expand Up @@ -360,9 +355,6 @@
},
{
"include": "#constant-currency"
},
{
"include": "#constant-ucase"
}
]
},
Expand All @@ -375,13 +367,9 @@
"name": "constant.language.time"
},
"constant-currency": {
"match": "\\b(ether|wei|gwei|nanoeth|finney|szabo)\\b",
"match": "\\b(ether|wei|finney|szabo)\\b",
"name": "constant.language.currency"
},
"constant-ucase": {
"match": "\\b((?=\\D)[A-Z_0-9]+)\\b",
"name": "constant.language.ucase.solidity"
},
"number": {
"patterns": [
{
Expand Down Expand Up @@ -466,6 +454,37 @@
}
]
},
"type-user": {
"patterns": [
{
"begin": "\\b([A-Z]\\w*)\\b(?:\\[\\])(\\()",
"beginCaptures": {
"1": {
"name": "entity.name.type"
}
},
"end": "(\\))",
"patterns": [
{
"include": "#primitive"
},
{
"include": "#punctuation"
},
{
"include": "#global"
},
{
"include": "#variable"
}
]
},
{
"match": "\\b([A-Z]\\w*)\\b",
"name": "entity.name.type"
}
]
},
"global": {
"patterns": [
{
Expand Down Expand Up @@ -592,6 +611,9 @@
{
"include": "#declaration-contract"
},
{
"include": "#declaration-userType"
},
{
"include": "#declaration-interface"
},
Expand Down Expand Up @@ -629,12 +651,18 @@
{
"include": "#type-primitive"
},
{
"include": "#type-user"
},
{
"include": "#type-modifier-access"
},
{
"include": "#type-modifier-immutable"
},
{
"include": "#type-modifier-extend-scope"
},
{
"include": "#type-modifier-payable"
},
Expand Down Expand Up @@ -673,6 +701,17 @@
},
"declaration-contract": {
"patterns": [
{
"match": "\\b(contract)\\b\\s+(\\w+)\\b\\s*(?=\\{)",
"captures": {
"1": {
"name": "storage.type.contract"
},
"2": {
"name": "entity.name.type.contract"
}
}
},
{
"begin": "\\b(contract)\\b\\s+(\\w+)\\b\\s+\\b(is)\\b\\s+",
"end": "(?=\\{)",
Expand All @@ -693,22 +732,36 @@
"name": "entity.name.type.contract.extend"
}
]
}
]
},
"declaration-userType": {
"match": "\\b(type)\\b\\s+(\\w+)\\b\\s+\\b(is)\\b",
"captures": {
"1": {
"name": "storage.type.userType"
},
"2": {
"name": "entity.name.type.userType"
},
"3": {
"name": "storage.modifier.is"
}
}
},
"declaration-interface": {
"patterns": [
{
"match": "\\b(contract)(\\s+([A-Za-z_]\\w*))?\\b",
"match": "\\b(interface)\\b\\s+(\\w+)\\b\\s*(?=\\{)",
"captures": {
"1": {
"name": "storage.type.contract"
"name": "storage.type.interface"
},
"2": {
"name": "entity.name.type.contract"
"name": "entity.name.type.interface"
}
}
}
]
},
"declaration-interface": {
"patterns": [
},
{
"begin": "\\b(interface)\\b\\s+(\\w+)\\b\\s+\\b(is)\\b\\s+",
"end": "(?=\\{)",
Expand All @@ -727,19 +780,11 @@
{
"match": "\\b(\\w+)\\b",
"name": "entity.name.type.interface.extend"
}
]
},
{
"match": "\\b(interface)(\\s+([A-Za-z_]\\w*))?\\b",
"captures": {
"1": {
"name": "storage.type.interface"
},
"2": {
"name": "entity.name.type.interface"
{
"include": "#comment"
}
}
]
}
]
},
Expand Down Expand Up @@ -782,6 +827,9 @@
{
"include": "#type-primitive"
},
{
"include": "#type-user"
},
{
"include": "#variable"
},
Expand Down Expand Up @@ -812,6 +860,9 @@
{
"include": "#type-primitive"
},
{
"include": "#type-user"
},
{
"match": "\\b(?:(indexed)\\s)?(\\w+)(?:,\\s*|)",
"captures": {
Expand Down Expand Up @@ -905,6 +956,9 @@
},
{
"include": "#punctuation"
},
{
"include": "#comment"
}
]
},
Expand All @@ -928,6 +982,9 @@
{
"include": "#type-primitive"
},
{
"include": "#type-user"
},
{
"include": "#type-modifier-extended-scope"
},
Expand Down Expand Up @@ -995,7 +1052,7 @@
"include": "#modifier-call"
},
{
"include": "#punctuation"
"include": "#comment"
}
]
},
Expand Down Expand Up @@ -1091,6 +1148,9 @@
{
"include": "#type-primitive"
},
{
"include": "#type-user"
},
{
"include": "#punctuation"
},
Expand All @@ -1117,13 +1177,10 @@
}
},
"function-call": {
"match": "\\b([A-Za-z_]\\w*)\\s*(\\()",
"match": "\\b([A-Za-z_]\\w*)\\s*\\(",
"captures": {
"1": {
"name": "entity.name.function"
},
"2": {
"name": "punctuation.parameters.begin"
}
}
},
Expand Down Expand Up @@ -1181,5 +1238,5 @@
}
},
"scopeName": "source.solidity",
"uuid": "18e064f3-32b1-44de-ac9e-10f0607d7b84"
"uuid": "4a2eb52d-02e5-46fd-848a-0648e20ef769"
}

0 comments on commit acb342c

Please sign in to comment.