-
Notifications
You must be signed in to change notification settings - Fork 1
/
build_syntax.js
29 lines (25 loc) · 1.82 KB
/
build_syntax.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const { readFileSync, existsSync, mkdirSync, writeFileSync } = require("fs");
const js_yaml = require("js-yaml");
let text = readFileSync("syntaxes/c3.tmLanguage.yml").toString();
const variables = {
"INT": '[0-9](_?[0-9])*',
"HINT": '[a-fA-F0-9](_?[a-fA-F0-9])*',
"OINT": '[0-7](_?[0-7])*',
"BINT": '[0-1](_?[0-1])*',
"INTTYPE": '(?:[ui](8|16|32|64|128)|[Uu][Ll]?|[Ll])',
"REALTYPE": '(?:[f](8|16|32|64|128)?)',
"E": '[Ee][+-]?[0-9]+',
"P": '[Pp][+-]?[0-9]+',
"CONST": '(?:_*[A-Z][_A-Z0-9]*)',
"TYPE": '(?:_*[A-Z][_A-Z0-9]*[a-z][_a-zA-Z0-9]*)',
"IDENT": '(?:_*[a-z][_a-zA-Z0-9]*)',
"keyword": 'assert|asm|catch|const|def|distinct|extern|tlocal|inline|import|module|interface|static|try|var',
"control_keyword": 'break|case|continue|default|defer|do|else|for|foreach|foreach_r|if|nextcase|return|switch|while',
"ct_keyword": 'alignof|and|append|assert|assignable|concat|default|defined|echo|embed|eval|error|exec|extnameof|feature|include|is_const|nameof|offsetof|or|qnameof|sizeof|stringify|vacount|vaconst|varef|vaarg|vaexpr|vasplat',
"ct_control_keyword": 'case|else|endfor|endforeach|endif|endswitch|for|foreach|if|switch',
"base_type": 'void|bool|char|double|float|float16|int128|ichar|int|iptr|isz|long|short|uint128|uint|ulong|uptr|ushort|usz|float128|any|anyfault|typeid',
"attribute": 'align|benchmark|bigendian|builtin|callconv|compact|const|deprecated|dynamic|export|extern|finalizer|if|inline|init|link|littleendian|local|maydiscard|naked|nodiscard|noinit|noinline|nopadding|noreturn|nosanitize|nostrip|obfuscate|operator|optional|overlap|packed|private|public|pure|reflect|safemacro|section|test|unused|used|wasm|weak|winmain',
};
text = text.replaceAll(/\{\{([A-Za-z0-9_]+)\}\}/g, (_, x) => variables[x]);
const json = js_yaml.load(text);
writeFileSync("syntaxes/c3.tmLanguage.json", JSON.stringify(json, null, 2));