oclang 1.2.2 → 1.3.2

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.
Files changed (60) hide show
  1. package/.gitattributes +7 -0
  2. package/BUG_REGISTRY.md +6 -1
  3. package/CHANGELOG.md +20 -3
  4. package/README.md +2 -0
  5. package/dist/cli/ocat/index.js +0 -0
  6. package/dist/cli/ocm/commands/run.js +0 -5
  7. package/dist/cli/ocm/index.js +0 -0
  8. package/dist/core/ast/astBuilder.js +20 -144
  9. package/dist/core/ast/statements/_base.js +1 -0
  10. package/dist/core/ast/statements/function.js +53 -0
  11. package/dist/core/ast/statements/import.js +16 -0
  12. package/dist/core/ast/statements/io.js +45 -0
  13. package/dist/core/ast/statements/vars.js +37 -0
  14. package/dist/core/ast/types/base/statement.js +1 -0
  15. package/dist/core/ast/types/statements/importStatement.js +1 -0
  16. package/dist/core/ast/types/statements/index.js +5 -4
  17. package/dist/core/index.js +7 -5
  18. package/dist/core/lexer/tokens/keywords.js +2 -1
  19. package/dist/core/parser/parser.js +42 -15
  20. package/dist/core/runner/funcs/_base.js +1 -0
  21. package/dist/core/runner/funcs/functions.js +28 -0
  22. package/dist/core/runner/funcs/io.js +29 -0
  23. package/dist/core/runner/funcs/modules.js +11 -0
  24. package/dist/core/runner/funcs/variables.js +42 -0
  25. package/dist/core/runner/runner.js +16 -101
  26. package/dist/core/services/log.service.js +7 -7
  27. package/dist/shared/context/globalContext.js +7 -1
  28. package/dist/shared/manager/baseManager.js +5 -3
  29. package/dist/shared/manager/warn/coreWarnings.js +2 -2
  30. package/package.json +30 -30
  31. package/src/cli/ocm/commands/run.ts +0 -5
  32. package/src/core/ast/astBuilder.ts +21 -152
  33. package/src/core/ast/statements/_base.ts +3 -0
  34. package/src/core/ast/statements/function.ts +60 -0
  35. package/src/core/ast/statements/import.ts +22 -0
  36. package/src/core/ast/statements/io.ts +50 -0
  37. package/src/core/ast/statements/vars.ts +46 -0
  38. package/src/core/ast/types/base/statement.ts +2 -1
  39. package/src/core/ast/types/statements/callStatement.ts +1 -2
  40. package/src/core/ast/types/statements/functionStatement.ts +2 -2
  41. package/src/core/ast/types/statements/importStatement.ts +6 -0
  42. package/src/core/ast/types/statements/index.ts +12 -9
  43. package/src/core/ast/types/statements/printStatement.ts +2 -2
  44. package/src/core/ast/types/statements/variableStatement.ts +2 -2
  45. package/src/core/context/coreContext.ts +3 -3
  46. package/src/core/index.ts +8 -5
  47. package/src/core/lexer/tokens/keywords.ts +3 -1
  48. package/src/core/parser/parser.ts +49 -15
  49. package/src/core/runner/funcs/_base.ts +3 -0
  50. package/src/core/runner/funcs/functions.ts +46 -0
  51. package/src/core/runner/funcs/io.ts +38 -0
  52. package/src/core/runner/funcs/modules.ts +17 -0
  53. package/src/core/runner/funcs/variables.ts +57 -0
  54. package/src/core/runner/runner.ts +27 -121
  55. package/src/core/services/log.service.ts +24 -16
  56. package/src/shared/context/globalContext.ts +12 -1
  57. package/src/shared/manager/baseManager.ts +5 -3
  58. package/src/shared/manager/warn/coreWarnings.ts +2 -2
  59. package/src/shared/models/func.ts +1 -1
  60. package/tsconfig.json +3 -3
