@irrelon/battlescript 3.1.4 → 3.1.6
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/bin/functionality.ts +32 -9
- package/bin/index.js +438 -345
- package/bin/index.js.map +1 -1
- package/bin/index.ts +2 -0
- package/dist/bin/functionality.d.ts.map +1 -1
- package/dist/index.js +416 -338
- package/dist/index.js.map +1 -1
- package/dist/services/fullAst/BattleScriptToAST.d.ts +4 -2
- package/dist/services/fullAst/BattleScriptToAST.d.ts.map +1 -1
- package/dist/services/grammar/ts/language/BattleScriptLexer.d.ts.map +1 -1
- package/dist/services/parser.d.ts.map +1 -1
- package/dist/tsconfig.types.tsbuildinfo +1 -1
- package/dist/types/BattleScriptTransformerOptions.d.ts +3 -0
- package/dist/types/BattleScriptTransformerOptions.d.ts.map +1 -1
- package/dist/types/ast/nodes/RootNode.d.ts.map +1 -1
- package/package.json +1 -1
package/bin/functionality.ts
CHANGED
|
@@ -9,14 +9,24 @@ import {
|
|
|
9
9
|
fromSourceCodeToMiniAst,
|
|
10
10
|
miniAstFromBinaryBuffer
|
|
11
11
|
} from "@/services";
|
|
12
|
+
import type {SourceResolverAsync, SourceResolverSync} from "@/types";
|
|
12
13
|
import type {ByteCodeJson} from "@/types/byteCode/ByteCodeJson";
|
|
13
14
|
import {version} from "../package.json";
|
|
14
15
|
import {readFileSync} from "fs";
|
|
15
16
|
import {writeFileSync} from "node:fs";
|
|
16
17
|
|
|
18
|
+
const sourceResolverAsync: SourceResolverAsync = (filePath: string) => {
|
|
19
|
+
return readFile(filePath, "utf-8")
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const sourceResolverSync: SourceResolverSync = (filePath: string): string => {
|
|
23
|
+
return readFileSync(filePath, "utf-8")
|
|
24
|
+
};
|
|
25
|
+
|
|
17
26
|
export async function toAst(inputPath: string, outputPath?: string) {
|
|
27
|
+
console.log(`[BattleScript ${version}] toAst: ${inputPath}`);
|
|
18
28
|
try {
|
|
19
|
-
const sourceCode = await
|
|
29
|
+
const sourceCode = await sourceResolverAsync(inputPath);
|
|
20
30
|
const ast = fromSourceCodeToFullAst(sourceCode, {filePath: inputPath, includeMetaData: true});
|
|
21
31
|
|
|
22
32
|
if (outputPath) {
|
|
@@ -32,9 +42,14 @@ export async function toAst(inputPath: string, outputPath?: string) {
|
|
|
32
42
|
}
|
|
33
43
|
|
|
34
44
|
export function toAstSync(inputPath: string, outputPath?: string) {
|
|
45
|
+
console.log(`[BattleScript ${version}] toAstSync: ${inputPath}`);
|
|
35
46
|
try {
|
|
36
|
-
const sourceCode =
|
|
37
|
-
const ast = fromSourceCodeToFullAst(sourceCode, {
|
|
47
|
+
const sourceCode = sourceResolverSync(inputPath);
|
|
48
|
+
const ast = fromSourceCodeToFullAst(sourceCode, {
|
|
49
|
+
filePath: inputPath,
|
|
50
|
+
includeMetaData: true,
|
|
51
|
+
sourceResolver: sourceResolverSync
|
|
52
|
+
});
|
|
38
53
|
|
|
39
54
|
if (outputPath) {
|
|
40
55
|
writeFileSync(outputPath, JSON.stringify(ast, null, 2));
|
|
@@ -49,8 +64,9 @@ export function toAstSync(inputPath: string, outputPath?: string) {
|
|
|
49
64
|
}
|
|
50
65
|
|
|
51
66
|
export async function fromAst(inputPath: string, outputPath: string) {
|
|
67
|
+
console.log(`[BattleScript ${version}] fromAst: ${inputPath}`);
|
|
52
68
|
try {
|
|
53
|
-
const astString = await
|
|
69
|
+
const astString = await sourceResolverAsync(inputPath);
|
|
54
70
|
const ast = JSON.parse(astString);
|
|
55
71
|
const code = fromFullAstToSourceCode(ast);
|
|
56
72
|
await writeFile(outputPath, code);
|
|
@@ -62,8 +78,9 @@ export async function fromAst(inputPath: string, outputPath: string) {
|
|
|
62
78
|
}
|
|
63
79
|
|
|
64
80
|
export async function toMiniAst(inputPath: string, outputPath: string) {
|
|
81
|
+
console.log(`[BattleScript ${version}] toMiniAst: ${inputPath}`);
|
|
65
82
|
try {
|
|
66
|
-
const sourceCode = await
|
|
83
|
+
const sourceCode = await sourceResolverAsync(inputPath);
|
|
67
84
|
const ast = fromSourceCodeToMiniAst(sourceCode, {filePath: inputPath, includeMetaData: true});
|
|
68
85
|
|
|
69
86
|
await writeFile(outputPath, JSON.stringify(ast));
|
|
@@ -75,9 +92,15 @@ export async function toMiniAst(inputPath: string, outputPath: string) {
|
|
|
75
92
|
}
|
|
76
93
|
|
|
77
94
|
export async function toBinary(inputPath: string, outputPath: string) {
|
|
95
|
+
console.log(`[BattleScript ${version}] toBinary: ${inputPath}`);
|
|
78
96
|
try {
|
|
79
|
-
|
|
97
|
+
console.log(`[BattleScript ${version}] Reading file contents: ${inputPath}`);
|
|
98
|
+
const sourceCode = await sourceResolverAsync(inputPath);
|
|
99
|
+
|
|
100
|
+
console.log(`[BattleScript ${version}] fromSourceCodeToBinary: ${inputPath}`);
|
|
80
101
|
const binary = fromSourceCodeToBinary(sourceCode, {includeMetaData: true, flatten: true, filePath: inputPath});
|
|
102
|
+
|
|
103
|
+
console.log(`[BattleScript ${version}] Writing file contents: ${outputPath}`);
|
|
81
104
|
await writeFile(outputPath, Buffer.concat(binary))
|
|
82
105
|
|
|
83
106
|
console.log(`[BattleScript ${version}] Compiled to ${outputPath}`);
|
|
@@ -89,7 +112,7 @@ export async function toBinary(inputPath: string, outputPath: string) {
|
|
|
89
112
|
|
|
90
113
|
export async function miniAstToBinary(inputPath: string, outputPath: string) {
|
|
91
114
|
try {
|
|
92
|
-
const sourceCode = await
|
|
115
|
+
const sourceCode = await sourceResolverAsync(inputPath);
|
|
93
116
|
const binary = fromMiniAstToBinary(JSON.parse(sourceCode), {
|
|
94
117
|
includeMetaData: true,
|
|
95
118
|
flatten: true,
|
|
@@ -118,7 +141,7 @@ export async function fromBinary(inputPath: string, outputPath: string) {
|
|
|
118
141
|
|
|
119
142
|
// async function toByteCode(inputPath: string, outputPath: string) {
|
|
120
143
|
// try {
|
|
121
|
-
// const sourceCode = await
|
|
144
|
+
// const sourceCode = await sourceResolverAsync(inputPath);
|
|
122
145
|
// const bcodeJson = fromSourceCodeToByteCode(sourceCode, {includeMetaData: true, flatten: true});
|
|
123
146
|
// await writeFile(outputPath, JSON.stringify(bcodeJson).replace(/\[\[/g, "[\n[").replace(/]]/g, "]\n]").replace(/],/g, "],\n"));
|
|
124
147
|
// console.log(`Compiled to ${outputPath}`);
|
|
@@ -130,7 +153,7 @@ export async function fromBinary(inputPath: string, outputPath: string) {
|
|
|
130
153
|
|
|
131
154
|
export async function fromByteCode(inputPath: string, outputPath: string) {
|
|
132
155
|
try {
|
|
133
|
-
const byteCodeJsonString = await
|
|
156
|
+
const byteCodeJsonString = await sourceResolverAsync(inputPath);
|
|
134
157
|
const byteCodeJson: ByteCodeJson = JSON.parse(byteCodeJsonString);
|
|
135
158
|
const code = disassembleBytecode(byteCodeJson);
|
|
136
159
|
await writeFile(outputPath, code.join("\n"));
|