Skip to content

Commit

Permalink
Merge pull request #513 from thetarnav/fix-ternary-grammar
Browse files Browse the repository at this point in the history
Add grammar for ternary exp and union member access
  • Loading branch information
DanielGavin authored Sep 25, 2024
2 parents 172c249 + d0f0f4d commit 5b9fa49
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions editors/vscode/syntaxes/odin.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,16 @@
"expressions": {
"patterns": [
{ "include": "#comments" },
{ "include": "#ternary" },
{ "include": "#map-bitset" },
{ "include": "#slice" },
{ "include": "#keywords" },
{ "include": "#type-parameter" },
{ "include": "#basic-types" },
{ "include": "#procedure-calls" },
{ "include": "#property-access" },
{ "include": "#union-member-access" },
{ "include": "#union-non-nil-access" },
{ "include": "#strings" },
{ "include": "#punctuation" },
{ "include": "#variable-name" }
Expand Down Expand Up @@ -355,20 +358,51 @@
}
]
},
"ternary": {
"name": "meta.ternary.odin",
"begin": "\\?",
"beginCaptures": { "0": { "name": "keyword.operator.ternary.odin" } },
"end": ":",
"endCaptures": { "0": { "name": "keyword.operator.ternary.odin" } },
"patterns": [{ "include": "#expressions" }]
},
"slice": {
"name": "meta.slice.odin",
"begin": "\\[",
"beginCaptures": { "0": { "name": "meta.brace.square.odin" } },
"end": "\\]",
"endCaptures": { "0": { "name": "meta.brace.square.odin" } },
"patterns": [ { "include": "#expressions" } ]
"patterns": [
{ "match": "\\?", "name": "keyword.operator.array.odin" },
{ "match": ":", "name": "keyword.operator.slice.odin" },
{ "include": "#expressions" }
]
},
"property-access": {
"match": "([A-Za-z_]\\w*)\\s*(\\.)\\s*(?=[A-Za-z_]\\w*)",
"captures": {
"1": { "name": "variable.other.object.odin" },
"2": { "name": "punctuation.accessor.odin" }
}
},
"union-member-access": {
"begin": "([A-Za-z_]\\w*)\\s*(\\.)\\s*(\\()",
"beginCaptures": {
"1": { "name": "variable.other.object.odin" },
"2": { "name": "punctuation.accessor.odin" },
"3": { "name": "meta.brace.round.odin" }
},
"match": "([A-Za-z_]\\w*)\\s*(\\.)(?=\\s*[A-Za-z_]\\w*)"
"end": "\\)",
"endCaptures": {"0": { "name": "meta.brace.round.odin" }},
"patterns": [{ "include": "#type-declaration" }]
},
"union-non-nil-access": {
"match": "([A-Za-z_]\\w*)\\s*(\\.)\\s*(\\?)",
"captures": {
"1": { "name": "variable.other.object.odin" },
"2": { "name": "punctuation.accessor.odin" },
"3": { "name": "punctuation.accessor.optional.odin" }
}
},
"comments": {
"patterns": [
Expand Down Expand Up @@ -510,10 +544,6 @@
"match": "->",
"name": "storage.type.function.arrow.odin"
},
{
"name": "keyword.operator.ternary.odin",
"match": "\\?"
},
{
"name": "keyword.operator.odin",
"match": "@|(\\||\\!|:|\\+|-|\\*|/|%|\\<\\<?|\\>\\>?|\\~)=?|=|: : ?|\\$"
Expand Down

0 comments on commit 5b9fa49

Please sign in to comment.