Skip to content

Commit a9dac44

Browse files
committed
TM: Update/fix real and integer literals, add hex/b64 literals
1 parent 0bec7b6 commit a9dac44

File tree

3 files changed

+95
-29
lines changed

3 files changed

+95
-29
lines changed

build_syntax.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ const js_yaml = require("js-yaml");
44
let text = readFileSync("syntaxes/c3.tmLanguage.yml").toString();
55

66
const variables = {
7-
"INT": '[0-9](_?[0-9])*',
8-
"HINT": '[a-fA-F0-9](_?[a-fA-F0-9])*',
7+
"INT": '[0-9](?:_?[0-9])*',
8+
"HINT": '[a-fA-F0-9](?:_?[a-fA-F0-9])*',
99
"OINT": '[0-7](_?[0-7])*',
1010
"BINT": '[0-1](_?[0-1])*',
11-
"INTTYPE": '(?:[ui](8|16|32|64|128)|[Uu][Ll]?|[Ll])',
12-
"REALTYPE": '(?:[f](8|16|32|64|128)?)',
11+
"INTTYPE": '(?:[ui](?:8|16|32|64|128)|[Uu][Ll]?|[Ll])',
12+
"REALTYPE": '(?:[f](?:8|16|32|64|128)?)',
1313
"E": '[Ee][+-]?[0-9]+',
1414
"P": '[Pp][+-]?[0-9]+',
1515
"CONST": '(?:_*[A-Z][_A-Z0-9]*)',

syntaxes/c3.tmLanguage.json

Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,9 @@
941941
},
942942
{
943943
"include": "#integer_literal"
944+
},
945+
{
946+
"include": "#bytes_literal"
944947
}
945948
]
946949
},
@@ -1010,23 +1013,75 @@
10101013
"real_literal": {
10111014
"patterns": [
10121015
{
1013-
"match": "\\b[0-9](?:_?[0-9])*(?:[f](?:8|16|32|64|128)?)\\b",
1016+
"match": "[0-9](?:_?[0-9])*(?:[f](?:8|16|32|64|128)?)",
10141017
"name": "constant.numeric.float.c3"
10151018
},
10161019
{
1017-
"match": "\\b(?:[0-9](?:_?[0-9])*[Ee][+-]?[0-9]+|[0-9](?:_?[0-9])*\\.[0-9](?:_?[0-9])*([Ee][+-]?[0-9]+)?)(?:(?:[f](?:8|16|32|64|128)?))?\\b",
1020+
"match": "(?:[0-9](?:_?[0-9])*[Ee][+-]?[0-9]+|[0-9](?:_?[0-9])*\\.(?:[0-9](?:_?[0-9])*)?(?:[Ee][+-]?[0-9]+)?)(?:[f](?:8|16|32|64|128)?)?",
10181021
"name": "constant.numeric.float.c3"
10191022
},
10201023
{
1021-
"match": "\\b(?:0[xX][a-fA-F0-9](?:_?[a-fA-F0-9])*[Pp][+-]?[0-9]+|0[xX][a-fA-F0-9](?:_?[a-fA-F0-9])*\\.[a-fA-F0-9](?:_?[a-fA-F0-9])*[Pp][+-]?[0-9]+)(?:[f](?:8|16|32|64|128)?)?\\b",
1024+
"match": "(?:0[xX][a-fA-F0-9](?:_?[a-fA-F0-9])*[Pp][+-]?[0-9]+|0[xX][a-fA-F0-9](?:_?[a-fA-F0-9])*\\.(?:[a-fA-F0-9](?:_?[a-fA-F0-9])*)?(?:[Pp][+-]?[0-9]+)?)",
10221025
"name": "constant.numeric.float.c3"
10231026
}
10241027
]
10251028
},
10261029
"integer_literal": {
1027-
"match": "\\b(?:[0-9](?:_?[0-9])*|0[xX][a-fA-F0-9](?:_?[a-fA-F0-9])*|0[oO][0-7](_?[0-7])*|0[bB][0-1](_?[0-1])*)(?:[ui](?:8|16|32|64|128)|[Uu][Ll]?|[Ll])?\\b",
1030+
"match": "(?:[0-9](?:_?[0-9])*|0[xX][a-fA-F0-9](?:_?[a-fA-F0-9])*|0[oO][0-7](_?[0-7])*|0[bB][0-1](_?[0-1])*)(?:[ui](?:8|16|32|64|128)|[Uu][Ll]?|[Ll])?",
10281031
"name": "constant.numeric.integer.c3"
10291032
},
1033+
"bytes_literal": {
1034+
"patterns": [
1035+
{
1036+
"begin": "(x)([\"'`])",
1037+
"beginCaptures": {
1038+
"1": {
1039+
"name": "keyword.other.c3"
1040+
},
1041+
"2": {
1042+
"name": "string.quoted.other.c3 punctuation.definition.string.begin.c3"
1043+
}
1044+
},
1045+
"end": "\\2",
1046+
"endCaptures": {
1047+
"0": {
1048+
"name": "string.quoted.other.c3 punctuation.definition.string.end.c3"
1049+
}
1050+
},
1051+
"contentName": "string.quoted.other.c3",
1052+
"patterns": [
1053+
{
1054+
"match": "[\\sfA-Fa-f0-9]+",
1055+
"name": "constant.numeric.integer.c3"
1056+
}
1057+
]
1058+
},
1059+
{
1060+
"begin": "(b64)([\"'`])",
1061+
"beginCaptures": {
1062+
"1": {
1063+
"name": "keyword.other.c3"
1064+
},
1065+
"2": {
1066+
"name": "string.quoted.other.c3 punctuation.definition.string.begin.c3"
1067+
}
1068+
},
1069+
"end": "\\2",
1070+
"endCaptures": {
1071+
"0": {
1072+
"name": "string.quoted.other.c3 punctuation.definition.string.end.c3"
1073+
}
1074+
},
1075+
"contentName": "string.quoted.other.c3",
1076+
"patterns": [
1077+
{
1078+
"match": "[\\sA-Za-z0-9+/=]+",
1079+
"name": "constant.numeric.integer.c3"
1080+
}
1081+
]
1082+
}
1083+
]
1084+
},
10301085
"comments": {
10311086
"patterns": [
10321087
{
@@ -1454,18 +1509,7 @@
14541509
"include": "#comments"
14551510
},
14561511
{
1457-
"match": "([$#]?(?:_*[a-z][_a-zA-Z0-9]*))\\s*(:(?!:))",
1458-
"captures": {
1459-
"1": {
1460-
"name": "variable.parameter.c3"
1461-
},
1462-
"2": {
1463-
"name": "punctuation.separator.c3"
1464-
}
1465-
}
1466-
},
1467-
{
1468-
"match": "(\\$(?:_*[A-Z][_A-Z0-9]*[a-z][_a-zA-Z0-9]*))\\s*(:(?!:))",
1512+
"match": "([$#]?(?:_*[a-z][_a-zA-Z0-9]*)|\\$(?:_*[A-Z][_A-Z0-9]*[a-z][_a-zA-Z0-9]*))\\s*(:(?!:))",
14691513
"captures": {
14701514
"1": {
14711515
"name": "variable.parameter.c3"

syntaxes/c3.tmLanguage.yml

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ repository:
466466
- include: "#raw_string_literal"
467467
- include: "#real_literal"
468468
- include: "#integer_literal"
469+
- include: "#bytes_literal"
469470

470471
char_literal:
471472
begin: "'"
@@ -505,17 +506,42 @@ repository:
505506

506507
real_literal:
507508
patterns:
508-
- match: '\b{{INT}}{{REALTYPE}}\b'
509+
- match: '{{INT}}{{REALTYPE}}'
509510
name: constant.numeric.float.c3
510-
- match: '\b(?:{{INT}}{{E}}|{{INT}}\.{{INT}}({{E}})?)(?:{{REALTYPE}})?\b'
511+
- match: '(?:{{INT}}{{E}}|{{INT}}\.(?:{{INT}})?(?:{{E}})?){{REALTYPE}}?'
511512
name: constant.numeric.float.c3
512-
- match: '\b(?:0[xX]{{HINT}}{{P}}|0[xX]{{HINT}}\.{{HINT}}{{P}}){{REALTYPE}}?\b'
513+
- match: '(?:0[xX]{{HINT}}{{P}}|0[xX]{{HINT}}\.(?:{{HINT}})?(?:{{P}})?)'
513514
name: constant.numeric.float.c3
514515

515516
integer_literal:
516-
match: '\b(?:{{INT}}|0[xX]{{HINT}}|0[oO]{{OINT}}|0[bB]{{BINT}}){{INTTYPE}}?\b'
517+
match: '(?:{{INT}}|0[xX]{{HINT}}|0[oO]{{OINT}}|0[bB]{{BINT}}){{INTTYPE}}?'
517518
name: constant.numeric.integer.c3
518519

520+
bytes_literal:
521+
patterns:
522+
- begin: "(x)([\"'`])"
523+
beginCaptures:
524+
1: { name: keyword.other.c3 }
525+
2: { name: string.quoted.other.c3 punctuation.definition.string.begin.c3 }
526+
end: "\\2"
527+
endCaptures:
528+
0: { name: string.quoted.other.c3 punctuation.definition.string.end.c3 }
529+
contentName: string.quoted.other.c3
530+
patterns:
531+
- match: '[\sfA-Fa-f0-9]+'
532+
name: constant.numeric.integer.c3
533+
- begin: "(b64)([\"'`])"
534+
beginCaptures:
535+
1: { name: keyword.other.c3 }
536+
2: { name: string.quoted.other.c3 punctuation.definition.string.begin.c3 }
537+
end: "\\2"
538+
endCaptures:
539+
0: { name: string.quoted.other.c3 punctuation.definition.string.end.c3 }
540+
contentName: string.quoted.other.c3
541+
patterns:
542+
- match: '[\sA-Za-z0-9+/=]+'
543+
name: constant.numeric.integer.c3
544+
519545
comments:
520546
patterns:
521547
- include: "#line_comment"
@@ -747,11 +773,7 @@ repository:
747773
patterns:
748774
- include: "#comments"
749775
# Named argument
750-
- match: '([$#]?{{IDENT}})\s*(:(?!:))'
751-
captures:
752-
1: { name: variable.parameter.c3 }
753-
2: { name: punctuation.separator.c3 }
754-
- match: '(\${{TYPE}})\s*(:(?!:))' # TODO I forget if this is even valid
776+
- match: '([$#]?{{IDENT}}|\${{TYPE}})\s*(:(?!:))' # TODO using \s* doesn't match over multiple lines
755777
captures:
756778
1: { name: variable.parameter.c3 }
757779
2: { name: punctuation.separator.c3 }

0 commit comments

Comments
 (0)