@aeriajs/compiler 0.0.61 → 0.0.63
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/ast.d.ts +1 -0
- package/dist/ast.js +4 -6
- package/dist/codegen/generateContracts.js +15 -19
- package/dist/codegen/generateExports.js +5 -9
- package/dist/codegen/generateJSCollections.js +13 -17
- package/dist/codegen/generateTSCollections.js +13 -17
- package/dist/codegen/index.js +4 -20
- package/dist/codegen/utils.js +25 -37
- package/dist/codegen.js +8 -45
- package/dist/compile.js +19 -58
- package/dist/diagnostic.js +1 -5
- package/dist/guards.js +3 -41
- package/dist/index.js +7 -23
- package/dist/lexer.js +48 -52
- package/dist/parser.js +267 -297
- package/dist/semantic.js +31 -68
- package/dist/token.js +1 -4
- package/dist/types.js +1 -2
- package/dist/utils.js +1 -4
- package/package.json +6 -9
- package/dist/ast.mjs +0 -24
- package/dist/codegen/generateContracts.mjs +0 -85
- package/dist/codegen/generateExports.mjs +0 -42
- package/dist/codegen/generateJSCollections.mjs +0 -103
- package/dist/codegen/generateTSCollections.mjs +0 -114
- package/dist/codegen/index.mjs +0 -5
- package/dist/codegen/utils.mjs +0 -161
- package/dist/codegen.mjs +0 -54
- package/dist/compile.mjs +0 -69
- package/dist/diagnostic.mjs +0 -18
- package/dist/guards.mjs +0 -8
- package/dist/index.mjs +0 -8
- package/dist/lexer.mjs +0 -375
- package/dist/parser.mjs +0 -1297
- package/dist/semantic.mjs +0 -202
- package/dist/token.mjs +0 -24
- package/dist/types.mjs +0 -1
- package/dist/utils.mjs +0 -12
package/dist/compile.js
CHANGED
|
@@ -1,55 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.compileFromFiles = exports.parseAndCheck = exports.postflight = exports.GLOB_PATTERN = void 0;
|
|
37
|
-
const diagnostic_js_1 = require("./diagnostic.js");
|
|
38
|
-
const lexer_js_1 = require("./lexer.js");
|
|
39
|
-
const parser_js_1 = require("./parser.js");
|
|
40
|
-
const semantic_js_1 = require("./semantic.js");
|
|
41
|
-
const codegen_js_1 = require("./codegen.js");
|
|
42
|
-
const fs = __importStar(require("node:fs"));
|
|
43
|
-
exports.GLOB_PATTERN = '**/*.aeria';
|
|
44
|
-
const postflight = (ast) => {
|
|
1
|
+
import { Diagnostic } from './diagnostic.js';
|
|
2
|
+
import { tokenize } from './lexer.js';
|
|
3
|
+
import { parse, locationMap } from './parser.js';
|
|
4
|
+
import { analyze } from './semantic.js';
|
|
5
|
+
import { generateCode } from './codegen.js';
|
|
6
|
+
import * as fs from 'node:fs';
|
|
7
|
+
export const GLOB_PATTERN = '**/*.aeria';
|
|
8
|
+
export const postflight = (ast) => {
|
|
45
9
|
const errors = [];
|
|
46
10
|
for (const node of ast.collections) {
|
|
47
11
|
if (node.functionSets?.length) {
|
|
48
12
|
for (const [functionSetName, locationSymbol] of node.functionSets) {
|
|
49
13
|
const functionSet = ast.functionsets.find(({ name }) => name === functionSetName);
|
|
50
14
|
if (!functionSet) {
|
|
51
|
-
const location =
|
|
52
|
-
errors.push(new
|
|
15
|
+
const location = locationMap.get(locationSymbol);
|
|
16
|
+
errors.push(new Diagnostic(`invalid function set "${functionSetName}"`, location));
|
|
53
17
|
continue;
|
|
54
18
|
}
|
|
55
19
|
node.functions.push(...functionSet.functions);
|
|
@@ -60,20 +24,19 @@ const postflight = (ast) => {
|
|
|
60
24
|
errors,
|
|
61
25
|
};
|
|
62
26
|
};
|
|
63
|
-
|
|
64
|
-
const parseAndCheck = async (sources, options = {}) => {
|
|
27
|
+
export const parseAndCheck = async (sources, options = {}) => {
|
|
65
28
|
const errors = [];
|
|
66
29
|
const allTokens = [];
|
|
67
30
|
for (const fileName in sources) {
|
|
68
|
-
const { errors: lexerErrors, tokens } =
|
|
31
|
+
const { errors: lexerErrors, tokens } = tokenize(sources[fileName], fileName);
|
|
69
32
|
if (lexerErrors.length > 0) {
|
|
70
33
|
errors.push(...lexerErrors);
|
|
71
34
|
}
|
|
72
35
|
allTokens.push(...tokens);
|
|
73
36
|
}
|
|
74
|
-
const { errors: parserErrors, ast } =
|
|
75
|
-
const { errors: semanticErrors } = await
|
|
76
|
-
const { errors: postflightErrors } =
|
|
37
|
+
const { errors: parserErrors, ast } = parse(allTokens);
|
|
38
|
+
const { errors: semanticErrors } = await analyze(ast, options);
|
|
39
|
+
const { errors: postflightErrors } = postflight(ast);
|
|
77
40
|
errors.push(...parserErrors.concat(semanticErrors, postflightErrors));
|
|
78
41
|
return {
|
|
79
42
|
success: errors.length === 0,
|
|
@@ -82,21 +45,20 @@ const parseAndCheck = async (sources, options = {}) => {
|
|
|
82
45
|
ast,
|
|
83
46
|
};
|
|
84
47
|
};
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
const fileList = await Array.fromAsync(fs.promises.glob(exports.GLOB_PATTERN));
|
|
48
|
+
export const compileFromFiles = async (options) => {
|
|
49
|
+
const fileList = await Array.fromAsync(fs.promises.glob(GLOB_PATTERN));
|
|
88
50
|
const sources = {};
|
|
89
51
|
for (const fileName of fileList) {
|
|
90
52
|
sources[fileName] = await fs.promises.readFile(fileName, {
|
|
91
53
|
encoding: 'utf-8',
|
|
92
54
|
});
|
|
93
55
|
}
|
|
94
|
-
const result = await
|
|
56
|
+
const result = await parseAndCheck(sources, options);
|
|
95
57
|
if (!result.ast || result.errorCount > 0) {
|
|
96
58
|
return result;
|
|
97
59
|
}
|
|
98
60
|
if (options.outDir) {
|
|
99
|
-
const emittedFiles = await
|
|
61
|
+
const emittedFiles = await generateCode(result.ast, options);
|
|
100
62
|
return {
|
|
101
63
|
...result,
|
|
102
64
|
emittedFiles,
|
|
@@ -104,4 +66,3 @@ const compileFromFiles = async (options) => {
|
|
|
104
66
|
}
|
|
105
67
|
return result;
|
|
106
68
|
};
|
|
107
|
-
exports.compileFromFiles = compileFromFiles;
|
package/dist/diagnostic.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Diagnostic = void 0;
|
|
4
1
|
const emptyLocation = {
|
|
5
2
|
file: '',
|
|
6
3
|
index: 0,
|
|
@@ -8,7 +5,7 @@ const emptyLocation = {
|
|
|
8
5
|
start: 0,
|
|
9
6
|
end: 0,
|
|
10
7
|
};
|
|
11
|
-
class Diagnostic extends Error {
|
|
8
|
+
export class Diagnostic extends Error {
|
|
12
9
|
message;
|
|
13
10
|
location;
|
|
14
11
|
constructor(message, location = emptyLocation) {
|
|
@@ -20,4 +17,3 @@ class Diagnostic extends Error {
|
|
|
20
17
|
}
|
|
21
18
|
}
|
|
22
19
|
}
|
|
23
|
-
exports.Diagnostic = Diagnostic;
|
package/dist/guards.js
CHANGED
|
@@ -1,45 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.isValidPropertyModifier = exports.isNativePropertyType = void 0;
|
|
37
|
-
const AST = __importStar(require("./ast.js"));
|
|
38
|
-
const isNativePropertyType = (value) => {
|
|
1
|
+
import * as AST from './ast.js';
|
|
2
|
+
export const isNativePropertyType = (value) => {
|
|
39
3
|
return value in AST.PropertyType;
|
|
40
4
|
};
|
|
41
|
-
|
|
42
|
-
const isValidPropertyModifier = (value) => {
|
|
5
|
+
export const isValidPropertyModifier = (value) => {
|
|
43
6
|
return value in AST.PropertyModifiers;
|
|
44
7
|
};
|
|
45
|
-
exports.isValidPropertyModifier = isValidPropertyModifier;
|
package/dist/index.js
CHANGED
|
@@ -1,23 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./ast.js"), exports);
|
|
18
|
-
__exportStar(require("./compile.js"), exports);
|
|
19
|
-
__exportStar(require("./parser.js"), exports);
|
|
20
|
-
__exportStar(require("./lexer.js"), exports);
|
|
21
|
-
__exportStar(require("./semantic.js"), exports);
|
|
22
|
-
__exportStar(require("./token.js"), exports);
|
|
23
|
-
__exportStar(require("./diagnostic.js"), exports);
|
|
1
|
+
export * from './ast.js';
|
|
2
|
+
export * from './compile.js';
|
|
3
|
+
export * from './parser.js';
|
|
4
|
+
export * from './lexer.js';
|
|
5
|
+
export * from './semantic.js';
|
|
6
|
+
export * from './token.js';
|
|
7
|
+
export * from './diagnostic.js';
|
package/dist/lexer.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const token_js_1 = require("./token.js");
|
|
5
|
-
const diagnostic_js_1 = require("./diagnostic.js");
|
|
6
|
-
exports.COLLECTION_KEYWORDS = [
|
|
1
|
+
import { TokenType } from './token.js';
|
|
2
|
+
import { Diagnostic } from './diagnostic.js';
|
|
3
|
+
export const COLLECTION_KEYWORDS = [
|
|
7
4
|
'actions',
|
|
8
5
|
'additionalProperties',
|
|
9
6
|
'filters',
|
|
@@ -25,7 +22,7 @@ exports.COLLECTION_KEYWORDS = [
|
|
|
25
22
|
'unique',
|
|
26
23
|
'writable',
|
|
27
24
|
];
|
|
28
|
-
|
|
25
|
+
export const COLLECTION_ACTIONS_KEYWORDS = [
|
|
29
26
|
'ask',
|
|
30
27
|
'button',
|
|
31
28
|
'clearItem',
|
|
@@ -44,16 +41,16 @@ exports.COLLECTION_ACTIONS_KEYWORDS = [
|
|
|
44
41
|
'setItem',
|
|
45
42
|
'translate',
|
|
46
43
|
];
|
|
47
|
-
|
|
44
|
+
export const COLLECTION_SEARCH_KEYWORDS = [
|
|
48
45
|
'indexes',
|
|
49
46
|
'placeholder',
|
|
50
47
|
'exactMatches',
|
|
51
48
|
];
|
|
52
|
-
|
|
49
|
+
export const COLLECTION_LAYOUT_KEYWORDS = [
|
|
53
50
|
'name',
|
|
54
51
|
'options',
|
|
55
52
|
];
|
|
56
|
-
|
|
53
|
+
export const COLLECTION_LAYOUT_OPTIONS_KEYWORDS = [
|
|
57
54
|
'title',
|
|
58
55
|
'picture',
|
|
59
56
|
'badge',
|
|
@@ -61,27 +58,27 @@ exports.COLLECTION_LAYOUT_OPTIONS_KEYWORDS = [
|
|
|
61
58
|
'active',
|
|
62
59
|
'translateBadge',
|
|
63
60
|
];
|
|
64
|
-
|
|
61
|
+
export const COLLECTION_FORM_LAYOUT_KEYWORDS = [
|
|
65
62
|
'fields',
|
|
66
63
|
'if',
|
|
67
64
|
'span',
|
|
68
65
|
'verticalSpacing',
|
|
69
66
|
'separator',
|
|
70
67
|
];
|
|
71
|
-
|
|
68
|
+
export const CONTRACT_KEYWORDS = [
|
|
72
69
|
'roles',
|
|
73
70
|
'payload',
|
|
74
71
|
'query',
|
|
75
72
|
'response',
|
|
76
73
|
];
|
|
77
|
-
|
|
74
|
+
export const TOPLEVEL_KEYWORDS = [
|
|
78
75
|
'collection',
|
|
79
76
|
'contract',
|
|
80
77
|
'functionset',
|
|
81
78
|
];
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
export const MISC_KEYWORDS = ['extends'];
|
|
80
|
+
export const KEYWORDS = [].concat(COLLECTION_KEYWORDS, COLLECTION_ACTIONS_KEYWORDS, COLLECTION_SEARCH_KEYWORDS, COLLECTION_LAYOUT_KEYWORDS, COLLECTION_LAYOUT_OPTIONS_KEYWORDS, COLLECTION_FORM_LAYOUT_KEYWORDS, CONTRACT_KEYWORDS, TOPLEVEL_KEYWORDS, MISC_KEYWORDS);
|
|
81
|
+
export const FINAL_OPERATORS = [
|
|
85
82
|
'==',
|
|
86
83
|
'in',
|
|
87
84
|
'>=',
|
|
@@ -90,12 +87,12 @@ exports.FINAL_OPERATORS = [
|
|
|
90
87
|
'<',
|
|
91
88
|
'!',
|
|
92
89
|
];
|
|
93
|
-
|
|
90
|
+
export const LOGICAL_OPERATORS = [
|
|
94
91
|
'&&',
|
|
95
92
|
'||',
|
|
96
93
|
];
|
|
97
94
|
const keywordsSet = new Set();
|
|
98
|
-
for (const keyword of
|
|
95
|
+
for (const keyword of KEYWORDS) {
|
|
99
96
|
keywordsSet.add(keyword);
|
|
100
97
|
}
|
|
101
98
|
const TOKENS = [
|
|
@@ -104,51 +101,51 @@ const TOKENS = [
|
|
|
104
101
|
matcher: /\r?[ \t]+/,
|
|
105
102
|
},
|
|
106
103
|
{
|
|
107
|
-
type:
|
|
104
|
+
type: TokenType.LineBreak,
|
|
108
105
|
matcher: '\n',
|
|
109
106
|
},
|
|
110
107
|
{
|
|
111
|
-
type:
|
|
108
|
+
type: TokenType.Comment,
|
|
112
109
|
matcher: '//',
|
|
113
110
|
},
|
|
114
111
|
{
|
|
115
|
-
type:
|
|
112
|
+
type: TokenType.LeftBracket,
|
|
116
113
|
matcher: '{',
|
|
117
114
|
},
|
|
118
115
|
{
|
|
119
|
-
type:
|
|
116
|
+
type: TokenType.RightBracket,
|
|
120
117
|
matcher: '}',
|
|
121
118
|
},
|
|
122
119
|
{
|
|
123
|
-
type:
|
|
120
|
+
type: TokenType.LeftParens,
|
|
124
121
|
matcher: '(',
|
|
125
122
|
},
|
|
126
123
|
{
|
|
127
|
-
type:
|
|
124
|
+
type: TokenType.RightParens,
|
|
128
125
|
matcher: ')',
|
|
129
126
|
},
|
|
130
127
|
{
|
|
131
|
-
type:
|
|
128
|
+
type: TokenType.LeftSquareBracket,
|
|
132
129
|
matcher: '[',
|
|
133
130
|
},
|
|
134
131
|
{
|
|
135
|
-
type:
|
|
132
|
+
type: TokenType.RightSquareBracket,
|
|
136
133
|
matcher: ']',
|
|
137
134
|
},
|
|
138
135
|
{
|
|
139
|
-
type:
|
|
140
|
-
matcher: [].concat(
|
|
136
|
+
type: TokenType.Operator,
|
|
137
|
+
matcher: [].concat(FINAL_OPERATORS, LOGICAL_OPERATORS),
|
|
141
138
|
},
|
|
142
139
|
{
|
|
143
|
-
type:
|
|
140
|
+
type: TokenType.Pipe,
|
|
144
141
|
matcher: '|',
|
|
145
142
|
},
|
|
146
143
|
{
|
|
147
|
-
type:
|
|
144
|
+
type: TokenType.Comma,
|
|
148
145
|
matcher: ',',
|
|
149
146
|
},
|
|
150
147
|
{
|
|
151
|
-
type:
|
|
148
|
+
type: TokenType.Range,
|
|
152
149
|
matcher: /(\d+\.\.\d*|\d*\.\.\d+)/g,
|
|
153
150
|
valueExtractor: (value) => {
|
|
154
151
|
const [, left, right] = value.match(/(\d*)\.\.(\d*)/);
|
|
@@ -159,16 +156,16 @@ const TOKENS = [
|
|
|
159
156
|
},
|
|
160
157
|
},
|
|
161
158
|
{
|
|
162
|
-
type:
|
|
159
|
+
type: TokenType.Dot,
|
|
163
160
|
matcher: '.',
|
|
164
161
|
},
|
|
165
162
|
{
|
|
166
|
-
type:
|
|
163
|
+
type: TokenType.Number,
|
|
167
164
|
matcher: /[0-9]+(\.[0-9]+)?/,
|
|
168
165
|
construct: Number,
|
|
169
166
|
},
|
|
170
167
|
{
|
|
171
|
-
type:
|
|
168
|
+
type: TokenType.Boolean,
|
|
172
169
|
matcher: [
|
|
173
170
|
'true',
|
|
174
171
|
'false',
|
|
@@ -176,13 +173,13 @@ const TOKENS = [
|
|
|
176
173
|
construct: Boolean,
|
|
177
174
|
},
|
|
178
175
|
{
|
|
179
|
-
type:
|
|
176
|
+
type: TokenType.Keyword,
|
|
180
177
|
matcher: Array.from(keywordsSet),
|
|
181
178
|
condition: (state, lastToken) => {
|
|
182
179
|
if (state.variableScopeStack.at(-1) || state.variableExpressionStack.at(-1)) {
|
|
183
180
|
return false;
|
|
184
181
|
}
|
|
185
|
-
if (lastToken && lastToken.type ===
|
|
182
|
+
if (lastToken && lastToken.type === TokenType.Keyword) {
|
|
186
183
|
switch (lastToken.value) {
|
|
187
184
|
case 'if':
|
|
188
185
|
case 'badge':
|
|
@@ -195,26 +192,26 @@ const TOKENS = [
|
|
|
195
192
|
},
|
|
196
193
|
},
|
|
197
194
|
{
|
|
198
|
-
type:
|
|
195
|
+
type: TokenType.MacroName,
|
|
199
196
|
matcher: /[a-zA-Z]([a-zA-Z0-9]|_)+\(/,
|
|
200
197
|
valueExtractor: (value) => value.slice(0, -1),
|
|
201
198
|
},
|
|
202
199
|
{
|
|
203
|
-
type:
|
|
200
|
+
type: TokenType.Identifier,
|
|
204
201
|
matcher: /([a-zA-Z0-9]|_)+/,
|
|
205
202
|
},
|
|
206
203
|
{
|
|
207
|
-
type:
|
|
204
|
+
type: TokenType.QuotedString,
|
|
208
205
|
matcher: /"([^"]+)"/,
|
|
209
206
|
valueExtractor: (value) => value.slice(1, -1),
|
|
210
207
|
},
|
|
211
208
|
{
|
|
212
|
-
type:
|
|
209
|
+
type: TokenType.AttributeName,
|
|
213
210
|
matcher: /@[a-zA-Z0-9]+/,
|
|
214
211
|
valueExtractor: (value) => value.slice(1),
|
|
215
212
|
},
|
|
216
213
|
];
|
|
217
|
-
const tokenize = function (rawInput, fileLocation) {
|
|
214
|
+
export const tokenize = function (rawInput, fileLocation) {
|
|
218
215
|
const input = rawInput.replace(/\r\n/g, '\n');
|
|
219
216
|
let index = 0, line = 1, start = 0, end = 0;
|
|
220
217
|
const tokens = [];
|
|
@@ -264,12 +261,12 @@ const tokenize = function (rawInput, fileLocation) {
|
|
|
264
261
|
};
|
|
265
262
|
switch (type) {
|
|
266
263
|
case null: break;
|
|
267
|
-
case
|
|
264
|
+
case TokenType.LineBreak:
|
|
268
265
|
line++;
|
|
269
266
|
end = 0;
|
|
270
267
|
start = 0;
|
|
271
268
|
break;
|
|
272
|
-
case
|
|
269
|
+
case TokenType.Comment: {
|
|
273
270
|
while (input[index++] !== '\n') { }
|
|
274
271
|
line++;
|
|
275
272
|
break;
|
|
@@ -291,9 +288,9 @@ const tokenize = function (rawInput, fileLocation) {
|
|
|
291
288
|
value: tokenValue,
|
|
292
289
|
};
|
|
293
290
|
switch (type) {
|
|
294
|
-
case
|
|
291
|
+
case TokenType.LeftBracket: {
|
|
295
292
|
let variableScope = false;
|
|
296
|
-
if (lastToken && lastToken.type ===
|
|
293
|
+
if (lastToken && lastToken.type === TokenType.Keyword) {
|
|
297
294
|
switch (lastToken.value) {
|
|
298
295
|
case 'fields':
|
|
299
296
|
case 'information':
|
|
@@ -313,11 +310,11 @@ const tokenize = function (rawInput, fileLocation) {
|
|
|
313
310
|
state.variableScopeStack.push(variableScope);
|
|
314
311
|
break;
|
|
315
312
|
}
|
|
316
|
-
case
|
|
313
|
+
case TokenType.LeftParens: {
|
|
317
314
|
let variableExpression = false;
|
|
318
315
|
if (lastToken) {
|
|
319
316
|
switch (lastToken.type) {
|
|
320
|
-
case
|
|
317
|
+
case TokenType.Keyword: {
|
|
321
318
|
switch (lastToken.value) {
|
|
322
319
|
case 'if': {
|
|
323
320
|
variableExpression = true;
|
|
@@ -326,7 +323,7 @@ const tokenize = function (rawInput, fileLocation) {
|
|
|
326
323
|
}
|
|
327
324
|
break;
|
|
328
325
|
}
|
|
329
|
-
case
|
|
326
|
+
case TokenType.Operator: {
|
|
330
327
|
variableExpression = true;
|
|
331
328
|
break;
|
|
332
329
|
}
|
|
@@ -335,13 +332,13 @@ const tokenize = function (rawInput, fileLocation) {
|
|
|
335
332
|
state.variableExpressionStack.push(variableExpression);
|
|
336
333
|
break;
|
|
337
334
|
}
|
|
338
|
-
case
|
|
335
|
+
case TokenType.RightBracket: {
|
|
339
336
|
if (state.variableScopeStack.length > 0) {
|
|
340
337
|
state.variableScopeStack.pop();
|
|
341
338
|
}
|
|
342
339
|
break;
|
|
343
340
|
}
|
|
344
|
-
case
|
|
341
|
+
case TokenType.RightParens: {
|
|
345
342
|
if (state.variableExpressionStack.length > 0) {
|
|
346
343
|
state.variableExpressionStack.pop();
|
|
347
344
|
}
|
|
@@ -356,7 +353,7 @@ const tokenize = function (rawInput, fileLocation) {
|
|
|
356
353
|
}
|
|
357
354
|
if (!hasMatch) {
|
|
358
355
|
index += input.slice(index).search(/[ \t\n\{\}\(\)\[\]]/);
|
|
359
|
-
errors.push(new
|
|
356
|
+
errors.push(new Diagnostic('unexpected token', {
|
|
360
357
|
file: fileLocation,
|
|
361
358
|
index,
|
|
362
359
|
line,
|
|
@@ -370,4 +367,3 @@ const tokenize = function (rawInput, fileLocation) {
|
|
|
370
367
|
errors,
|
|
371
368
|
};
|
|
372
369
|
};
|
|
373
|
-
exports.tokenize = tokenize;
|