pure-dango 1.8.2 → 1.8.3
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/dist/PureDango.cjs +2 -3
- package/dist/PureDangoLauncher.exe +0 -0
- package/package.json +3 -1
- package/src/globals.d.ts +15 -0
- package/src/index.ts +1 -1
- package/src/types.d.ts +102 -0
- package/dist/lib/parser/main.js +0 -481
- package/dist/lib/tokenizer/tokenizer.js +0 -298
package/dist/PureDango.cjs
CHANGED
|
@@ -4200,7 +4200,7 @@ var typeMap = /* @__PURE__ */ new Map([
|
|
|
4200
4200
|
(parameter) => ({
|
|
4201
4201
|
name: parameter.name,
|
|
4202
4202
|
rest: parameter.rest,
|
|
4203
|
-
default: parameter.
|
|
4203
|
+
default: parameter.default ? parseObject(parameter.default, [], true) : null,
|
|
4204
4204
|
typeAnnotation: parameter.typeAnnotation ?? null
|
|
4205
4205
|
})
|
|
4206
4206
|
);
|
|
@@ -9308,7 +9308,7 @@ var {
|
|
|
9308
9308
|
} = utils_exports;
|
|
9309
9309
|
var packageJson = {
|
|
9310
9310
|
name: true ? "pure-dango" : "pure-dango",
|
|
9311
|
-
version: true ? "1.8.
|
|
9311
|
+
version: true ? "1.8.2" : "1.8.2",
|
|
9312
9312
|
description: true ? "A simple programming language built in JavaScript" : "A simple programming language built in JavaScript"
|
|
9313
9313
|
};
|
|
9314
9314
|
function pause(code = 0) {
|
|
@@ -9409,7 +9409,6 @@ process.on(
|
|
|
9409
9409
|
console.log(`
|
|
9410
9410
|
Pure dango program exited after: ${state.time.toFixed(3)} milliseconds...`);
|
|
9411
9411
|
} catch (error) {
|
|
9412
|
-
console.error(error);
|
|
9413
9412
|
console.error(`
|
|
9414
9413
|
${error.message}`);
|
|
9415
9414
|
console.log(`Pure dango program exited after: ${state.time.toFixed(3)} milliseconds...`);
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pure-dango",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A simple programming language built in JavaScript",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"files": [
|
|
8
8
|
"src/core",
|
|
9
9
|
"src/runtime",
|
|
10
|
+
"src/types.d.ts",
|
|
11
|
+
"src/globals.d.ts",
|
|
10
12
|
"dist"
|
|
11
13
|
],
|
|
12
14
|
"bin": {
|
package/src/globals.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare namespace NodeJS
|
|
2
|
+
{
|
|
3
|
+
interface Process
|
|
4
|
+
{
|
|
5
|
+
pkg?:
|
|
6
|
+
{
|
|
7
|
+
entrypoint: string;
|
|
8
|
+
defaultEntryPoint: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare const PACKAGE_NAME: string | undefined;
|
|
14
|
+
declare const PACKAGE_VERSION: string | undefined;
|
|
15
|
+
declare const PACKAGE_DESCRIPTION: string | undefined;
|
package/src/index.ts
CHANGED
|
@@ -38,7 +38,7 @@ const
|
|
|
38
38
|
const packageJson =
|
|
39
39
|
{
|
|
40
40
|
name: typeof PACKAGE_NAME !== "undefined" ? PACKAGE_NAME : "pure-dango",
|
|
41
|
-
version: typeof PACKAGE_VERSION !== "undefined" ? PACKAGE_VERSION : "1.8.
|
|
41
|
+
version: typeof PACKAGE_VERSION !== "undefined" ? PACKAGE_VERSION : "1.8.2",
|
|
42
42
|
description: typeof PACKAGE_DESCRIPTION !== "undefined" ? PACKAGE_DESCRIPTION : "A simple programming language built in JavaScript"
|
|
43
43
|
};
|
|
44
44
|
|
package/src/types.d.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
type BaseToken =
|
|
2
|
+
{
|
|
3
|
+
type : string
|
|
4
|
+
value : string
|
|
5
|
+
row : number
|
|
6
|
+
column : number
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
type ParserToken =
|
|
10
|
+
{
|
|
11
|
+
type : string,
|
|
12
|
+
|
|
13
|
+
argument? : ParserToken | null | undefined,
|
|
14
|
+
name? : any,
|
|
15
|
+
value? : any,
|
|
16
|
+
object? : any,
|
|
17
|
+
property? : any,
|
|
18
|
+
|
|
19
|
+
constant? : boolean,
|
|
20
|
+
typeAnnotation? : boolean,
|
|
21
|
+
|
|
22
|
+
operator? : string,
|
|
23
|
+
left? : any,
|
|
24
|
+
right? : any,
|
|
25
|
+
|
|
26
|
+
condition? : ParserToken,
|
|
27
|
+
|
|
28
|
+
args? :
|
|
29
|
+
(
|
|
30
|
+
ParserToken |
|
|
31
|
+
{
|
|
32
|
+
type: string;
|
|
33
|
+
argument: ParserToken;
|
|
34
|
+
row: number;
|
|
35
|
+
column: number;
|
|
36
|
+
}
|
|
37
|
+
)[],
|
|
38
|
+
|
|
39
|
+
index? : ParserToken,
|
|
40
|
+
|
|
41
|
+
initial? : ParserToken | null,
|
|
42
|
+
update? : ParserToken,
|
|
43
|
+
|
|
44
|
+
parameters? : {name: string, default: ParserToken | null, rest: boolean}[],
|
|
45
|
+
methods? : ParserToken[],
|
|
46
|
+
|
|
47
|
+
body? : ParserToken | ParserToken[],
|
|
48
|
+
returnType? : string | null,
|
|
49
|
+
then? : ParserToken,
|
|
50
|
+
else? : ParserToken | ParserToken[] | null,
|
|
51
|
+
|
|
52
|
+
tryBlock?: ParserToken[],
|
|
53
|
+
catchBlock?: ParserToken[],
|
|
54
|
+
finallyBlock?: ParserToken[] | null,
|
|
55
|
+
|
|
56
|
+
names?: string[],
|
|
57
|
+
|
|
58
|
+
discriminant?: ParserToken | null,
|
|
59
|
+
cases?: any[],
|
|
60
|
+
defaultCase?: any,
|
|
61
|
+
|
|
62
|
+
isDeclaration?: boolean,
|
|
63
|
+
|
|
64
|
+
errorVariable?: string,
|
|
65
|
+
|
|
66
|
+
elements? : ParserToken[],
|
|
67
|
+
|
|
68
|
+
className? : string,
|
|
69
|
+
variableName? : string,
|
|
70
|
+
|
|
71
|
+
path? : string,
|
|
72
|
+
|
|
73
|
+
superclass? : string | null,
|
|
74
|
+
|
|
75
|
+
row : number,
|
|
76
|
+
column : number
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
type AST =
|
|
80
|
+
{
|
|
81
|
+
type : "Program",
|
|
82
|
+
body : ParserToken[]
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
type Operator =
|
|
86
|
+
{
|
|
87
|
+
prec : number,
|
|
88
|
+
assoc : string,
|
|
89
|
+
type : string,
|
|
90
|
+
fix? : string
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
type Operators = Record<string, Operator>;
|
|
94
|
+
|
|
95
|
+
type Tokens = BaseToken[];
|
|
96
|
+
|
|
97
|
+
type State =
|
|
98
|
+
{
|
|
99
|
+
time : number,
|
|
100
|
+
position : number,
|
|
101
|
+
lastToken : BaseToken | null
|
|
102
|
+
}
|
package/dist/lib/parser/main.js
DELETED
|
@@ -1,481 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var main_exports = {};
|
|
30
|
-
__export(main_exports, {
|
|
31
|
-
OPERATORS: () => OPERATORS,
|
|
32
|
-
next: () => next,
|
|
33
|
-
parseExpression: () => parseExpression,
|
|
34
|
-
parseStatement: () => parseStatement,
|
|
35
|
-
parser: () => parser,
|
|
36
|
-
peek: () => peek
|
|
37
|
-
});
|
|
38
|
-
module.exports = __toCommonJS(main_exports);
|
|
39
|
-
var import_errors = require("../../runtime/errors");
|
|
40
|
-
var import_stdlib = require("../../runtime/stdlib");
|
|
41
|
-
var handlers = __toESM(require("./handlers"), 1);
|
|
42
|
-
var helpers = __toESM(require("./helpers"), 1);
|
|
43
|
-
const OPERATORS = {
|
|
44
|
-
// operators
|
|
45
|
-
"+": { prec: 10, assoc: "left", type: "binary" },
|
|
46
|
-
"-": { prec: 10, assoc: "left", type: "binary" },
|
|
47
|
-
"*": { prec: 20, assoc: "left", type: "binary" },
|
|
48
|
-
"/": { prec: 20, assoc: "left", type: "binary" },
|
|
49
|
-
"%": { prec: 20, assoc: "left", type: "binary" },
|
|
50
|
-
// assignment operators
|
|
51
|
-
"=": { prec: 5, assoc: "right", type: "assignment" },
|
|
52
|
-
"-=": { prec: 5, assoc: "right", type: "assignment" },
|
|
53
|
-
"+=": { prec: 5, assoc: "right", type: "assignment" },
|
|
54
|
-
"*=": { prec: 5, assoc: "right", type: "assignment" },
|
|
55
|
-
"/=": { prec: 5, assoc: "right", type: "assignment" },
|
|
56
|
-
// equality operators
|
|
57
|
-
"==": { prec: 7, assoc: "left", type: "binary" },
|
|
58
|
-
"!=": { prec: 7, assoc: "left", type: "binary" },
|
|
59
|
-
">": { prec: 8, assoc: "left", type: "binary" },
|
|
60
|
-
"<": { prec: 8, assoc: "left", type: "binary" },
|
|
61
|
-
">=": { prec: 8, assoc: "left", type: "binary" },
|
|
62
|
-
"<=": { prec: 8, assoc: "left", type: "binary" },
|
|
63
|
-
// logical operators
|
|
64
|
-
"&&": { prec: 3, assoc: "left", type: "logical" },
|
|
65
|
-
"||": { prec: 2, assoc: "left", type: "logical" },
|
|
66
|
-
"??": { prec: 1, assoc: "left", type: "logical" },
|
|
67
|
-
// unary operators
|
|
68
|
-
"!": { prec: 30, assoc: "right", type: "unary", fix: "prefix" },
|
|
69
|
-
"~": { prec: 30, assoc: "right", type: "unary", fix: "prefix" },
|
|
70
|
-
"+u": { prec: 30, assoc: "right", type: "unary", fix: "prefix" },
|
|
71
|
-
"-u": { prec: 30, assoc: "right", type: "unary", fix: "prefix" },
|
|
72
|
-
"++": { prec: 30, assoc: "right", type: "unary", fix: "both" },
|
|
73
|
-
"--": { prec: 30, assoc: "right", type: "unary", fix: "both" },
|
|
74
|
-
// bitwise operators
|
|
75
|
-
"&": { prec: 9, assoc: "left", type: "binary" },
|
|
76
|
-
"^": { prec: 8, assoc: "left", type: "binary" },
|
|
77
|
-
"|": { prec: 7, assoc: "left", type: "binary" },
|
|
78
|
-
"<<": { prec: 12, assoc: "left", type: "binary" },
|
|
79
|
-
">>": { prec: 12, assoc: "left", type: "binary" },
|
|
80
|
-
">>>": { prec: 12, assoc: "left", type: "binary" },
|
|
81
|
-
"&=": { prec: 5, assoc: "right", type: "assignment" },
|
|
82
|
-
"|=": { prec: 5, assoc: "right", type: "assignment" },
|
|
83
|
-
"^=": { prec: 5, assoc: "right", type: "assignment" },
|
|
84
|
-
"<<=": { prec: 5, assoc: "right", type: "assignment" },
|
|
85
|
-
">>=": { prec: 5, assoc: "right", type: "assignment" },
|
|
86
|
-
">>>=": { prec: 5, assoc: "right", type: "assignment" }
|
|
87
|
-
};
|
|
88
|
-
function peek(tokens, state) {
|
|
89
|
-
return tokens[state.position];
|
|
90
|
-
}
|
|
91
|
-
function next(tokens, state) {
|
|
92
|
-
if (state.position >= tokens.length)
|
|
93
|
-
return null;
|
|
94
|
-
const token = tokens[state.position++];
|
|
95
|
-
state.lastToken = token;
|
|
96
|
-
return token;
|
|
97
|
-
}
|
|
98
|
-
function isUnaryPrefix(operator) {
|
|
99
|
-
return OPERATORS[operator]?.type === "unary" && OPERATORS[operator].fix !== "postfix";
|
|
100
|
-
}
|
|
101
|
-
function parseStartingToken(token, tokens, state) {
|
|
102
|
-
if (!token)
|
|
103
|
-
(0, import_stdlib.errorTemplate)("parseStartingToken", `Unexpected end of input`);
|
|
104
|
-
let {
|
|
105
|
-
type,
|
|
106
|
-
value,
|
|
107
|
-
row,
|
|
108
|
-
column
|
|
109
|
-
} = token;
|
|
110
|
-
if (type === "Keyword" && value === "function")
|
|
111
|
-
return handlers.parseFunctionNode(tokens, state, true);
|
|
112
|
-
if (type === "Keyword" && value === "inst")
|
|
113
|
-
return handlers.parseInstantationExpression(token, tokens, state);
|
|
114
|
-
if (type === "Operator" && (value === "+" || value === "-")) {
|
|
115
|
-
const previousToken = state.lastToken;
|
|
116
|
-
const isUnaryContext = !previousToken || previousToken.type === "Keyword" || previousToken.value === "(" || previousToken.value === "," || previousToken.type === "Operator" && previousToken.value !== ")" && previousToken.value !== "++" && previousToken.value !== "--";
|
|
117
|
-
if (isUnaryContext)
|
|
118
|
-
value += "u";
|
|
119
|
-
}
|
|
120
|
-
if (type === "Literal" || type === "StringLiteral") {
|
|
121
|
-
return {
|
|
122
|
-
type,
|
|
123
|
-
value,
|
|
124
|
-
row,
|
|
125
|
-
column
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
if (isUnaryPrefix(value)) {
|
|
129
|
-
const valueObject = OPERATORS[value];
|
|
130
|
-
const operand = parseExpression(tokens, valueObject.prec, state);
|
|
131
|
-
if (valueObject.fix === "both") {
|
|
132
|
-
return {
|
|
133
|
-
type: "UnaryExpression",
|
|
134
|
-
value: value.toString(),
|
|
135
|
-
argument: operand,
|
|
136
|
-
row,
|
|
137
|
-
column
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
if (valueObject.fix === "prefix") {
|
|
141
|
-
return {
|
|
142
|
-
type: "UnaryExpression",
|
|
143
|
-
value,
|
|
144
|
-
argument: operand,
|
|
145
|
-
row,
|
|
146
|
-
column
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
throw new import_errors.parseErrors.UnaryOperatorError(value, row, column);
|
|
150
|
-
}
|
|
151
|
-
if (type === "Identifier") {
|
|
152
|
-
const peekToken = peek(tokens, state);
|
|
153
|
-
if (peekToken && peekToken.value === "(")
|
|
154
|
-
return parseFunctionCall(value, tokens, state);
|
|
155
|
-
return {
|
|
156
|
-
type: "VariableReference",
|
|
157
|
-
value,
|
|
158
|
-
row,
|
|
159
|
-
column
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
if (value === "(") {
|
|
163
|
-
const expression = parseExpression(tokens, 0, state);
|
|
164
|
-
const peekToken = peek(tokens, state);
|
|
165
|
-
if (!peekToken || peekToken.value !== ")")
|
|
166
|
-
throw new import_errors.parseErrors.MissingTokenError(")", expression.row, expression.column);
|
|
167
|
-
next(tokens, state);
|
|
168
|
-
return expression;
|
|
169
|
-
}
|
|
170
|
-
if (value === "[") {
|
|
171
|
-
const elements = [];
|
|
172
|
-
while (peek(tokens, state) && peek(tokens, state).value !== "]") {
|
|
173
|
-
const element = parseExpression(tokens, 0, state, true);
|
|
174
|
-
if (element)
|
|
175
|
-
elements.push(element);
|
|
176
|
-
const peekToken = peek(tokens, state);
|
|
177
|
-
if (peekToken && peekToken.value === ",")
|
|
178
|
-
next(tokens, state);
|
|
179
|
-
else if (peekToken && peekToken.value !== "]")
|
|
180
|
-
throw new import_errors.parseErrors.UnexpectedTokenError(peekToken.value, peekToken.row, peekToken.column);
|
|
181
|
-
}
|
|
182
|
-
if (!peek(tokens, state) || peek(tokens, state).value !== "]")
|
|
183
|
-
throw new import_errors.parseErrors.MissingTokenError("]", token.row, token.column);
|
|
184
|
-
next(tokens, state);
|
|
185
|
-
return {
|
|
186
|
-
type: "ArrayLiteral",
|
|
187
|
-
elements,
|
|
188
|
-
row,
|
|
189
|
-
column
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
if (value === "{") {
|
|
193
|
-
const properties = [];
|
|
194
|
-
while (peek(tokens, state) && peek(tokens, state).value !== "}") {
|
|
195
|
-
const keyToken = next(tokens, state);
|
|
196
|
-
const isInvalid = !keyToken || !(keyToken.type === "Identifier" || keyToken.type === "StringLiteral" || keyToken.type === "Literal");
|
|
197
|
-
if (isInvalid)
|
|
198
|
-
throw new import_errors.parseErrors.UnexpectedTokenError(keyToken?.value, keyToken?.row ?? row, keyToken?.column ?? column);
|
|
199
|
-
if (!peek(tokens, state) || peek(tokens, state).value !== ":")
|
|
200
|
-
throw new import_errors.parseErrors.MissingTokenError(":", keyToken.row, keyToken.column);
|
|
201
|
-
next(tokens, state);
|
|
202
|
-
const value2 = parseExpression(tokens, 0, state, true);
|
|
203
|
-
properties.unshift({ key: keyToken.value, value: value2 });
|
|
204
|
-
const peekToken = peek(tokens, state);
|
|
205
|
-
if (peekToken && peekToken.value === ",")
|
|
206
|
-
next(tokens, state);
|
|
207
|
-
else if (peekToken && peekToken.value !== "}")
|
|
208
|
-
throw new import_errors.parseErrors.UnexpectedTokenError(peekToken.value, peekToken.row, peekToken.column);
|
|
209
|
-
}
|
|
210
|
-
if (!peek(tokens, state) || peek(tokens, state).value !== "}")
|
|
211
|
-
throw new import_errors.parseErrors.MissingTokenError("}", token.row, token.column);
|
|
212
|
-
next(tokens, state);
|
|
213
|
-
const node = {
|
|
214
|
-
type: "ObjectLiteral",
|
|
215
|
-
properties,
|
|
216
|
-
row,
|
|
217
|
-
column
|
|
218
|
-
};
|
|
219
|
-
return node;
|
|
220
|
-
}
|
|
221
|
-
if (value === ";")
|
|
222
|
-
return null;
|
|
223
|
-
throw new import_errors.parseErrors.UnexpectedTokenError(value, row, column);
|
|
224
|
-
}
|
|
225
|
-
function parseExpression(tokens, minimumPrecedence = 0, state, stopAtComma = false) {
|
|
226
|
-
let operatorStack = [];
|
|
227
|
-
let outputStack = [];
|
|
228
|
-
let token = next(tokens, state);
|
|
229
|
-
if (!token)
|
|
230
|
-
return null;
|
|
231
|
-
let node = parseStartingToken(token, tokens, state);
|
|
232
|
-
node = helpers.attach(node, tokens, state, stopAtComma);
|
|
233
|
-
outputStack.push(node);
|
|
234
|
-
while (true) {
|
|
235
|
-
let token2 = peek(tokens, state);
|
|
236
|
-
if (helpers.stoppingCheck(token2, stopAtComma))
|
|
237
|
-
break;
|
|
238
|
-
const operatorInfo = OPERATORS[token2.value];
|
|
239
|
-
if (!operatorInfo || operatorInfo.prec < minimumPrecedence)
|
|
240
|
-
break;
|
|
241
|
-
const operator = next(tokens, state);
|
|
242
|
-
while (outputStack.length > 0) {
|
|
243
|
-
const topOperator = operatorStack[operatorStack.length - 1];
|
|
244
|
-
const topInfo = OPERATORS[topOperator?.value] ?? null;
|
|
245
|
-
if (!topInfo)
|
|
246
|
-
break;
|
|
247
|
-
if (topInfo.type !== "assignment" && (operatorInfo.assoc === "left" && operatorInfo.prec <= topInfo.prec || operatorInfo.assoc === "right" && operatorInfo.prec < topInfo.prec)) {
|
|
248
|
-
if (topInfo.type === "unary") {
|
|
249
|
-
const operand = outputStack.pop();
|
|
250
|
-
outputStack.push(
|
|
251
|
-
{
|
|
252
|
-
type: "UnaryExpression",
|
|
253
|
-
value: topOperator.value,
|
|
254
|
-
argument: operand,
|
|
255
|
-
row: topOperator.row,
|
|
256
|
-
column: topOperator.column
|
|
257
|
-
}
|
|
258
|
-
);
|
|
259
|
-
} else {
|
|
260
|
-
const rightNode = outputStack.pop();
|
|
261
|
-
const leftNode = outputStack.pop();
|
|
262
|
-
outputStack.push(
|
|
263
|
-
{
|
|
264
|
-
type: topInfo.type === "logical" ? "LogicalExpression" : "BinaryExpression",
|
|
265
|
-
operator: topOperator.value,
|
|
266
|
-
left: leftNode,
|
|
267
|
-
right: rightNode,
|
|
268
|
-
row: topOperator.row,
|
|
269
|
-
column: topOperator.column
|
|
270
|
-
}
|
|
271
|
-
);
|
|
272
|
-
}
|
|
273
|
-
operatorStack.pop();
|
|
274
|
-
} else
|
|
275
|
-
break;
|
|
276
|
-
}
|
|
277
|
-
if (operatorInfo.type === "assignment") {
|
|
278
|
-
const leftNode = outputStack.pop();
|
|
279
|
-
if (leftNode.type !== "VariableReference" && leftNode.type !== "ArrayAccess" && leftNode.type !== "MemberExpression")
|
|
280
|
-
throw new import_errors.parseErrors.AssignmentError(operator.value, operator.row, operator.column);
|
|
281
|
-
const rightNode = parseExpression(tokens, operatorInfo.prec, state, stopAtComma);
|
|
282
|
-
const baseOperators = {
|
|
283
|
-
"+=": "+",
|
|
284
|
-
"-=": "-",
|
|
285
|
-
"*=": "*",
|
|
286
|
-
"/=": "/",
|
|
287
|
-
"%=": "%",
|
|
288
|
-
"&=": "&",
|
|
289
|
-
"|=": "|",
|
|
290
|
-
"^=": "^",
|
|
291
|
-
"<<=": "<<",
|
|
292
|
-
">>=": ">>",
|
|
293
|
-
">>>=": ">>>"
|
|
294
|
-
};
|
|
295
|
-
const name = leftNode.type === "ArrayAccess" || leftNode.type === "MemberExpression" ? leftNode : leftNode.value;
|
|
296
|
-
const valueType = OPERATORS[baseOperators[operator.value]]?.type === "logical" ? "LogicalExpression" : "BinaryExpression";
|
|
297
|
-
outputStack.push(
|
|
298
|
-
{
|
|
299
|
-
type: "Assignment",
|
|
300
|
-
name,
|
|
301
|
-
value: operator.value === "=" ? rightNode : {
|
|
302
|
-
type: valueType,
|
|
303
|
-
operator: baseOperators[operator.value],
|
|
304
|
-
left: leftNode,
|
|
305
|
-
right: rightNode
|
|
306
|
-
},
|
|
307
|
-
row: operator.row,
|
|
308
|
-
column: operator.column
|
|
309
|
-
}
|
|
310
|
-
);
|
|
311
|
-
break;
|
|
312
|
-
}
|
|
313
|
-
operatorStack.push(operator);
|
|
314
|
-
let nextToken = next(tokens, state);
|
|
315
|
-
if (!nextToken)
|
|
316
|
-
throw new import_errors.parseErrors.UnexpectedTokenError("end of input", operator.row, operator.column);
|
|
317
|
-
let node2 = parseStartingToken(nextToken, tokens, state);
|
|
318
|
-
if (!node2)
|
|
319
|
-
throw new import_errors.parseErrors.UnexpectedTokenError(nextToken.value, nextToken.row, nextToken.column);
|
|
320
|
-
node2 = helpers.attach(node2, tokens, state, stopAtComma);
|
|
321
|
-
outputStack.push(node2);
|
|
322
|
-
}
|
|
323
|
-
while (operatorStack.length) {
|
|
324
|
-
const operator = operatorStack.pop();
|
|
325
|
-
const operatorInfo = OPERATORS[operator.value];
|
|
326
|
-
if (operatorInfo.type === "unary") {
|
|
327
|
-
const operand = outputStack.pop();
|
|
328
|
-
outputStack.push(
|
|
329
|
-
{
|
|
330
|
-
type: "UnaryExpression",
|
|
331
|
-
value: operator.value,
|
|
332
|
-
argument: operand,
|
|
333
|
-
row: operator.row,
|
|
334
|
-
column: operator.column
|
|
335
|
-
}
|
|
336
|
-
);
|
|
337
|
-
} else {
|
|
338
|
-
const rightNode = outputStack.pop();
|
|
339
|
-
const leftNode = outputStack.pop();
|
|
340
|
-
outputStack.push(
|
|
341
|
-
{
|
|
342
|
-
type: operatorInfo.type === "logical" ? "LogicalExpression" : "BinaryExpression",
|
|
343
|
-
operator: operator.value,
|
|
344
|
-
left: leftNode,
|
|
345
|
-
right: rightNode,
|
|
346
|
-
row: operator.row,
|
|
347
|
-
column: operator.column
|
|
348
|
-
}
|
|
349
|
-
);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
const maybeTernary = peek(tokens, state);
|
|
353
|
-
if (maybeTernary && maybeTernary.value === "?") {
|
|
354
|
-
next(tokens, state);
|
|
355
|
-
const thenBranch = parseExpression(tokens, 0, state, stopAtComma);
|
|
356
|
-
const elseColon = peek(tokens, state);
|
|
357
|
-
if (!elseColon || elseColon.value !== ":")
|
|
358
|
-
throw new import_errors.parseErrors.MissingTokenError(":", elseColon?.row ?? 0, elseColon?.column ?? 0);
|
|
359
|
-
next(tokens, state);
|
|
360
|
-
const elseBranch = parseExpression(tokens, 0, state, stopAtComma);
|
|
361
|
-
return {
|
|
362
|
-
type: "TernaryExpression",
|
|
363
|
-
condition: outputStack[0],
|
|
364
|
-
then: thenBranch,
|
|
365
|
-
else: elseBranch,
|
|
366
|
-
row: maybeTernary.row,
|
|
367
|
-
column: maybeTernary.column
|
|
368
|
-
};
|
|
369
|
-
}
|
|
370
|
-
return outputStack[0];
|
|
371
|
-
}
|
|
372
|
-
function parseFunctionCall(name, tokens, state) {
|
|
373
|
-
const row = state.lastToken?.row ?? 0;
|
|
374
|
-
const column = state.lastToken?.column ?? 0;
|
|
375
|
-
next(tokens, state);
|
|
376
|
-
let args = [];
|
|
377
|
-
const peekToken = peek(tokens, state);
|
|
378
|
-
if (peekToken && peekToken.value === ")") {
|
|
379
|
-
next(tokens, state);
|
|
380
|
-
return {
|
|
381
|
-
type: "FunctionCall",
|
|
382
|
-
name,
|
|
383
|
-
args,
|
|
384
|
-
row,
|
|
385
|
-
column
|
|
386
|
-
};
|
|
387
|
-
}
|
|
388
|
-
while (peek(tokens, state) && peek(tokens, state).value !== ")") {
|
|
389
|
-
if (peek(tokens, state)?.value === "...") {
|
|
390
|
-
next(tokens, state);
|
|
391
|
-
const expression = parseExpression(tokens, 0, state, true);
|
|
392
|
-
args.push(
|
|
393
|
-
{
|
|
394
|
-
type: "SpreadElement",
|
|
395
|
-
argument: expression,
|
|
396
|
-
row,
|
|
397
|
-
column
|
|
398
|
-
}
|
|
399
|
-
);
|
|
400
|
-
} else {
|
|
401
|
-
const expression = parseExpression(tokens, 0, state, true);
|
|
402
|
-
if (!expression) {
|
|
403
|
-
console.warn(`
|
|
404
|
-
Expected expression in function call "${name}"`);
|
|
405
|
-
break;
|
|
406
|
-
}
|
|
407
|
-
args.push(expression);
|
|
408
|
-
}
|
|
409
|
-
const peekToken2 = peek(tokens, state);
|
|
410
|
-
if (peekToken2 && peekToken2.value === ",")
|
|
411
|
-
next(tokens, state);
|
|
412
|
-
else if (peekToken2 && peekToken2.value !== ")")
|
|
413
|
-
throw new import_errors.parseErrors.UnexpectedTokenError(peekToken2.value, peekToken2.row, peekToken2.column);
|
|
414
|
-
}
|
|
415
|
-
if (!peek(tokens, state) || peek(tokens, state).value !== ")") {
|
|
416
|
-
const lastToken = tokens[state.position - 1];
|
|
417
|
-
const row2 = lastToken?.row ?? 0;
|
|
418
|
-
const column2 = lastToken?.column ?? 0;
|
|
419
|
-
throw new import_errors.parseErrors.FunctionCallError(`Missing ")" in function call for name "${name}"`, row2, column2);
|
|
420
|
-
}
|
|
421
|
-
next(tokens, state);
|
|
422
|
-
if (peek(tokens, state) && peek(tokens, state).value === "(")
|
|
423
|
-
throw new import_errors.parseErrors.ChainedFunctionCallError(name, peek(tokens, state).row, peek(tokens, state).column);
|
|
424
|
-
return {
|
|
425
|
-
type: "FunctionCall",
|
|
426
|
-
name,
|
|
427
|
-
args,
|
|
428
|
-
row,
|
|
429
|
-
column
|
|
430
|
-
};
|
|
431
|
-
}
|
|
432
|
-
function parseStatement(ast, tokens, state) {
|
|
433
|
-
const token = peek(tokens, state);
|
|
434
|
-
if (!token)
|
|
435
|
-
return null;
|
|
436
|
-
if (token.type === "Keyword") {
|
|
437
|
-
if (handlers.variableHandler(ast, token, tokens, state)) return true;
|
|
438
|
-
else if (handlers.ifHandler(ast, token, tokens, state)) return true;
|
|
439
|
-
else if (handlers.doWhileHandler(ast, token, tokens, state)) return true;
|
|
440
|
-
else if (handlers.whileHandler(ast, token, tokens, state)) return true;
|
|
441
|
-
else if (handlers.loopControlHandler(ast, token, tokens, state)) return true;
|
|
442
|
-
else if (handlers.forHandler(ast, token, tokens, state)) return true;
|
|
443
|
-
else if (handlers.functionHandler(ast, token, tokens, state)) return true;
|
|
444
|
-
else if (handlers.returnHandler(ast, token, tokens, state)) return true;
|
|
445
|
-
else if (handlers.importHandler(ast, token, tokens, state)) return true;
|
|
446
|
-
else if (handlers.classHandler(ast, token, tokens, state)) return true;
|
|
447
|
-
else if (handlers.tryHandler(ast, token, tokens, state)) return true;
|
|
448
|
-
else if (handlers.switchHandler(ast, token, tokens, state)) return true;
|
|
449
|
-
}
|
|
450
|
-
const expression = parseExpression(tokens, 0, state);
|
|
451
|
-
if (expression)
|
|
452
|
-
ast.body.push(expression);
|
|
453
|
-
return expression;
|
|
454
|
-
}
|
|
455
|
-
function parser(tokens) {
|
|
456
|
-
let state = {
|
|
457
|
-
position: 0,
|
|
458
|
-
time: 0,
|
|
459
|
-
lastToken: null
|
|
460
|
-
};
|
|
461
|
-
let ast = {
|
|
462
|
-
type: "Program",
|
|
463
|
-
body: []
|
|
464
|
-
};
|
|
465
|
-
while (state.position < tokens.length) {
|
|
466
|
-
const token = peek(tokens, state);
|
|
467
|
-
if (!token)
|
|
468
|
-
break;
|
|
469
|
-
parseStatement(ast, tokens, state);
|
|
470
|
-
}
|
|
471
|
-
return ast;
|
|
472
|
-
}
|
|
473
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
474
|
-
0 && (module.exports = {
|
|
475
|
-
OPERATORS,
|
|
476
|
-
next,
|
|
477
|
-
parseExpression,
|
|
478
|
-
parseStatement,
|
|
479
|
-
parser,
|
|
480
|
-
peek
|
|
481
|
-
});
|
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var tokenizer_exports = {};
|
|
30
|
-
__export(tokenizer_exports, {
|
|
31
|
-
tokenizer: () => tokenizer
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(tokenizer_exports);
|
|
34
|
-
var import_errors = require("../../runtime/errors");
|
|
35
|
-
var quote_crimes = __toESM(require("./funnies"), 1);
|
|
36
|
-
const REGEX = new RegExp([
|
|
37
|
-
// strings
|
|
38
|
-
"(`(?:[^`\\\\]|\\\\.)*`)",
|
|
39
|
-
// backtick strings
|
|
40
|
-
"('(?:[^'\\\\]|\\\\.)*')",
|
|
41
|
-
// single quote strings
|
|
42
|
-
"(\u201C(?:[^\u201C\u201D\\\\]|\\\\.)*\u201D)",
|
|
43
|
-
// curly single quote strings
|
|
44
|
-
"(\u2018(?:[^\u2018\u2019\\\\]|\\\\.)*\u2019)",
|
|
45
|
-
// curly double quote strings
|
|
46
|
-
// multi-char operators
|
|
47
|
-
"\\?\\?",
|
|
48
|
-
"&&",
|
|
49
|
-
"\\|\\|",
|
|
50
|
-
"!=",
|
|
51
|
-
"<=",
|
|
52
|
-
">=",
|
|
53
|
-
"==",
|
|
54
|
-
"--",
|
|
55
|
-
"\\+\\+",
|
|
56
|
-
"-=",
|
|
57
|
-
"\\+=",
|
|
58
|
-
"/=",
|
|
59
|
-
"\\*=",
|
|
60
|
-
"&=",
|
|
61
|
-
"\\|=",
|
|
62
|
-
"\\^=",
|
|
63
|
-
// bitwise assignment
|
|
64
|
-
"<<=",
|
|
65
|
-
">>=",
|
|
66
|
-
">>>=",
|
|
67
|
-
// shift assignment
|
|
68
|
-
">>>",
|
|
69
|
-
">>",
|
|
70
|
-
"<<",
|
|
71
|
-
// shifts (longest first)
|
|
72
|
-
"\\.\\..",
|
|
73
|
-
// spread
|
|
74
|
-
// number literals
|
|
75
|
-
"0b[01]+",
|
|
76
|
-
// binary
|
|
77
|
-
"0x[0-9a-fA-F]+",
|
|
78
|
-
// hex
|
|
79
|
-
"\\d+(\\.\\d+)?",
|
|
80
|
-
// float
|
|
81
|
-
// identifiers
|
|
82
|
-
"[\\p{L}_][\\p{L}\\d_]*",
|
|
83
|
-
// single char
|
|
84
|
-
"[+\\-*/=()&^%$#@!<>?:~,|]",
|
|
85
|
-
"[\\[\\]{}]",
|
|
86
|
-
"[\\n;]",
|
|
87
|
-
"\\."
|
|
88
|
-
].join("|"), "gu");
|
|
89
|
-
const keywordSet = /* @__PURE__ */ new Set(["new", "const", "if", "else", "while", "continue", "break", "for", "in", "of", "function", "return", "import", "class", "extends", "inst", "internal", "try", "catch", "finally", "do", "switch", "case", "default"]);
|
|
90
|
-
const separatorSet = /* @__PURE__ */ new Set(["\n", ",", " ", ";"]);
|
|
91
|
-
const operatorSet = /* @__PURE__ */ new Set([
|
|
92
|
-
"...",
|
|
93
|
-
"??",
|
|
94
|
-
"&&",
|
|
95
|
-
"||",
|
|
96
|
-
"{",
|
|
97
|
-
"}",
|
|
98
|
-
"[",
|
|
99
|
-
"]",
|
|
100
|
-
"!=",
|
|
101
|
-
"<=",
|
|
102
|
-
">=",
|
|
103
|
-
"==",
|
|
104
|
-
"-=",
|
|
105
|
-
"+=",
|
|
106
|
-
"++",
|
|
107
|
-
"/=",
|
|
108
|
-
"*=",
|
|
109
|
-
"--",
|
|
110
|
-
"&=",
|
|
111
|
-
"|=",
|
|
112
|
-
"^=",
|
|
113
|
-
"<<=",
|
|
114
|
-
">>=",
|
|
115
|
-
">>>=",
|
|
116
|
-
">>>",
|
|
117
|
-
">>",
|
|
118
|
-
"<<",
|
|
119
|
-
"+",
|
|
120
|
-
"-",
|
|
121
|
-
"*",
|
|
122
|
-
"/",
|
|
123
|
-
"%",
|
|
124
|
-
"=",
|
|
125
|
-
"(",
|
|
126
|
-
")",
|
|
127
|
-
"&",
|
|
128
|
-
"^",
|
|
129
|
-
"!",
|
|
130
|
-
"<",
|
|
131
|
-
">",
|
|
132
|
-
"?",
|
|
133
|
-
":",
|
|
134
|
-
"~",
|
|
135
|
-
".",
|
|
136
|
-
"|"
|
|
137
|
-
]);
|
|
138
|
-
function getType(code) {
|
|
139
|
-
if (keywordSet.has(code))
|
|
140
|
-
return "Keyword";
|
|
141
|
-
if (separatorSet.has(code))
|
|
142
|
-
return "Separator";
|
|
143
|
-
if (operatorSet.has(code))
|
|
144
|
-
return "Operator";
|
|
145
|
-
if (/^["'`]/.test(code))
|
|
146
|
-
return "StringLiteral";
|
|
147
|
-
if (/^\d/.test(code))
|
|
148
|
-
return "Literal";
|
|
149
|
-
return "Identifier";
|
|
150
|
-
}
|
|
151
|
-
function tokenizer(code) {
|
|
152
|
-
const tokens = [];
|
|
153
|
-
const uid = Math.random().toString(36).slice(2);
|
|
154
|
-
const stringMeta = /* @__PURE__ */ new Map();
|
|
155
|
-
const out = [];
|
|
156
|
-
let row = 1;
|
|
157
|
-
let column = 1;
|
|
158
|
-
let i = 0;
|
|
159
|
-
let stringIndex = 0;
|
|
160
|
-
while (i < code.length) {
|
|
161
|
-
const character = code[i];
|
|
162
|
-
if (character === "#") {
|
|
163
|
-
while (i < code.length && code[i] !== "\n")
|
|
164
|
-
i++;
|
|
165
|
-
continue;
|
|
166
|
-
}
|
|
167
|
-
if (character === "/" && code[i + 1] === "*") {
|
|
168
|
-
while (i < code.length && !(code[i] === "*" && code[i + 1] === "/")) {
|
|
169
|
-
if (code[i] === "\n") {
|
|
170
|
-
row++;
|
|
171
|
-
column = 1;
|
|
172
|
-
}
|
|
173
|
-
i++;
|
|
174
|
-
}
|
|
175
|
-
i += 2;
|
|
176
|
-
continue;
|
|
177
|
-
}
|
|
178
|
-
if ((character === '"' || character === "\u201C" || character === "'" || character === "\u2018" || character === "`") && (i === 0 || !/[\p{L}\d]/u.test(code[i - 1]))) {
|
|
179
|
-
const quote = character === "\u201C" ? "\u201D" : character === "\u2018" ? "\u2019" : character;
|
|
180
|
-
const stringRow = row;
|
|
181
|
-
const stringColumn = column;
|
|
182
|
-
const start = i;
|
|
183
|
-
i++;
|
|
184
|
-
column++;
|
|
185
|
-
while (i < code.length && code[i] !== quote) {
|
|
186
|
-
const type = quote === "\u201D" ? "double" : "single";
|
|
187
|
-
const opening = type === "double" ? "\u201C" : "\u2018";
|
|
188
|
-
if (code[i] === "\u201C" && quote === "\u201D" || code[i] === "\u2018" && quote === "\u2019") {
|
|
189
|
-
const quoteCrimesMessage = quote_crimes.QuoteCrimesMessage(quote_crimes.incrementQuoteCrimes() - 1, opening) + " ";
|
|
190
|
-
throw new import_errors.Tokenizer(
|
|
191
|
-
quoteCrimesMessage + `Found: ${opening}...${opening}. Tip: Either match them or just use normal ${type} quotes`,
|
|
192
|
-
row,
|
|
193
|
-
column
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
if (code[i] === "\\") {
|
|
197
|
-
i += 2;
|
|
198
|
-
column += 2;
|
|
199
|
-
} else {
|
|
200
|
-
if (code[i] === "\n") {
|
|
201
|
-
row++;
|
|
202
|
-
column = 1;
|
|
203
|
-
} else
|
|
204
|
-
column++;
|
|
205
|
-
i++;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
i++;
|
|
209
|
-
column++;
|
|
210
|
-
const raw = code.slice(start, i);
|
|
211
|
-
const placeholder = `__STRING${uid}_${stringIndex++}__`;
|
|
212
|
-
stringMeta.set(
|
|
213
|
-
placeholder,
|
|
214
|
-
{
|
|
215
|
-
value: raw.slice(1, -1).replace(/\\"/g, '"').replace(/\\'/g, "'").replace(/\\\\/g, "\\").replace(/\\n/g, "\n").replace(/\\t/g, " ").replace(/\\r/g, "\r"),
|
|
216
|
-
row: stringRow,
|
|
217
|
-
column: stringColumn
|
|
218
|
-
}
|
|
219
|
-
);
|
|
220
|
-
out.push(placeholder);
|
|
221
|
-
continue;
|
|
222
|
-
}
|
|
223
|
-
if (character === "\n") {
|
|
224
|
-
row++;
|
|
225
|
-
column = 1;
|
|
226
|
-
} else
|
|
227
|
-
column++;
|
|
228
|
-
out.push(character);
|
|
229
|
-
i++;
|
|
230
|
-
}
|
|
231
|
-
const processed = out.join("");
|
|
232
|
-
row = 1;
|
|
233
|
-
column = 1;
|
|
234
|
-
let commented = false;
|
|
235
|
-
const matches = processed.matchAll(REGEX);
|
|
236
|
-
for (const match of matches) {
|
|
237
|
-
const value = match[0];
|
|
238
|
-
if (value === "\n") {
|
|
239
|
-
row++;
|
|
240
|
-
column = 1;
|
|
241
|
-
commented = false;
|
|
242
|
-
continue;
|
|
243
|
-
}
|
|
244
|
-
if (value === "#") {
|
|
245
|
-
commented = true;
|
|
246
|
-
continue;
|
|
247
|
-
}
|
|
248
|
-
if (commented || value === " ") {
|
|
249
|
-
column += value.length;
|
|
250
|
-
continue;
|
|
251
|
-
}
|
|
252
|
-
if (value === ",") {
|
|
253
|
-
tokens.push(
|
|
254
|
-
{
|
|
255
|
-
type: "Separator",
|
|
256
|
-
value,
|
|
257
|
-
row,
|
|
258
|
-
column
|
|
259
|
-
}
|
|
260
|
-
);
|
|
261
|
-
column += value.length;
|
|
262
|
-
continue;
|
|
263
|
-
}
|
|
264
|
-
if (stringMeta.has(value)) {
|
|
265
|
-
const meta = stringMeta.get(value);
|
|
266
|
-
tokens.push(
|
|
267
|
-
{
|
|
268
|
-
type: "StringLiteral",
|
|
269
|
-
value: meta.value,
|
|
270
|
-
row: meta.row,
|
|
271
|
-
column: meta.column
|
|
272
|
-
}
|
|
273
|
-
);
|
|
274
|
-
column += value.length;
|
|
275
|
-
continue;
|
|
276
|
-
}
|
|
277
|
-
const lines = value.split("\n");
|
|
278
|
-
if (lines.length > 1) {
|
|
279
|
-
row += lines.length - 1;
|
|
280
|
-
column = lines[lines.length - 1].length + 1;
|
|
281
|
-
}
|
|
282
|
-
tokens.push(
|
|
283
|
-
{
|
|
284
|
-
type: getType(value),
|
|
285
|
-
value,
|
|
286
|
-
row,
|
|
287
|
-
column
|
|
288
|
-
}
|
|
289
|
-
);
|
|
290
|
-
if (lines.length === 1)
|
|
291
|
-
column += value.length;
|
|
292
|
-
}
|
|
293
|
-
return tokens;
|
|
294
|
-
}
|
|
295
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
296
|
-
0 && (module.exports = {
|
|
297
|
-
tokenizer
|
|
298
|
-
});
|