@@ -0,0 +1,42 @@
1
+ import { AlreadyDeclaredVariableError, CantModifyConstError, } from "../../../shared/manager/errors/semantic/undefined/declared.js";
2
+ import { UndeclaredVariableError } from "../../../shared/manager/errors/semantic/undefined/undeclared.js";
3
+ import { ValueType } from "../../../shared/models/value.js";
4
+ import { solveString } from "../utils/string.js";
5
+ export const variableStatement = (statement, context) => {
6
+ const varId = statement.id;
7
+ /*if (statement.set) {
8
+ if (!context.variables[varId]) {
9
+ new UndeclaredVariableError(varId).throw(
10
+ statement.sourceInfo.startLine,
11
+ );
12
+ }
13
+ if (context.variables[varId]?.props.isConst) {
14
+ new CantModifyConstError(varId).throw(
15
+ statement.sourceInfo.startLine,
16
+ );
17
+ }
18
+ } else if (!statement.var.props.isConst) {
19
+ if (context.variables[varId]) {
20
+ new AlreadyDeclaredVariableError(varId).throw(
21
+ statement.sourceInfo.startLine,
22
+ );
23
+ }
24
+ }*/
25
+ let value = statement.var.value;
26
+ switch (statement.var.type) {
27
+ case ValueType.String:
28
+ value = solveString(value, context, (err) => {
29
+ err.throw(statement.sourceInfo.startLine);
30
+ });
31
+ break;
32
+ default:
33
+ break;
34
+ }
35
+ context.variables[varId] = {
36
+ type: statement.var.type,
37
+ value,
38
+ props: {
39
+ isConst: !!statement.var.props.isConst,
40
+ },
41
+ };
42
+ };
@@ -1,108 +1,23 @@
1
- import { AlreadyDeclaredFunctionError, AlreadyDeclaredVariableError, CantModifyConstError, } from "../../shared/manager/errors/semantic/undefined/declared.js";
1
+ import { AlreadyDeclaredFunctionError } from "../../shared/manager/errors/semantic/undefined/declared.js";
2
2
  import { UndeclaredFunctionError, UndeclaredVariableError, } from "../../shared/manager/errors/semantic/undefined/undeclared.js";
3
- import { createCoreContext } from "../context/coreContext.js";
4
- import { ValueType } from "../../shared/models/value.js";
5
- import { solveString } from "./utils/string.js";
6
3
  import { StatementKind } from "../ast/types/base/statement.js";
