Skip to content

Commit b1d1c2b

Browse files
committed
TM: Optimize operator regex
1 parent f7138c0 commit b1d1c2b

File tree

2 files changed

+48
-21
lines changed

2 files changed

+48
-21
lines changed

syntaxes/c3.tmLanguage.json

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,9 @@
752752
},
753753
"end": "(?=;)",
754754
"patterns": [
755+
{
756+
"include": "#attribute"
757+
},
755758
{
756759
"include": "#expression"
757760
}
@@ -853,11 +856,11 @@
853856
"name": "keyword.declaration.function.arrow.c3"
854857
},
855858
{
856-
"match": "\\+=|-=|\\*=|/=|%=|&=|\\|=|\\^=|>>=|<<=",
859+
"match": "(?:[-%&*+/^|]|>>|<<)=",
857860
"name": "keyword.operator.assignment.augmented.c3"
858861
},
859862
{
860-
"match": "<=|>=|==|<|>|\\!=",
863+
"match": "<=|>=|==|<|>|!=",
861864
"name": "keyword.operator.comparison.c3"
862865
},
863866
{
@@ -877,15 +880,15 @@
877880
"name": "keyword.operator.arithmetic.c3"
878881
},
879882
{
880-
"match": "\\+|\\-|/|%|\\||\\^|~",
883+
"match": "[-%+/^|~]",
881884
"name": "keyword.operator.arithmetic.c3"
882885
},
883886
{
884887
"match": "=",
885888
"name": "keyword.operator.assignment.c3"
886889
},
887890
{
888-
"match": "!|\\?[?:]?|\\*|&|:",
891+
"match": "!|\\?[?:]?|[&*:]",
889892
"name": "keyword.operator.c3"
890893
}
891894
]
@@ -923,6 +926,10 @@
923926
}
924927
]
925928
},
929+
"escape_sequence": {
930+
"match": "\\\\([0abefnrtv'\"\\\\]|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8})",
931+
"name": "constant.character.escape.c3"
932+
},
926933
"char_literal": {
927934
"begin": "'",
928935
"beginCaptures": {
@@ -939,8 +946,7 @@
939946
"contentName": "string.quoted.single.c3",
940947
"patterns": [
941948
{
942-
"match": "\\\\.",
943-
"name": "constant.character.escape.c3"
949+
"include": "#escape_sequence"
944950
}
945951
]
946952
},
@@ -960,8 +966,7 @@
960966
"contentName": "string.quoted.double.c3",
961967
"patterns": [
962968
{
963-
"match": "\\\\([0abefnrtv'\"\\\\]|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8})",
964-
"name": "constant.character.escape.c3"
969+
"include": "#escape_sequence"
965970
}
966971
]
967972
},
@@ -1258,13 +1263,13 @@
12581263
"attribute": {
12591264
"patterns": [
12601265
{
1261-
"begin": "@(?:(?:align|benchmark|bigendian|builtin|callconv|compact|const|deprecated|dynamic|export|extern|finalizer|format|if|inline|init|link|littleendian|local|maydiscard|naked|noalias|nodiscard|noinit|noinline|nopadding|norecurse|noreturn|nosanitize|nostrip|obfuscate|operator|operator_r|operator_s|optional|overlap|packed|private|public|pure|reflect|safemacro|section|tag|test|unused|used|wasm|weak|winmain)|(?:\\b_*[A-Z][_A-Z0-9]*[a-z][_a-zA-Z0-9]*\\b))",
1266+
"begin": "@(?:(?:align|benchmark|bigendian|builtin|callconv|compact|const|deprecated|dynamic|export|extern|finalizer|format|if|inline|init|link|littleendian|local|maydiscard|naked|noalias|nodiscard|noinit|noinline|nopadding|norecurse|noreturn|nosanitize|nostrip|obfuscate|operator|operator_r|operator_s|optional|overlap|packed|private|public|pure|reflect|safemacro|section|tag|test|unused|used|wasm|weak|winmain)\\b|(?:\\b_*[A-Z][_A-Z0-9]*[a-z][_a-zA-Z0-9]*\\b))",
12621267
"beginCaptures": {
12631268
"0": {
12641269
"name": "keyword.annotation.c3"
12651270
}
12661271
},
1267-
"end": "(?=[^\\s\\(])|(?<=\\))",
1272+
"end": "(?=[^\\s(])|(?<=\\))",
12681273
"name": "meta.annotation.c3",
12691274
"patterns": [
12701275
{
@@ -1424,6 +1429,9 @@
14241429
{
14251430
"include": "#control_statements"
14261431
},
1432+
{
1433+
"include": "#attribute"
1434+
},
14271435
{
14281436
"include": "#block"
14291437
},
@@ -1433,12 +1441,9 @@
14331441
]
14341442
},
14351443
"variable": {
1436-
"begin": "(?<!#)(?:(@(?:\\b_*[a-z][_a-zA-Z0-9]*\\b))|(\\$?(?:\\b_*[a-z][_a-zA-Z0-9]*\\b)))",
1444+
"begin": "(?<!#)(\\$?(?:\\b_*[a-z][_a-zA-Z0-9]*\\b))",
14371445
"beginCaptures": {
14381446
"1": {
1439-
"name": "entity.name.function.c3"
1440-
},
1441-
"2": {
14421447
"name": "variable.other.c3"
14431448
}
14441449
},
@@ -1449,6 +1454,28 @@
14491454
}
14501455
]
14511456
},
1457+
"leftover_at_ident": {
1458+
"patterns": [
1459+
{
1460+
"match": "@(?:pure|inline|noinline)",
1461+
"name": "meta.annotation.c3 keyword.annotation.c3"
1462+
},
1463+
{
1464+
"begin": "@(?:\\b_*[a-z][_a-zA-Z0-9]*\\b)",
1465+
"beginCaptures": {
1466+
"0": {
1467+
"name": "entity.name.function.c3"
1468+
}
1469+
},
1470+
"end": "(?=[^{\\s])|(?<=\\})",
1471+
"patterns": [
1472+
{
1473+
"include": "#generic_params"
1474+
}
1475+
]
1476+
}
1477+
]
1478+
},
14521479
"expression": {
14531480
"patterns": [
14541481
{
@@ -1478,9 +1505,6 @@
14781505
{
14791506
"include": "#path"
14801507
},
1481-
{
1482-
"include": "#attribute"
1483-
},
14841508
{
14851509
"include": "#function_call"
14861510
},
@@ -1498,6 +1522,9 @@
14981522
},
14991523
{
15001524
"include": "#punctuation"
1525+
},
1526+
{
1527+
"include": "#leftover_at_ident"
15011528
}
15021529
]
15031530
},

syntaxes/c3.tmLanguage.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,9 @@ repository:
432432
patterns:
433433
- match: '=>'
434434
name: keyword.declaration.function.arrow.c3
435-
- match: '\+=|-=|\*=|/=|%=|&=|\|=|\^=|>>=|<<='
435+
- match: '(?:[-%&*+/^|]|>>|<<)='
436436
name: keyword.operator.assignment.augmented.c3
437-
- match: '<=|>=|==|<|>|\!='
437+
- match: '<=|>=|==|<|>|!='
438438
name: keyword.operator.comparison.c3
439439
- match: '\.\.\.'
440440
name: keyword.operator.variadic.c3
@@ -444,11 +444,11 @@ repository:
444444
name: keyword.operator.arithmetic.c3
445445
- match: '<<|>>|&&&?|\|\|\|?'
446446
name: keyword.operator.arithmetic.c3
447-
- match: '\+|\-|/|%|\||\^|~'
447+
- match: '[-%+/^|~]'
448448
name: keyword.operator.arithmetic.c3
449449
- match: '='
450450
name: keyword.operator.assignment.c3
451-
- match: '!|\?[?:]?|\*|&|:'
451+
- match: '!|\?[?:]?|[&*:]'
452452
name: keyword.operator.c3
453453

454454
path:

0 commit comments

Comments
 (0)