@minduscript/lexer 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.npmignore +2 -0
- package/binding.gyp +36 -0
- package/cpp/lexer.cc +72 -0
- package/cpp/lexer.hh +34 -0
- package/cpp/lexer.l +180 -0
- package/dist/exe.d.ts +2 -0
- package/dist/exe.js +53 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +8 -0
- package/dist/lexer.d.ts +13 -0
- package/dist/lexer.js +42 -0
- package/dist/token.d.ts +168 -0
- package/dist/token.js +172 -0
- package/package.json +34 -0
package/.npmignore
ADDED
package/binding.gyp
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"targets": [
|
|
3
|
+
{
|
|
4
|
+
"target_name": "addon",
|
|
5
|
+
"sources": [
|
|
6
|
+
"cpp/lexer.cc",
|
|
7
|
+
"build/lex.yy.cc"
|
|
8
|
+
],
|
|
9
|
+
"include_dirs": [
|
|
10
|
+
"<!@(node -p \"require('node-addon-api').include\")",
|
|
11
|
+
"<!(node -p \"process.env.LEX_HOME || 'D:/win_flex_bison'\")",
|
|
12
|
+
"cpp"
|
|
13
|
+
],
|
|
14
|
+
"dependencies": ["<!(node -p \"require('node-addon-api').gyp\")"],
|
|
15
|
+
"cflags!": ["-fno-exceptions"],
|
|
16
|
+
"cflags_cc!": ["-fno-exceptions"],
|
|
17
|
+
"defines": ["NAPI_DISABLE_CPP_EXCEPTIONS"],
|
|
18
|
+
"xcode_settings": {
|
|
19
|
+
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
|
|
20
|
+
"CLANG_CXX_LIBRARY": "libc++",
|
|
21
|
+
"MACOSX_DEPLOYMENT_TARGET": "10.7"
|
|
22
|
+
},
|
|
23
|
+
"msvs_settings": {
|
|
24
|
+
"VCCLCompilerTool": { "ExceptionHandling": 1 }
|
|
25
|
+
},
|
|
26
|
+
"actions": [
|
|
27
|
+
{
|
|
28
|
+
"action_name": "flex",
|
|
29
|
+
"inputs": ["cpp/lexer.l"],
|
|
30
|
+
"outputs": ["build/lex.yy.cc"],
|
|
31
|
+
"action": ["flex", "-+", "-o", "<@(_outputs)", "<@(_inputs)"]
|
|
32
|
+
},
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
}
|
package/cpp/lexer.cc
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#include <FlexLexer.h>
|
|
2
|
+
#include "lexer.hh"
|
|
3
|
+
|
|
4
|
+
#include <fstream>
|
|
5
|
+
#include <sstream>
|
|
6
|
+
|
|
7
|
+
using namespace Napi;
|
|
8
|
+
|
|
9
|
+
External<Lexer> lexer::initLexer(const CallbackInfo &info) {
|
|
10
|
+
Env env = info.Env();
|
|
11
|
+
if (info.Length() == 1) {
|
|
12
|
+
if (!info[0].IsString())
|
|
13
|
+
TypeError::New(env, "Invalid parameter").ThrowAsJavaScriptException();
|
|
14
|
+
|
|
15
|
+
auto file = info[0].As<String>().Utf8Value();
|
|
16
|
+
auto f = new std::ifstream(file);
|
|
17
|
+
if (!f->is_open())
|
|
18
|
+
Error::New(env, std::string("Cannot open file ") + file).ThrowAsJavaScriptException();
|
|
19
|
+
auto lexer = new Lexer(f);
|
|
20
|
+
return External<Lexer>::New(env, lexer);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (info.Length() == 2) {
|
|
24
|
+
if (!info[0].IsString())
|
|
25
|
+
TypeError::New(env, "Invalid parameter").ThrowAsJavaScriptException();
|
|
26
|
+
auto source = info[0].As<String>().Utf8Value();
|
|
27
|
+
auto s = new std::stringstream(source);
|
|
28
|
+
auto lexer = new Lexer(s);
|
|
29
|
+
return External<Lexer>::New(env, lexer);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
auto lexer = new Lexer();
|
|
33
|
+
return External<Lexer>::New(env, lexer);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
void lexer::deleteLexer(const CallbackInfo &info) {
|
|
37
|
+
Env env = info.Env();
|
|
38
|
+
if (info.Length() < 1 || !info[0].IsExternal())
|
|
39
|
+
TypeError::New(env, "Invalid parameter").ThrowAsJavaScriptException();
|
|
40
|
+
|
|
41
|
+
auto lexer = info[0].As<External<Lexer>>().Data();
|
|
42
|
+
delete lexer;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
Object lexer::lex(const CallbackInfo &info) {
|
|
46
|
+
Env env = info.Env();
|
|
47
|
+
if (info.Length() < 1 || !info[0].IsExternal())
|
|
48
|
+
TypeError::New(env, "Invalid parameter").ThrowAsJavaScriptException();
|
|
49
|
+
|
|
50
|
+
auto lexer = info[0].As<External<Lexer>>().Data();
|
|
51
|
+
auto out = Object::New(env);
|
|
52
|
+
auto result = lexer->yylex();
|
|
53
|
+
auto leng = lexer->YYLeng();
|
|
54
|
+
auto text = lexer->YYText();
|
|
55
|
+
auto row = lexer->getRow();
|
|
56
|
+
auto col = lexer->getCol() - lexer->YYLeng();
|
|
57
|
+
out.Set("type", Value::From<int>(env, result));
|
|
58
|
+
out.Set("leng", Value::From<int>(env, leng));
|
|
59
|
+
out.Set("raw", Value::From<const char *>(env, text));
|
|
60
|
+
out.Set("row", Value::From<int>(env, row));
|
|
61
|
+
out.Set("col", Value::From<int>(env, col));
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
Object init(Env env, Object exports) {
|
|
66
|
+
exports.Set("initLexer", Function::New(env, lexer::initLexer));
|
|
67
|
+
exports.Set("deleteLexer", Function::New(env, lexer::deleteLexer));
|
|
68
|
+
exports.Set("lex", Function::New(env, lexer::lex));
|
|
69
|
+
return exports;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
NODE_API_MODULE(addon, init)
|
package/cpp/lexer.hh
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#define YY_NO_UNISTD_H
|
|
4
|
+
|
|
5
|
+
#include <napi.h>
|
|
6
|
+
|
|
7
|
+
#ifndef __FLEX_LEXER_H
|
|
8
|
+
class yyFlexLexer {
|
|
9
|
+
public:
|
|
10
|
+
yyFlexLexer(std::istream *in);
|
|
11
|
+
};
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
class Lexer : public yyFlexLexer {
|
|
15
|
+
private:
|
|
16
|
+
int row;
|
|
17
|
+
int col;
|
|
18
|
+
|
|
19
|
+
public:
|
|
20
|
+
Lexer(std::istream *in = nullptr) : yyFlexLexer(in), row(0), col(0) {}
|
|
21
|
+
int getRow() {
|
|
22
|
+
return row;
|
|
23
|
+
}
|
|
24
|
+
int getCol() {
|
|
25
|
+
return col;
|
|
26
|
+
}
|
|
27
|
+
int yylex();
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
namespace lexer {
|
|
31
|
+
Napi::External<Lexer> initLexer(const Napi::CallbackInfo &info);
|
|
32
|
+
void deleteLexer(const Napi::CallbackInfo &info);
|
|
33
|
+
Napi::Object lex(const Napi::CallbackInfo &info);
|
|
34
|
+
}
|
package/cpp/lexer.l
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
%{
|
|
2
|
+
#include "lexer.hh"
|
|
3
|
+
%}
|
|
4
|
+
|
|
5
|
+
%option noyywrap
|
|
6
|
+
%option c++
|
|
7
|
+
%option yyclass="Lexer"
|
|
8
|
+
|
|
9
|
+
%%
|
|
10
|
+
"macro" { col += YYLeng(); return 1; } // Minduscript关键字
|
|
11
|
+
"return" { col += YYLeng(); return 2; }
|
|
12
|
+
"if" { col += YYLeng(); return 3; }
|
|
13
|
+
"else" { col += YYLeng(); return 4; }
|
|
14
|
+
"for" { col += YYLeng(); return 5; }
|
|
15
|
+
"while" { col += YYLeng(); return 6; }
|
|
16
|
+
"continue" { col += YYLeng(); return 7; }
|
|
17
|
+
"break" { col += YYLeng(); return 8; }
|
|
18
|
+
"import" { col += YYLeng(); return 9; }
|
|
19
|
+
"as" { col += YYLeng(); return 10; }
|
|
20
|
+
"from" { col += YYLeng(); return 11; }
|
|
21
|
+
"let" { col += YYLeng(); return 12; }
|
|
22
|
+
"const" { col += YYLeng(); return 13; }
|
|
23
|
+
"bind" { col += YYLeng(); return 14; }
|
|
24
|
+
|
|
25
|
+
"=" { col += YYLeng(); return 15; } // Minduscript运算符
|
|
26
|
+
"+=" { col += YYLeng(); return 16; }
|
|
27
|
+
"-=" { col += YYLeng(); return 17; }
|
|
28
|
+
"*=" { col += YYLeng(); return 18; }
|
|
29
|
+
"/=" { col += YYLeng(); return 19; }
|
|
30
|
+
"//=" { col += YYLeng(); return 20; }
|
|
31
|
+
"%=" { col += YYLeng(); return 21; }
|
|
32
|
+
"**=" { col += YYLeng(); return 22; }
|
|
33
|
+
"&&=" { col += YYLeng(); return 23; }
|
|
34
|
+
"<<=" { col += YYLeng(); return 24; }
|
|
35
|
+
">>=" { col += YYLeng(); return 25; }
|
|
36
|
+
"&=" { col += YYLeng(); return 26; }
|
|
37
|
+
"|=" { col += YYLeng(); return 27; }
|
|
38
|
+
"^=" { col += YYLeng(); return 28; }
|
|
39
|
+
"||" { col += YYLeng(); return 29; }
|
|
40
|
+
"||=" { col += YYLeng(); return 30; }
|
|
41
|
+
"!" { col += YYLeng(); return 31; }
|
|
42
|
+
|
|
43
|
+
"max" { col += YYLeng(); return 32; } // Mindustry关键字
|
|
44
|
+
"min" { col += YYLeng(); return 33; }
|
|
45
|
+
"angle" { col += YYLeng(); return 34; }
|
|
46
|
+
"angleDiff" { col += YYLeng(); return 35; }
|
|
47
|
+
"len" { col += YYLeng(); return 36; }
|
|
48
|
+
"noise" { col += YYLeng(); return 37; }
|
|
49
|
+
"abs" { col += YYLeng(); return 38; }
|
|
50
|
+
"log" { col += YYLeng(); return 39; }
|
|
51
|
+
"log10" { col += YYLeng(); return 40; }
|
|
52
|
+
"floor" { col += YYLeng(); return 41; }
|
|
53
|
+
"ceil" { col += YYLeng(); return 42; }
|
|
54
|
+
"sqrt" { col += YYLeng(); return 43; }
|
|
55
|
+
"rand" { col += YYLeng(); return 44; }
|
|
56
|
+
"sin" { col += YYLeng(); return 45; }
|
|
57
|
+
"cos" { col += YYLeng(); return 46; }
|
|
58
|
+
"tan" { col += YYLeng(); return 47; }
|
|
59
|
+
"asin" { col += YYLeng(); return 48; }
|
|
60
|
+
"acos" { col += YYLeng(); return 49; }
|
|
61
|
+
"atan" { col += YYLeng(); return 50; }
|
|
62
|
+
"read" { col += YYLeng(); return 51; }
|
|
63
|
+
"write" { col += YYLeng(); return 52; }
|
|
64
|
+
"drawClear" { col += YYLeng(); return 53; }
|
|
65
|
+
"drawColor" { col += YYLeng(); return 54; }
|
|
66
|
+
"drawCol" { col += YYLeng(); return 55; }
|
|
67
|
+
"drawStroke" { col += YYLeng(); return 56; }
|
|
68
|
+
"drawLine" { col += YYLeng(); return 57; }
|
|
69
|
+
"drawRect" { col += YYLeng(); return 58; }
|
|
70
|
+
"drawLineRect" { col += YYLeng(); return 59; }
|
|
71
|
+
"drawPoly" { col += YYLeng(); return 60; }
|
|
72
|
+
"drawLinePoly" { col += YYLeng(); return 61; }
|
|
73
|
+
"drawTriangle" { col += YYLeng(); return 62; }
|
|
74
|
+
"drawImage" { col += YYLeng(); return 63; }
|
|
75
|
+
"print" { col += YYLeng(); return 64; }
|
|
76
|
+
"drawFlush" { col += YYLeng(); return 65; }
|
|
77
|
+
"printFlush" { col += YYLeng(); return 66; }
|
|
78
|
+
"getLink" { col += YYLeng(); return 67; }
|
|
79
|
+
"setEnabled" { col += YYLeng(); return 68; }
|
|
80
|
+
"setShoot" { col += YYLeng(); return 69; }
|
|
81
|
+
"setShootP" { col += YYLeng(); return 70; }
|
|
82
|
+
"setConfig" { col += YYLeng(); return 71; }
|
|
83
|
+
"setColor" { col += YYLeng(); return 72; }
|
|
84
|
+
"radar" { col += YYLeng(); return 73; }
|
|
85
|
+
"sensor" { col += YYLeng(); return 74; }
|
|
86
|
+
"packColor" { col += YYLeng(); return 75; }
|
|
87
|
+
"wait" { col += YYLeng(); return 76; }
|
|
88
|
+
"cpuStop" { col += YYLeng(); return 77; }
|
|
89
|
+
"unitBind" { col += YYLeng(); return 78; }
|
|
90
|
+
"unitRadar" { col += YYLeng(); return 79; }
|
|
91
|
+
"unitLocate" { col += YYLeng(); return 80; }
|
|
92
|
+
"idle" { col += YYLeng(); return 81; }
|
|
93
|
+
"stop" { col += YYLeng(); return 82; }
|
|
94
|
+
"move" { col += YYLeng(); return 83; }
|
|
95
|
+
"approach" { col += YYLeng(); return 84; }
|
|
96
|
+
"pathFind" { col += YYLeng(); return 85; }
|
|
97
|
+
"autoPathFind" { col += YYLeng(); return 86; }
|
|
98
|
+
"boost" { col += YYLeng(); return 87; }
|
|
99
|
+
"target" { col += YYLeng(); return 88; }
|
|
100
|
+
"targetP" { col += YYLeng(); return 89; }
|
|
101
|
+
"itemDrop" { col += YYLeng(); return 90; }
|
|
102
|
+
"itemTake" { col += YYLeng(); return 91; }
|
|
103
|
+
"payDrop" { col += YYLeng(); return 92; }
|
|
104
|
+
"payTake" { col += YYLeng(); return 93; }
|
|
105
|
+
"payEnter" { col += YYLeng(); return 94; }
|
|
106
|
+
"mine" { col += YYLeng(); return 95; }
|
|
107
|
+
"flag" { col += YYLeng(); return 96; }
|
|
108
|
+
"build" { col += YYLeng(); return 97; }
|
|
109
|
+
"getBlock" { col += YYLeng(); return 98; }
|
|
110
|
+
"within" { col += YYLeng(); return 99; }
|
|
111
|
+
"unbind" { col += YYLeng(); return 100; }
|
|
112
|
+
"null" { col += YYLeng(); return 101; }
|
|
113
|
+
"true" { col += YYLeng(); return 102; }
|
|
114
|
+
"false" { col += YYLeng(); return 103; }
|
|
115
|
+
"Any" { col += YYLeng(); return 104; }
|
|
116
|
+
"Enemy" { col += YYLeng(); return 105; }
|
|
117
|
+
"Ally" { col += YYLeng(); return 106; }
|
|
118
|
+
"Player" { col += YYLeng(); return 107; }
|
|
119
|
+
"Attacker" { col += YYLeng(); return 108; }
|
|
120
|
+
"Flying" { col += YYLeng(); return 109; }
|
|
121
|
+
"Boss" { col += YYLeng(); return 110; }
|
|
122
|
+
"Ground" { col += YYLeng(); return 111; }
|
|
123
|
+
"Distance" { col += YYLeng(); return 112; }
|
|
124
|
+
"Health" { col += YYLeng(); return 113; }
|
|
125
|
+
"Shield" { col += YYLeng(); return 114; }
|
|
126
|
+
"Armor" { col += YYLeng(); return 115; }
|
|
127
|
+
"MaxHealth" { col += YYLeng(); return 116; }
|
|
128
|
+
"Ore" { col += YYLeng(); return 117; }
|
|
129
|
+
"Building" { col += YYLeng(); return 118; }
|
|
130
|
+
"Spawn" { col += YYLeng(); return 119; }
|
|
131
|
+
"Damaged" { col += YYLeng(); return 120; }
|
|
132
|
+
"Core" { col += YYLeng(); return 121; }
|
|
133
|
+
"Storage" { col += YYLeng(); return 122; }
|
|
134
|
+
"Generator" { col += YYLeng(); return 123; }
|
|
135
|
+
"Turret" { col += YYLeng(); return 124; }
|
|
136
|
+
"Factory" { col += YYLeng(); return 125; }
|
|
137
|
+
"Repair" { col += YYLeng(); return 126; }
|
|
138
|
+
"Battery" { col += YYLeng(); return 127; }
|
|
139
|
+
"Reactor" { col += YYLeng(); return 128; }
|
|
140
|
+
|
|
141
|
+
"+" { col += YYLeng(); return 129; } // Mindustry运算符
|
|
142
|
+
"-" { col += YYLeng(); return 130; }
|
|
143
|
+
"*" { col += YYLeng(); return 131; }
|
|
144
|
+
"/" { col += YYLeng(); return 132; }
|
|
145
|
+
"//" { col += YYLeng(); return 133; }
|
|
146
|
+
"%" { col += YYLeng(); return 134; }
|
|
147
|
+
"**" { col += YYLeng(); return 135; }
|
|
148
|
+
"==" { col += YYLeng(); return 136; }
|
|
149
|
+
"!=" { col += YYLeng(); return 137; }
|
|
150
|
+
"&&" { col += YYLeng(); return 138; }
|
|
151
|
+
"<" { col += YYLeng(); return 139; }
|
|
152
|
+
"<=" { col += YYLeng(); return 140; }
|
|
153
|
+
">" { col += YYLeng(); return 141; }
|
|
154
|
+
">=" { col += YYLeng(); return 142; }
|
|
155
|
+
"===" { col += YYLeng(); return 143; }
|
|
156
|
+
"<<" { col += YYLeng(); return 144; }
|
|
157
|
+
">>" { col += YYLeng(); return 145; }
|
|
158
|
+
"|" { col += YYLeng(); return 146; }
|
|
159
|
+
"&" { col += YYLeng(); return 147; }
|
|
160
|
+
"^" { col += YYLeng(); return 148; }
|
|
161
|
+
"~" { col += YYLeng(); return 149; }
|
|
162
|
+
|
|
163
|
+
[A-Za-z][A-Za-z0-9]* { col += YYLeng(); return 150; } // 标识符
|
|
164
|
+
"@"[A-Za-z][A-Za-z0-9]* { col += YYLeng(); return 151; } // Mindustry标识符
|
|
165
|
+
-?[0-9]+("."[0-9]+)? { col += YYLeng(); return 152; } // 数字字面量
|
|
166
|
+
\"[^\"]*\" { col += YYLeng(); return 153; } // 字符串字面量
|
|
167
|
+
"%"[a-f0-9]{6} { col += YYLeng(); return 154; } // 颜色
|
|
168
|
+
|
|
169
|
+
"{" { col += YYLeng(); return 155; } // 其他符号
|
|
170
|
+
"}" { col += YYLeng(); return 156; }
|
|
171
|
+
"(" { col += YYLeng(); return 157; }
|
|
172
|
+
")" { col += YYLeng(); return 158; }
|
|
173
|
+
"," { col += YYLeng(); return 159; }
|
|
174
|
+
";" { col += YYLeng(); return 160; }
|
|
175
|
+
|
|
176
|
+
#[^\n]* { col += YYLeng(); } // 空白
|
|
177
|
+
\r?\n { col = 0; row++; }
|
|
178
|
+
[\x20\t] { col += YYLeng(); }
|
|
179
|
+
. { col += YYLeng(); return -1; }
|
|
180
|
+
%%
|
package/dist/exe.d.ts
ADDED
package/dist/exe.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const commander_1 = require("commander");
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const _1 = require(".");
|
|
10
|
+
const lexer_1 = require("./lexer");
|
|
11
|
+
commander_1.program
|
|
12
|
+
.option('-o, --output <string>', '输出文件,若不存在则输出到标准输出')
|
|
13
|
+
.option('-r, --raw', '输出可被语法分析器使用的原始Token流')
|
|
14
|
+
.argument('[inputFile]', '输入文件名,若不存在则读取标准输入')
|
|
15
|
+
.action(function (input) {
|
|
16
|
+
const options = this.opts();
|
|
17
|
+
const output = options.output;
|
|
18
|
+
const raw = options.raw ?? false;
|
|
19
|
+
let inputData;
|
|
20
|
+
if (input) {
|
|
21
|
+
inputData = fs_1.default.readFileSync(input, { encoding: 'utf-8' });
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
inputData = process.stdin.read();
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
const tokens = _1.lexer.lexString(inputData);
|
|
28
|
+
let outputData;
|
|
29
|
+
if (raw) {
|
|
30
|
+
outputData = JSON.stringify(tokens);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
outputData = JSON.stringify(tokens.map((token) => `${_1.TokenType[token.type]}(${token.raw})`));
|
|
34
|
+
}
|
|
35
|
+
if (output) {
|
|
36
|
+
fs_1.default.writeFileSync(output, outputData, { encoding: 'utf-8' });
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
console.log(outputData);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
if (e instanceof lexer_1.LexError) {
|
|
44
|
+
console.error(e.message);
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
throw e;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
.parse();
|
|
53
|
+
//# sourceMappingURL=exe.js.map
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TokenType = exports.lexer = void 0;
|
|
4
|
+
const lexer_1 = require("./lexer");
|
|
5
|
+
exports.lexer = new lexer_1.Lexer();
|
|
6
|
+
var token_1 = require("./token");
|
|
7
|
+
Object.defineProperty(exports, "TokenType", { enumerable: true, get: function () { return token_1.TokenType; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
package/dist/lexer.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Token } from './token';
|
|
2
|
+
export declare class LexError extends Error {
|
|
3
|
+
readonly row: number;
|
|
4
|
+
readonly col: number;
|
|
5
|
+
readonly raw: string;
|
|
6
|
+
constructor(row: number, col: number, raw: string);
|
|
7
|
+
}
|
|
8
|
+
export declare class Lexer {
|
|
9
|
+
private lex;
|
|
10
|
+
lexInput(): Token[];
|
|
11
|
+
lexFile(fileName: string): Token[];
|
|
12
|
+
lexString(str: string): Token[];
|
|
13
|
+
}
|
package/dist/lexer.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Lexer = exports.LexError = void 0;
|
|
4
|
+
const cppLib = require('../build/Release/addon.node');
|
|
5
|
+
class LexError extends Error {
|
|
6
|
+
row;
|
|
7
|
+
col;
|
|
8
|
+
raw;
|
|
9
|
+
constructor(row, col, raw) {
|
|
10
|
+
super(`Unexpected char "${JSON.stringify(raw)}" at (${row}, ${col})`);
|
|
11
|
+
this.row = row;
|
|
12
|
+
this.col = col;
|
|
13
|
+
this.raw = raw;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.LexError = LexError;
|
|
17
|
+
class Lexer {
|
|
18
|
+
lex(lexer) {
|
|
19
|
+
const tokenStream = [];
|
|
20
|
+
let token;
|
|
21
|
+
while ((token = cppLib.lex(lexer)).type != 0) {
|
|
22
|
+
if (token.type == -1) {
|
|
23
|
+
cppLib.deleteLexer(lexer);
|
|
24
|
+
throw new LexError(token.row, token.col, token.raw);
|
|
25
|
+
}
|
|
26
|
+
tokenStream.push(token);
|
|
27
|
+
}
|
|
28
|
+
cppLib.deleteLexer(lexer);
|
|
29
|
+
return tokenStream;
|
|
30
|
+
}
|
|
31
|
+
lexInput() {
|
|
32
|
+
return this.lex(cppLib.initLexer());
|
|
33
|
+
}
|
|
34
|
+
lexFile(fileName) {
|
|
35
|
+
return this.lex(cppLib.initLexer(fileName));
|
|
36
|
+
}
|
|
37
|
+
lexString(str) {
|
|
38
|
+
return this.lex(cppLib.initLexer(str, true));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.Lexer = Lexer;
|
|
42
|
+
//# sourceMappingURL=lexer.js.map
|
package/dist/token.d.ts
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
export declare enum TokenType {
|
|
2
|
+
MACRO = 1,// macro
|
|
3
|
+
RETURN = 2,
|
|
4
|
+
IF = 3,// if
|
|
5
|
+
ELSE = 4,// else
|
|
6
|
+
FOR = 5,// for
|
|
7
|
+
WHILE = 6,// while
|
|
8
|
+
CONTINUE = 7,// continue
|
|
9
|
+
BREAK = 8,// break
|
|
10
|
+
IMPORT = 9,// import
|
|
11
|
+
AS = 10,// as
|
|
12
|
+
FROM = 11,// from
|
|
13
|
+
LET = 12,// let
|
|
14
|
+
CONST = 13,// const
|
|
15
|
+
BIND = 14,// bind
|
|
16
|
+
ASSIGN = 15,// =
|
|
17
|
+
ADD_ASSIGN = 16,// +=
|
|
18
|
+
SUB_ASSIGN = 17,// -=
|
|
19
|
+
MUL_ASSIGN = 18,// *=
|
|
20
|
+
DIV_ASSIGN = 19,// /=
|
|
21
|
+
IDIV_ASSIGN = 20,// //=
|
|
22
|
+
MOD_ASSIGN = 21,// %=
|
|
23
|
+
POW_ASSIGN = 22,// **=
|
|
24
|
+
AND_ASSIGN = 23,// &&=
|
|
25
|
+
SHL_ASSIGN = 24,// <<=
|
|
26
|
+
SHR_ASSIGN = 25,// >>=
|
|
27
|
+
BITAND_ASSIGN = 26,// &=
|
|
28
|
+
BITOR_ASSIGN = 27,// |=
|
|
29
|
+
XOR_ASSIGN = 28,// ^=
|
|
30
|
+
OR = 29,// ||
|
|
31
|
+
OR_ASSIGN = 30,// ||=
|
|
32
|
+
NOT = 31,// !
|
|
33
|
+
MAX = 32,// max
|
|
34
|
+
MIN = 33,// min
|
|
35
|
+
ANGLE = 34,// angle
|
|
36
|
+
ANGLE_DIFF = 35,// angleDiff
|
|
37
|
+
LEN = 36,// len
|
|
38
|
+
NOISE = 37,// noise
|
|
39
|
+
ABS = 38,// abs
|
|
40
|
+
LOG = 39,// log
|
|
41
|
+
LOG10 = 40,// log10
|
|
42
|
+
FLOOR = 41,// floor
|
|
43
|
+
CEIL = 42,// ceil
|
|
44
|
+
SQRT = 43,// sqrt
|
|
45
|
+
RAND = 44,// rand
|
|
46
|
+
SIN = 45,// sin
|
|
47
|
+
COS = 46,// cos
|
|
48
|
+
TAN = 47,// tan
|
|
49
|
+
ASIN = 48,// asin
|
|
50
|
+
ACOS = 49,// acos,
|
|
51
|
+
ATAN = 50,// atan
|
|
52
|
+
READ = 51,// read
|
|
53
|
+
WRITE = 52,// write
|
|
54
|
+
DRAW_CLEAR = 53,// drawClear
|
|
55
|
+
DRAW_COLOR = 54,// drawColor
|
|
56
|
+
DRAW_COL = 55,// drawCol
|
|
57
|
+
DRAW_STROKE = 56,// drawStroke
|
|
58
|
+
DRAW_LINE = 57,// drawLine
|
|
59
|
+
DRAW_RECT = 58,// drawRect
|
|
60
|
+
DRAW_LINE_RECT = 59,// drawLineRect
|
|
61
|
+
DRAW_POLY = 60,// drawPoly
|
|
62
|
+
DRAW_LINE_POLY = 61,// drawLinePoly
|
|
63
|
+
DRAW_TRIANGLE = 62,// drawTriangle
|
|
64
|
+
DRAW_IMAGE = 63,// drawImage
|
|
65
|
+
PRINT = 64,// print
|
|
66
|
+
DRAW_FLUSH = 65,// drawFlush
|
|
67
|
+
PRINT_FLUSH = 66,// printFlush
|
|
68
|
+
GET_LINK = 67,// getLink
|
|
69
|
+
SET_ENABLED = 68,// setEnabled
|
|
70
|
+
SET_SHOOT = 69,// setShoot
|
|
71
|
+
SET_SHOOT_P = 70,// setShootP
|
|
72
|
+
SET_CONFIG = 71,// setConfig
|
|
73
|
+
SET_COLOR = 72,// setColor
|
|
74
|
+
RADAR = 73,// radar
|
|
75
|
+
SENSOR = 74,// sensor
|
|
76
|
+
PACK_COLOR = 75,// packColor
|
|
77
|
+
WAIT = 76,// wait
|
|
78
|
+
CPU_STOP = 77,// cpuStop
|
|
79
|
+
UNIT_BIND = 78,// unitBind
|
|
80
|
+
UNIT_RADAR = 79,// unitRadar
|
|
81
|
+
UNIT_LOCATE = 80,// unitLocate
|
|
82
|
+
IDLE = 81,// idle
|
|
83
|
+
STOP = 82,// stop
|
|
84
|
+
MOVE = 83,// move
|
|
85
|
+
APPROACH = 84,// approach
|
|
86
|
+
PATH_FIND = 85,// pathFind
|
|
87
|
+
AUTO_PATH_FIND = 86,// autoPathFind
|
|
88
|
+
BOOST = 87,// boost
|
|
89
|
+
TARGET = 88,// target
|
|
90
|
+
TARGET_P = 89,// targetP
|
|
91
|
+
ITEM_DROP = 90,// itemDrop
|
|
92
|
+
ITEM_TAKE = 91,// itemTake
|
|
93
|
+
PAY_DROP = 92,// payDrop
|
|
94
|
+
PAY_TAKE = 93,// payTake
|
|
95
|
+
PAY_ENTER = 94,// payEnter
|
|
96
|
+
MINE = 95,// mine
|
|
97
|
+
FLAG = 96,// flag
|
|
98
|
+
BUILD = 97,// build
|
|
99
|
+
GET_BLOCK = 98,// getBlock
|
|
100
|
+
WITHIN = 99,// within
|
|
101
|
+
UNBIND = 100,// unbind
|
|
102
|
+
NULL = 101,// null
|
|
103
|
+
TRUE = 102,// true
|
|
104
|
+
FALSE = 103,// false
|
|
105
|
+
ANY = 104,// Any
|
|
106
|
+
ENEMY = 105,// Enemy
|
|
107
|
+
ALLY = 106,// Ally
|
|
108
|
+
PLAYER = 107,// Player
|
|
109
|
+
ATTACKER = 108,// Attacker
|
|
110
|
+
FLYING = 109,// Flying
|
|
111
|
+
BOSS = 110,// Boss
|
|
112
|
+
GROUND = 111,// Ground
|
|
113
|
+
DISTANCE = 112,// Distance
|
|
114
|
+
HEALTH = 113,// Health
|
|
115
|
+
SHIELD = 114,// Shield
|
|
116
|
+
ARMOR = 115,// Armor
|
|
117
|
+
MAX_HEALTH = 116,// MaxHealth
|
|
118
|
+
ORE = 117,// Ore
|
|
119
|
+
BUILDING = 118,// Building
|
|
120
|
+
SPAWN = 119,// Spawn
|
|
121
|
+
DAMAGED = 120,// Damaged
|
|
122
|
+
CORE = 121,// Core
|
|
123
|
+
STORAGE = 122,// Storage
|
|
124
|
+
GENERATOR = 123,// Generator
|
|
125
|
+
TURRET = 124,// Turret
|
|
126
|
+
FACTORY = 125,// Factory
|
|
127
|
+
REPAIR = 126,// Repair
|
|
128
|
+
BATTERY = 127,// Battery
|
|
129
|
+
REACTOR = 128,// Reactor
|
|
130
|
+
ADD = 129,// +
|
|
131
|
+
SUB = 130,// -
|
|
132
|
+
MUL = 131,// *
|
|
133
|
+
DIV = 132,// /
|
|
134
|
+
IDIV = 133,// //
|
|
135
|
+
MOD = 134,// %
|
|
136
|
+
POW = 135,// **
|
|
137
|
+
EQ = 136,// ==
|
|
138
|
+
NE = 137,// !=
|
|
139
|
+
AND = 138,// &&
|
|
140
|
+
LESS = 139,// <
|
|
141
|
+
LE = 140,// <=
|
|
142
|
+
GREATER = 141,// >
|
|
143
|
+
GE = 142,// >=
|
|
144
|
+
STRICT_EQ = 143,// ===
|
|
145
|
+
SHL = 144,// <<
|
|
146
|
+
SHR = 145,// >>
|
|
147
|
+
BITOR = 146,// |
|
|
148
|
+
BITAND = 147,// &
|
|
149
|
+
XOR = 148,// ^
|
|
150
|
+
FLIP = 149,// ~
|
|
151
|
+
IDENTIFIER = 150,// 标识符
|
|
152
|
+
MINDUSTRY_IDENTIFIER = 151,// Mindustry标识符
|
|
153
|
+
NUMBER = 152,// 数字字面量
|
|
154
|
+
STRING = 153,// 字符串字面量
|
|
155
|
+
COLOR = 154,// 颜色
|
|
156
|
+
L_BRACE = 155,// {
|
|
157
|
+
R_BRACE = 156,// }
|
|
158
|
+
L_PAREN = 157,// (
|
|
159
|
+
R_PAREN = 158,// )
|
|
160
|
+
COMMA = 159,// ,
|
|
161
|
+
SEMICOLON = 160
|
|
162
|
+
}
|
|
163
|
+
export type Token = {
|
|
164
|
+
type: TokenType;
|
|
165
|
+
raw: string;
|
|
166
|
+
row: number;
|
|
167
|
+
col: number;
|
|
168
|
+
};
|
package/dist/token.js
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TokenType = void 0;
|
|
4
|
+
var TokenType;
|
|
5
|
+
(function (TokenType) {
|
|
6
|
+
// Minduscript关键字
|
|
7
|
+
TokenType[TokenType["MACRO"] = 1] = "MACRO";
|
|
8
|
+
TokenType[TokenType["RETURN"] = 2] = "RETURN";
|
|
9
|
+
TokenType[TokenType["IF"] = 3] = "IF";
|
|
10
|
+
TokenType[TokenType["ELSE"] = 4] = "ELSE";
|
|
11
|
+
TokenType[TokenType["FOR"] = 5] = "FOR";
|
|
12
|
+
TokenType[TokenType["WHILE"] = 6] = "WHILE";
|
|
13
|
+
TokenType[TokenType["CONTINUE"] = 7] = "CONTINUE";
|
|
14
|
+
TokenType[TokenType["BREAK"] = 8] = "BREAK";
|
|
15
|
+
TokenType[TokenType["IMPORT"] = 9] = "IMPORT";
|
|
16
|
+
TokenType[TokenType["AS"] = 10] = "AS";
|
|
17
|
+
TokenType[TokenType["FROM"] = 11] = "FROM";
|
|
18
|
+
TokenType[TokenType["LET"] = 12] = "LET";
|
|
19
|
+
TokenType[TokenType["CONST"] = 13] = "CONST";
|
|
20
|
+
TokenType[TokenType["BIND"] = 14] = "BIND";
|
|
21
|
+
// Minduscript运算符
|
|
22
|
+
TokenType[TokenType["ASSIGN"] = 15] = "ASSIGN";
|
|
23
|
+
TokenType[TokenType["ADD_ASSIGN"] = 16] = "ADD_ASSIGN";
|
|
24
|
+
TokenType[TokenType["SUB_ASSIGN"] = 17] = "SUB_ASSIGN";
|
|
25
|
+
TokenType[TokenType["MUL_ASSIGN"] = 18] = "MUL_ASSIGN";
|
|
26
|
+
TokenType[TokenType["DIV_ASSIGN"] = 19] = "DIV_ASSIGN";
|
|
27
|
+
TokenType[TokenType["IDIV_ASSIGN"] = 20] = "IDIV_ASSIGN";
|
|
28
|
+
TokenType[TokenType["MOD_ASSIGN"] = 21] = "MOD_ASSIGN";
|
|
29
|
+
TokenType[TokenType["POW_ASSIGN"] = 22] = "POW_ASSIGN";
|
|
30
|
+
TokenType[TokenType["AND_ASSIGN"] = 23] = "AND_ASSIGN";
|
|
31
|
+
TokenType[TokenType["SHL_ASSIGN"] = 24] = "SHL_ASSIGN";
|
|
32
|
+
TokenType[TokenType["SHR_ASSIGN"] = 25] = "SHR_ASSIGN";
|
|
33
|
+
TokenType[TokenType["BITAND_ASSIGN"] = 26] = "BITAND_ASSIGN";
|
|
34
|
+
TokenType[TokenType["BITOR_ASSIGN"] = 27] = "BITOR_ASSIGN";
|
|
35
|
+
TokenType[TokenType["XOR_ASSIGN"] = 28] = "XOR_ASSIGN";
|
|
36
|
+
TokenType[TokenType["OR"] = 29] = "OR";
|
|
37
|
+
TokenType[TokenType["OR_ASSIGN"] = 30] = "OR_ASSIGN";
|
|
38
|
+
TokenType[TokenType["NOT"] = 31] = "NOT";
|
|
39
|
+
// Mindustry关键字
|
|
40
|
+
TokenType[TokenType["MAX"] = 32] = "MAX";
|
|
41
|
+
TokenType[TokenType["MIN"] = 33] = "MIN";
|
|
42
|
+
TokenType[TokenType["ANGLE"] = 34] = "ANGLE";
|
|
43
|
+
TokenType[TokenType["ANGLE_DIFF"] = 35] = "ANGLE_DIFF";
|
|
44
|
+
TokenType[TokenType["LEN"] = 36] = "LEN";
|
|
45
|
+
TokenType[TokenType["NOISE"] = 37] = "NOISE";
|
|
46
|
+
TokenType[TokenType["ABS"] = 38] = "ABS";
|
|
47
|
+
TokenType[TokenType["LOG"] = 39] = "LOG";
|
|
48
|
+
TokenType[TokenType["LOG10"] = 40] = "LOG10";
|
|
49
|
+
TokenType[TokenType["FLOOR"] = 41] = "FLOOR";
|
|
50
|
+
TokenType[TokenType["CEIL"] = 42] = "CEIL";
|
|
51
|
+
TokenType[TokenType["SQRT"] = 43] = "SQRT";
|
|
52
|
+
TokenType[TokenType["RAND"] = 44] = "RAND";
|
|
53
|
+
TokenType[TokenType["SIN"] = 45] = "SIN";
|
|
54
|
+
TokenType[TokenType["COS"] = 46] = "COS";
|
|
55
|
+
TokenType[TokenType["TAN"] = 47] = "TAN";
|
|
56
|
+
TokenType[TokenType["ASIN"] = 48] = "ASIN";
|
|
57
|
+
TokenType[TokenType["ACOS"] = 49] = "ACOS";
|
|
58
|
+
TokenType[TokenType["ATAN"] = 50] = "ATAN";
|
|
59
|
+
TokenType[TokenType["READ"] = 51] = "READ";
|
|
60
|
+
TokenType[TokenType["WRITE"] = 52] = "WRITE";
|
|
61
|
+
TokenType[TokenType["DRAW_CLEAR"] = 53] = "DRAW_CLEAR";
|
|
62
|
+
TokenType[TokenType["DRAW_COLOR"] = 54] = "DRAW_COLOR";
|
|
63
|
+
TokenType[TokenType["DRAW_COL"] = 55] = "DRAW_COL";
|
|
64
|
+
TokenType[TokenType["DRAW_STROKE"] = 56] = "DRAW_STROKE";
|
|
65
|
+
TokenType[TokenType["DRAW_LINE"] = 57] = "DRAW_LINE";
|
|
66
|
+
TokenType[TokenType["DRAW_RECT"] = 58] = "DRAW_RECT";
|
|
67
|
+
TokenType[TokenType["DRAW_LINE_RECT"] = 59] = "DRAW_LINE_RECT";
|
|
68
|
+
TokenType[TokenType["DRAW_POLY"] = 60] = "DRAW_POLY";
|
|
69
|
+
TokenType[TokenType["DRAW_LINE_POLY"] = 61] = "DRAW_LINE_POLY";
|
|
70
|
+
TokenType[TokenType["DRAW_TRIANGLE"] = 62] = "DRAW_TRIANGLE";
|
|
71
|
+
TokenType[TokenType["DRAW_IMAGE"] = 63] = "DRAW_IMAGE";
|
|
72
|
+
TokenType[TokenType["PRINT"] = 64] = "PRINT";
|
|
73
|
+
TokenType[TokenType["DRAW_FLUSH"] = 65] = "DRAW_FLUSH";
|
|
74
|
+
TokenType[TokenType["PRINT_FLUSH"] = 66] = "PRINT_FLUSH";
|
|
75
|
+
TokenType[TokenType["GET_LINK"] = 67] = "GET_LINK";
|
|
76
|
+
TokenType[TokenType["SET_ENABLED"] = 68] = "SET_ENABLED";
|
|
77
|
+
TokenType[TokenType["SET_SHOOT"] = 69] = "SET_SHOOT";
|
|
78
|
+
TokenType[TokenType["SET_SHOOT_P"] = 70] = "SET_SHOOT_P";
|
|
79
|
+
TokenType[TokenType["SET_CONFIG"] = 71] = "SET_CONFIG";
|
|
80
|
+
TokenType[TokenType["SET_COLOR"] = 72] = "SET_COLOR";
|
|
81
|
+
TokenType[TokenType["RADAR"] = 73] = "RADAR";
|
|
82
|
+
TokenType[TokenType["SENSOR"] = 74] = "SENSOR";
|
|
83
|
+
TokenType[TokenType["PACK_COLOR"] = 75] = "PACK_COLOR";
|
|
84
|
+
TokenType[TokenType["WAIT"] = 76] = "WAIT";
|
|
85
|
+
TokenType[TokenType["CPU_STOP"] = 77] = "CPU_STOP";
|
|
86
|
+
TokenType[TokenType["UNIT_BIND"] = 78] = "UNIT_BIND";
|
|
87
|
+
TokenType[TokenType["UNIT_RADAR"] = 79] = "UNIT_RADAR";
|
|
88
|
+
TokenType[TokenType["UNIT_LOCATE"] = 80] = "UNIT_LOCATE";
|
|
89
|
+
TokenType[TokenType["IDLE"] = 81] = "IDLE";
|
|
90
|
+
TokenType[TokenType["STOP"] = 82] = "STOP";
|
|
91
|
+
TokenType[TokenType["MOVE"] = 83] = "MOVE";
|
|
92
|
+
TokenType[TokenType["APPROACH"] = 84] = "APPROACH";
|
|
93
|
+
TokenType[TokenType["PATH_FIND"] = 85] = "PATH_FIND";
|
|
94
|
+
TokenType[TokenType["AUTO_PATH_FIND"] = 86] = "AUTO_PATH_FIND";
|
|
95
|
+
TokenType[TokenType["BOOST"] = 87] = "BOOST";
|
|
96
|
+
TokenType[TokenType["TARGET"] = 88] = "TARGET";
|
|
97
|
+
TokenType[TokenType["TARGET_P"] = 89] = "TARGET_P";
|
|
98
|
+
TokenType[TokenType["ITEM_DROP"] = 90] = "ITEM_DROP";
|
|
99
|
+
TokenType[TokenType["ITEM_TAKE"] = 91] = "ITEM_TAKE";
|
|
100
|
+
TokenType[TokenType["PAY_DROP"] = 92] = "PAY_DROP";
|
|
101
|
+
TokenType[TokenType["PAY_TAKE"] = 93] = "PAY_TAKE";
|
|
102
|
+
TokenType[TokenType["PAY_ENTER"] = 94] = "PAY_ENTER";
|
|
103
|
+
TokenType[TokenType["MINE"] = 95] = "MINE";
|
|
104
|
+
TokenType[TokenType["FLAG"] = 96] = "FLAG";
|
|
105
|
+
TokenType[TokenType["BUILD"] = 97] = "BUILD";
|
|
106
|
+
TokenType[TokenType["GET_BLOCK"] = 98] = "GET_BLOCK";
|
|
107
|
+
TokenType[TokenType["WITHIN"] = 99] = "WITHIN";
|
|
108
|
+
TokenType[TokenType["UNBIND"] = 100] = "UNBIND";
|
|
109
|
+
TokenType[TokenType["NULL"] = 101] = "NULL";
|
|
110
|
+
TokenType[TokenType["TRUE"] = 102] = "TRUE";
|
|
111
|
+
TokenType[TokenType["FALSE"] = 103] = "FALSE";
|
|
112
|
+
TokenType[TokenType["ANY"] = 104] = "ANY";
|
|
113
|
+
TokenType[TokenType["ENEMY"] = 105] = "ENEMY";
|
|
114
|
+
TokenType[TokenType["ALLY"] = 106] = "ALLY";
|
|
115
|
+
TokenType[TokenType["PLAYER"] = 107] = "PLAYER";
|
|
116
|
+
TokenType[TokenType["ATTACKER"] = 108] = "ATTACKER";
|
|
117
|
+
TokenType[TokenType["FLYING"] = 109] = "FLYING";
|
|
118
|
+
TokenType[TokenType["BOSS"] = 110] = "BOSS";
|
|
119
|
+
TokenType[TokenType["GROUND"] = 111] = "GROUND";
|
|
120
|
+
TokenType[TokenType["DISTANCE"] = 112] = "DISTANCE";
|
|
121
|
+
TokenType[TokenType["HEALTH"] = 113] = "HEALTH";
|
|
122
|
+
TokenType[TokenType["SHIELD"] = 114] = "SHIELD";
|
|
123
|
+
TokenType[TokenType["ARMOR"] = 115] = "ARMOR";
|
|
124
|
+
TokenType[TokenType["MAX_HEALTH"] = 116] = "MAX_HEALTH";
|
|
125
|
+
TokenType[TokenType["ORE"] = 117] = "ORE";
|
|
126
|
+
TokenType[TokenType["BUILDING"] = 118] = "BUILDING";
|
|
127
|
+
TokenType[TokenType["SPAWN"] = 119] = "SPAWN";
|
|
128
|
+
TokenType[TokenType["DAMAGED"] = 120] = "DAMAGED";
|
|
129
|
+
TokenType[TokenType["CORE"] = 121] = "CORE";
|
|
130
|
+
TokenType[TokenType["STORAGE"] = 122] = "STORAGE";
|
|
131
|
+
TokenType[TokenType["GENERATOR"] = 123] = "GENERATOR";
|
|
132
|
+
TokenType[TokenType["TURRET"] = 124] = "TURRET";
|
|
133
|
+
TokenType[TokenType["FACTORY"] = 125] = "FACTORY";
|
|
134
|
+
TokenType[TokenType["REPAIR"] = 126] = "REPAIR";
|
|
135
|
+
TokenType[TokenType["BATTERY"] = 127] = "BATTERY";
|
|
136
|
+
TokenType[TokenType["REACTOR"] = 128] = "REACTOR";
|
|
137
|
+
// Mindustry运算符
|
|
138
|
+
TokenType[TokenType["ADD"] = 129] = "ADD";
|
|
139
|
+
TokenType[TokenType["SUB"] = 130] = "SUB";
|
|
140
|
+
TokenType[TokenType["MUL"] = 131] = "MUL";
|
|
141
|
+
TokenType[TokenType["DIV"] = 132] = "DIV";
|
|
142
|
+
TokenType[TokenType["IDIV"] = 133] = "IDIV";
|
|
143
|
+
TokenType[TokenType["MOD"] = 134] = "MOD";
|
|
144
|
+
TokenType[TokenType["POW"] = 135] = "POW";
|
|
145
|
+
TokenType[TokenType["EQ"] = 136] = "EQ";
|
|
146
|
+
TokenType[TokenType["NE"] = 137] = "NE";
|
|
147
|
+
TokenType[TokenType["AND"] = 138] = "AND";
|
|
148
|
+
TokenType[TokenType["LESS"] = 139] = "LESS";
|
|
149
|
+
TokenType[TokenType["LE"] = 140] = "LE";
|
|
150
|
+
TokenType[TokenType["GREATER"] = 141] = "GREATER";
|
|
151
|
+
TokenType[TokenType["GE"] = 142] = "GE";
|
|
152
|
+
TokenType[TokenType["STRICT_EQ"] = 143] = "STRICT_EQ";
|
|
153
|
+
TokenType[TokenType["SHL"] = 144] = "SHL";
|
|
154
|
+
TokenType[TokenType["SHR"] = 145] = "SHR";
|
|
155
|
+
TokenType[TokenType["BITOR"] = 146] = "BITOR";
|
|
156
|
+
TokenType[TokenType["BITAND"] = 147] = "BITAND";
|
|
157
|
+
TokenType[TokenType["XOR"] = 148] = "XOR";
|
|
158
|
+
TokenType[TokenType["FLIP"] = 149] = "FLIP";
|
|
159
|
+
// 其他
|
|
160
|
+
TokenType[TokenType["IDENTIFIER"] = 150] = "IDENTIFIER";
|
|
161
|
+
TokenType[TokenType["MINDUSTRY_IDENTIFIER"] = 151] = "MINDUSTRY_IDENTIFIER";
|
|
162
|
+
TokenType[TokenType["NUMBER"] = 152] = "NUMBER";
|
|
163
|
+
TokenType[TokenType["STRING"] = 153] = "STRING";
|
|
164
|
+
TokenType[TokenType["COLOR"] = 154] = "COLOR";
|
|
165
|
+
TokenType[TokenType["L_BRACE"] = 155] = "L_BRACE";
|
|
166
|
+
TokenType[TokenType["R_BRACE"] = 156] = "R_BRACE";
|
|
167
|
+
TokenType[TokenType["L_PAREN"] = 157] = "L_PAREN";
|
|
168
|
+
TokenType[TokenType["R_PAREN"] = 158] = "R_PAREN";
|
|
169
|
+
TokenType[TokenType["COMMA"] = 159] = "COMMA";
|
|
170
|
+
TokenType[TokenType["SEMICOLON"] = 160] = "SEMICOLON";
|
|
171
|
+
})(TokenType || (exports.TokenType = TokenType = {}));
|
|
172
|
+
//# sourceMappingURL=token.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@minduscript/lexer",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "commonjs",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"lex-minduscript": "dist/exe.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"cpp",
|
|
13
|
+
".npmignore",
|
|
14
|
+
"binding.gyp"
|
|
15
|
+
],
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"bindings": "^1.5.0",
|
|
18
|
+
"commander": "^14.0.3",
|
|
19
|
+
"node-addon-api": "^8.6.0"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/bindings": "^1.5.5",
|
|
23
|
+
"@types/node": "^25.5.0",
|
|
24
|
+
"node-gyp": "^12.2.0",
|
|
25
|
+
"rimraf": "^6.1.3",
|
|
26
|
+
"typescript": "^5.9.3"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"init:cpp": "node-gyp configure",
|
|
30
|
+
"build:cpp": "node-gyp rebuild",
|
|
31
|
+
"build:ts": "rimraf dist && tsc",
|
|
32
|
+
"build": "pnpm build:cpp && pnpm build:ts"
|
|
33
|
+
}
|
|
34
|
+
}
|