7
- import * as ctx from "../../shared/context/globalContext.js";
4
+ // import { coreContext as context } from "../context/coreContext.js";
5
+ import { printStatement } from "./funcs/io.js";
6
+ import { variableStatement } from "./funcs/variables.js";
7
+ import { callStatement, functionStatement } from "./funcs/functions.js";
8
+ const statementMap = new Map([
9
+ [StatementKind.PrintStatement, printStatement],
10
+ [StatementKind.VariableStatement, variableStatement],
11
+ [StatementKind.FunctionStatement, functionStatement],
12
+ [StatementKind.CallStatement, callStatement],
13
+ ]);
8
14
  export function run(ast, context) {
9
15
  for (const statement of ast) {
10
- switch (statement.kind) {
11
- case StatementKind.PrintStatement:
12
- printStatement(statement, context);
13
- break;
14
- case StatementKind.VariableStatement:
15
- variableStatement(statement, context);
16
- break;
17
- case StatementKind.FunctionStatement:
18
- functionStatement(statement, context);
19
- break;
20
- case StatementKind.CallStatement:
21
- callStatement(statement, context);
22
- break;
16
+ const runner = statementMap.get(statement.kind);
17
+ if (!runner) {
18
+ throw new Error(`No runner for statement kind: ${statement.kind}`);
23
19
  }
20
+ runner(statement, context);
24
21
  }
25
- }
26
- function printStatement(statement, context) {
27
- let val;
28
- switch (statement.value.type) {
29
- case ValueType.Identifier:
30
- const id = statement.value.value;
31
- const varData = context.variables[id];
32
- if (varData !== undefined) {
33
- val = varData.value;
34
- }
35
- else {
36
- new UndeclaredVariableError(id).throw(statement.sourceInfo.startLine);
37
- }
38
- break;
39
- case ValueType.String:
40
- val = solveString(statement.value.value, context, (err) => {
41
- err.throw(statement.sourceInfo.startLine);
42
- });
43
- break;
44
- default:
45
- val = statement.value.value;
46
- break;
47
- }
48
- const info = ctx.get("services").log;
49
- info.info(val);
50
- }
51
- function variableStatement(statement, context) {
52
- const varId = statement.id;
53
- if (statement.set) {
54
- if (!context.variables[varId]) {
55
- new UndeclaredVariableError(varId).throw(statement.sourceInfo.startLine);
56
- }
57
- if (context.variables[varId]?.props.isConst) {
58
- new CantModifyConstError(varId).throw(statement.sourceInfo.startLine);
59
- }
60
- }
61
- else if (!statement.var.props.isConst) {
62
- if (context.variables[varId]) {
63
- new AlreadyDeclaredVariableError(varId).throw(statement.sourceInfo.startLine);
64
- }
65
- }
66
- let value = statement.var.value;
67
- switch (statement.var.type) {
68
- case ValueType.String:
69
- value = solveString(value, context, (err) => {
70
- err.throw(statement.sourceInfo.startLine);
71
- });
72
- break;
73
- default:
74
- break;
75
- }
76
- context.variables[varId] = {
77
- type: statement.var.type,
78
- value,
79
- props: {
80
- isConst: !!statement.var.props.isConst,
81
- },
82
- };
83
- }
84
- function functionStatement(statement, context) {
85
- const idToken = statement.id;
86
- if (!idToken)
87
- return;
88
- const funcData = context.functions[idToken];
89
- if (funcData) {
90
- new AlreadyDeclaredFunctionError(idToken).throw(statement.sourceInfo.startLine);
91
- }
92
- const body = statement.func.body ?? [];
93
- const scope = statement.func.scope;
94
- context.functions[idToken] = {
95
- body,
96
- scope,
97
- };
98
- }
99
- function callStatement(statement, context) {
100
- const funcId = statement.id;
101
- if (!funcId)
102
- return;
103
- const funcData = context.functions[funcId];
104
- if (!funcData) {
105
- new UndeclaredFunctionError(funcId).throw(statement.sourceInfo.startLine);
106
- }
107
- run(funcData.body, context.functions[funcId].scope);
22
+ return context;
108
23
  }
@@ -11,16 +11,14 @@ export class LoggerService {
11
11
  constructor(config) {
12
12
  this.config = config;
13
13
  }
14
- log(message, level = LogLevel.Info) {
14
+ log(message, level = LogLevel.Info, printMsg = message) {
15
15
  this.logs.push({ message, level });
16
- this.config.interceptors.forEach(interceptor => {
16
+ this.config.interceptors.forEach((interceptor) => {
17
17
  if (interceptor.level === level) {
18
18
  message = interceptor.onLog(message);
19
19
  }
20
20
  });
21
- if (this.config.logs.includes(level)) {
22
- console.log(message);
23
- }
21
+ console.log(printMsg);
24
22
  }
25
23
  debug(message) {
26
24
  this.log(message, LogLevel.Debug);
@@ -41,10 +39,12 @@ export class LoggerService {
41
39
  this.config.interceptors.push(interceptor);
42
40
  }
43
41
  removeInterceptor(interceptor) {
44
- this.config.interceptors = this.config.interceptors.filter(i => i !== interceptor);
42
+ this.config.interceptors = this.config.interceptors.filter((i) => i !== interceptor);
45
43
  }
46
44
  toString() {
47
- return this.logs.map(log => `[${log.level}] ${log.message}`).join("\n");
45
+ return this.logs
46
+ .map((log) => `[${log.level}] ${log.message}`)
47
+ .join("\n");
48
48
  }
49
49
  }
50
50
  export const defaultLoggerConfig = {
@@ -1,4 +1,10 @@
1
- let globalContext = {};
1
+ let globalContext = { services: new Map() };
2
+ export function pushService(service, name) {
3
+ globalContext.services.set(name, service);
4
+ }
5
+ export function getService(name) {
6
+ return globalContext.services.get(name);
7
+ }
2
8
  export function get(key) {
3
9
  return globalContext[key];
4
10
  }
@@ -5,11 +5,13 @@ export class OcatManager {
5
5
  message;
6
6
  color;
7
7
  level;
8
+ printFn;
8
9
  constructor(name, color, level) {
9
10
  this.name = name;
10
11
  this.message = "";
11
12
  this.color = color;
12
13
  this.level = level;
14
+ this.printFn = console.log;
13
15
  }
14
16
  toString(line = undefined) {
15
17
  return `${this.color.bold(this.name)}${line ? chalk.gray(` at line ${line}`) : ""}: ${this.color.italic(this.message)}`;
@@ -22,9 +24,9 @@ export class OcatManager {
22
24
  return this;
23
25
  }
24
26
  throw(line = undefined) {
25
- console.log(this.toString(line));
26
- const log = ctx.get("services").log;
27
- log.log(this.build(line), this.level);
27
+ const log = ctx.get("services")?.log;
28
+ const message = this.build(line);
29
+ log?.log(message, this.level, this.toString(line));
28
30
  process.exit(1);
29
31
  }
30
32
  }
@@ -1,6 +1,6 @@
1
1
  import chalk from "chalk";
2
- import { OcatManager } from "../baseManager";
3
- import { LogLevel } from "../../../core/services/log.service";
2
+ import { OcatManager } from "../baseManager.js";
3
+ import { LogLevel } from "../../../core/services/log.service.js";
4
4
  export class OcatWarning extends OcatManager {
5
5
  constructor(name) {
6
6
  super(name, chalk.yellow, LogLevel.Warning);
package/package.json CHANGED
@@ -1,30 +1,30 @@
1
- {
2
- "name": "oclang",
3
- "version": "1.2.2",
4
- "description": "A programming language",
5
- "author": "LuisRG-L, Orange Cat",
6
- "license": "MIT",
7
- "type": "module",
8
- "module": "src/index.ts",
9
- "bin": {
10
- "ocat": "dist/cli/ocat/index.js",
11
- "ocm": "dist/cli/ocm/index.js"
12
- },
13
- "scripts": {
14
- "build": "tsc",
15
- "test": "tsc && npm link --force"
16
- },
17
- "devDependencies": {
18
- "@types/bun": "latest"
19
- },
20
- "peerDependencies": {
21
- "typescript": "^5.0.0"
22
- },
23
- "dependencies": {
24
- "@types/node": "^25.0.3",
25
- "chalk": "^5.6.2",
26
- "chevrotain": "^11.0.3",
27
- "commander": "^14.0.2",
28
- "inquirer": "^13.1.0"
29
- }
30
- }
1
+ {
2
+ "name": "oclang",
3
+ "version": "1.3.2",
4
+ "description": "A programming language",
5
+ "author": "LuisRG-L, Orange Cat",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "module": "src/index.ts",
9
+ "bin": {
10
+ "ocat": "dist/cli/ocat/index.js",
11
+ "ocm": "dist/cli/ocm/index.js"
12
+ },
13
+ "scripts": {
14
+ "build": "tsc",
15
+ "test": "rm -rf dist && tsc && npm link --force"
16
+ },
17
+ "devDependencies": {
18
+ "@types/bun": "latest"
19
+ },
20
+ "peerDependencies": {
21
+ "typescript": "^5.0.0"
22
+ },
23
+ "dependencies": {
24
+ "@types/node": "^25.0.3",
25
+ "chalk": "^5.6.2",
26
+ "chevrotain": "^11.0.3",
27
+ "commander": "^14.0.2",
28
+ "inquirer": "^13.1.0"
29
+ }
30
+ }
@@ -10,11 +10,6 @@ export function run() {
10
10
  context.set("isProject", true);
11
11
  context.set("projectConfig", projectConfig);
12
12
  context.set("services", {});
13
- context.useObject("services", services => {
14
- return {
15
- log: new LoggerService(defaultLoggerConfig),
16
- };
17
- });
18
13
 
19
14
  runfile(projectConfig.main, { force: false });
20
15
  }
@@ -1,166 +1,35 @@
1
- import { createCoreContext, type CoreContext } from "../context/coreContext.js";
2
- import { ValueType } from "../../shared/models/value.js";
3
- import { StatementKind } from "./types/base/index.js";
4
1
  import type { AnyStatement, PrintStatement } from "./types/statements/index.js";
2
+ import { ioStatements } from "./statements/io.js";
3
+ import { variableStatements } from "./statements/vars.js";
4
+ import { functionStatements } from "./statements/function.js";
5
+ import { importStatements } from "./statements/import.js";
6
+ import type { FBuilder } from "./statements/_base.js";
5
7
 
6
8
  export type BuildType = AnyStatement | null;
7
9
 
10
+ const possibleStatements: FBuilder<AnyStatement>[] = [
11
+ ...ioStatements,
12
+ ...variableStatements,
13
+ ...functionStatements,
14
+ ...importStatements,
15
+ ];
16
+
8
17
  export function buildAst(cst: any): AnyStatement[] {
9
18
  const statements = cst.children.statement ?? [];
10
19
  const ast: AnyStatement[] = [];
11
20
 
12
- for (const statement of statements) {
13
- let __tmp: BuildType = null;
14
- const __$tmp = () => { if (__tmp) ast.push(__tmp); }
15
- __tmp = printStatement(statement);
16
- __$tmp();
17
- __tmp = variableStatement(statement);
18
- __$tmp();
19
- __tmp = functionStatement(statement);
20
- __$tmp();
21
- __tmp = callStatement(statement);
22
- __$tmp();
23
- }
24
-
25
- return ast;
26
- }
27
-
28
- export type FBuilder = (statement: any) => AnyStatement | null;
21
+ for (const node of statements) {
22
+ let built: AnyStatement | null = null;
29
23
 
30
- const printStatement: FBuilder = (statement: any) => {
31
- const printStmt = statement.children.printStatement?.[0];
32
- if (printStmt) {
33
- const strToken = printStmt.children.StringLiteral?.[0];
34
- if (strToken) {
35
- return {
36
- kind: StatementKind.PrintStatement,
37
- sourceInfo: {
38
- tokens: printStmt.children,
39
- cstNode: printStmt,
40
- startLine: printStmt.startLine,
41
- endLine: printStmt.endLine,
42
- startColumn: printStmt.startColumn,
43
- endColumn: printStmt.endColumn,
44
- },
45
- value: {
46
- value: strToken.image,
47
- type: ValueType.String,
48
- }
49
- } as PrintStatement;
24
+ for (const builder of possibleStatements) {
25
+ built = builder(node);
26
+ if (built) break;
50
27
  }
51
28
 
52
- const idToken = printStmt.children.Identifier?.[0];
53
- if (idToken) {
54
- return {
55
- kind: StatementKind.PrintStatement,
56
- sourceInfo: {
57
- tokens: printStmt.children,
58
- cstNode: printStmt,
59
- startLine: printStmt.startLine,
60
- endLine: printStmt.endLine,
61
- startColumn: printStmt.startColumn,
62
- endColumn: printStmt.endColumn,
63
- },
64
- value: {
65
- value: idToken.image,
66
- type: ValueType.Identifier,
67
- }
68
- }
29
+ if (built) {
30
+ ast.push(built);
69
31
  }
70
32
  }
71
- return null;
72
- }
73
33
 
74
- const variableStatement: FBuilder = (statement: any) => {
75
- const varStmt = statement.children.variableStatement?.[0];
76
- if (varStmt) {
77
- const typeToken = varStmt.children.VarType?.[0];
78
- const idToken = varStmt.children.Identifier?.[0];
79
- const valueToken =
80
- varStmt.children.StringLiteral?.[0] ??
81
- varStmt.children.NumberLiteral?.[0] ??
82
- varStmt.children.BooleanLiteral?.[0];
83
-
84
- if (!typeToken || !idToken || !valueToken) return null;
85
-
86
- const setToken = varStmt.children.Set?.[0];
87
- const constToken = varStmt.children.Const?.[0];
88
-
89
- const type = typeToken.image as ValueType;
90
- const id = idToken.image;
91
- const value: string = valueToken.image;
92
- return {
93
- kind: StatementKind.VariableStatement,
94
- sourceInfo: {
95
- tokens: varStmt.children,
96
- cstNode: varStmt,
97
- startLine: varStmt.startLine,
98
- endLine: varStmt.endLine,
99
- startColumn: varStmt.startColumn,
100
- endColumn: varStmt.endColumn,
101
- },
102
- id,
103
- var: {
104
- type,
105
- value,
106
- props: {
107
- isConst: !!constToken,
108
- }
109
- },
110
- set: !!setToken,
111
- }
112
- }
113
- return null;
114
- }
115
-
116
- const functionStatement: FBuilder = (statement: any) => {
117
- const funcStmt = statement.children.functionStatement?.[0];
118
- if (funcStmt) {
119
- const idToken = funcStmt.children.Identifier?.[0];
120
- if (!idToken) return null;
121
- const id = idToken.image;
122
-
123
- const body = buildAst(funcStmt) ;
124
-
125
- return {
126
- kind: StatementKind.FunctionStatement,
127
- sourceInfo: {
128
- tokens: funcStmt.children,
129
- cstNode: funcStmt,
130
- startLine: funcStmt.startLine,
131
- endLine: funcStmt.endLine,
132
- startColumn: funcStmt.startColumn,
133
- endColumn: funcStmt.endColumn,
134
- },
135
- id,
136
- func: {
137
- body,
138
- scope: createCoreContext(),
139
- }
140
- }
141
- }
142
- return null
143
- }
144
-
145
- const callStatement: FBuilder = (statement: any) => {
146
- const callStmt = statement.children.callStatement?.[0];
147
- if (callStmt) {
148
- const idToken = callStmt.children.Identifier?.[0];
149
- if (!idToken) return null;
150
- const id = idToken.image;
151
-
152
- return {
153
- kind: StatementKind.CallStatement,
154
- sourceInfo: {
155
- tokens: callStmt.children,
156
- cstNode: callStmt,
157
- startLine: callStmt.startLine,
158
- endLine: callStmt.endLine,
159
- startColumn: callStmt.startColumn,
160
- endColumn: callStmt.endColumn,
161
- },
162
- id,
163
- };
164
- }
165
- return null;
166
- };
34
+ return ast;
35
+ }
@@ -0,0 +1,3 @@
1
+ import type { AnyStatement } from "../types/statements/index.js";
2
+
3
+ export type FBuilder<T> = (statement: any) => T | null;
@@ -0,0 +1,60 @@
1
+ import { createCoreContext } from "../../context/coreContext.js";
2
+ import { buildAst } from "../astBuilder.js";
3
+ import { StatementKind } from "../types/base/index.js";
4
+ import type { CallStatement } from "../types/statements/callStatement.js";
5
+ import type { FunctionStatement } from "../types/statements/functionStatement.js";
6
+ import type { FBuilder } from "./_base.js";
7
+
8
+ const functionStatement: FBuilder<FunctionStatement> = (statement: any) => {
9
+ const funcStmt = statement.children.functionStatement?.[0];
10
+ if (funcStmt) {
11
+ const idToken = funcStmt.children.Identifier?.[0];
12
+ if (!idToken) return null;
13
+ const id = idToken.image;
14
+
15
+ const body = buildAst(funcStmt);
16
+
17
+ return {
18
+ kind: StatementKind.FunctionStatement,
19
+ sourceInfo: {
20
+ tokens: funcStmt.children,
21
+ cstNode: funcStmt,
22
+ startLine: funcStmt.startLine,
23
+ endLine: funcStmt.endLine,
24
+ startColumn: funcStmt.startColumn,
25
+ endColumn: funcStmt.endColumn,
26
+ },
27
+ id,
28
+ func: {
29
+ body,
30
+ scope: createCoreContext(),
31
+ },
32
+ };
33
+ }
34
+ return null;
35
+ };
36
+
37
+ const callStatement: FBuilder<CallStatement> = (statement: any) => {
38
+ const callStmt = statement.children.callStatement?.[0];
39
+ if (callStmt) {
40
+ const idToken = callStmt.children.Identifier?.[0];
41
+ if (!idToken) return null;
42
+ const id = idToken.image;
43
+
44
+ return {
45
+ kind: StatementKind.CallStatement,
46
+ sourceInfo: {
47
+ tokens: callStmt.children,
48
+ cstNode: callStmt,
49
+ startLine: callStmt.startLine,
50
+ endLine: callStmt.endLine,
51
+ startColumn: callStmt.startColumn,
52
+ endColumn: callStmt.endColumn,
53
+ },
54
+ id,
55
+ };
56
+ }
57
+ return null;
58
+ };
59
+
60
+ export const functionStatements = [functionStatement, callStatement];
@@ -0,0 +1,22 @@
1
+ import { StatementKind } from "../types/base/index.js";
2
+ import type { ImportStatement } from "../types/statements/importStatement.js";
3
+ import type { FBuilder } from "./_base.js";
4
+
5
+ const importStatement: FBuilder<ImportStatement> = (statement: any) => {
6
+ const node = statement.children.importStatement?.[0];
7
+ if (!node) return null;
8
+
9
+ const stringToken = node.children.StringLiteral?.[0];
10
+ if (!stringToken) return null;
11
+
12
+ const rawValue = stringToken.image;
13
+
14
+ const path = rawValue.slice(1, -1) as string;
15
+
16
+ return {
17
+ kind: StatementKind.ImportStatement,
18
+ path,
19
+ };
20
+ };
21
+
22
+ export const importStatements = [importStatement];
@@ -0,0 +1,50 @@
1
+ import { ValueType } from "../../../shared/models/value.js";
2
+ import { StatementKind } from "../types/base/index.js";
3
+ import type { PrintStatement } from "../types/statements/index.js";
4
+ import type { FBuilder } from "./_base.js";
5
+
6
+ const printStatement: FBuilder<PrintStatement> = (statement: any) => {
7
+ const printStmt = statement.children.printStatement?.[0];
8
+ if (printStmt) {
9
+ const strToken = printStmt.children.StringLiteral?.[0];
10
+ if (strToken) {
11
+ return {
12
+ kind: StatementKind.PrintStatement,
13
+ sourceInfo: {
14
+ tokens: printStmt.children,
15
+ cstNode: printStmt,
16
+ startLine: printStmt.startLine,
17
+ endLine: printStmt.endLine,
18
+ startColumn: printStmt.startColumn,
19
+ endColumn: printStmt.endColumn,
20
+ },
21
+ value: {
22
+ value: strToken.image,
23
+ type: ValueType.String,
24
+ },
25
+ };
26
+ }
27
+
28
+ const idToken = printStmt.children.Identifier?.[0];
29
+ if (idToken) {
30
+ return {
31
+ kind: StatementKind.PrintStatement,
32
+ sourceInfo: {
33
+ tokens: printStmt.children,
34
+ cstNode: printStmt,
35
+ startLine: printStmt.startLine,
36
+ endLine: printStmt.endLine,
37
+ startColumn: printStmt.startColumn,
38
+ endColumn: printStmt.endColumn,
39
+ },
40
+ value: {
41
+ value: idToken.image,
42
+ type: ValueType.Identifier,
43
+ },
44
+ };
45
+ }
46
+ }
47
+ return null;
48
+ };
49
+
50
+ export const ioStatements = [printStatement];