Skip to content

Commit 32fa487

Browse files
authored
Merge pull request #51 from source-academy/move-exported-methods
Move exported methods to src
2 parents 8f08da5 + 07c7183 commit 32fa487

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "java-slang",
3-
"version": "1.0.12",
3+
"version": "1.0.13",
44
"main": "dist/index.js",
55
"types": "dist/index.d.ts",
66
"files": ["dist"],

src/ec-evaluator/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import { RuntimeError } from "./errors";
55
import { evaluate } from "./interpreter";
66
import { Context, Error, Finished, Result } from "./types";
77

8+
export * from './components';
9+
export * from './errors';
10+
export * from './types';
11+
export { isInstr, isNode } from './utils';
12+
813
export const runECEvaluator = (
914
code: string,
1015
targetStep: number = STEP_LIMIT,

src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import { astToString } from './ast/utils/astToString'
2+
import * as ECE from './ec-evaluator'
13
import * as JVM from './jvm'
4+
import { typeCheck } from './types'
5+
import { compile, compileFromSource} from './compiler'
26

3-
export { JVM }
7+
export { astToString, ECE, JVM, typeCheck, compile, compileFromSource }

src/types/index.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
import { check } from './checker'
2-
import { Node } from './ast/types'
32
import { parse } from './ast'
43
import { TypeCheckerError } from './errors'
54

6-
export type TypeCheckResult = { hasTypeErrors: boolean; errors: Error[] }
5+
type TypeCheckResult = { hasTypeErrors: boolean; errorMsgs: string[] }
76

8-
export const parseProgram = (program: string): Node => {
9-
return parse(program)
7+
const convertErrorsToReadableMsgs = (program: string, errors: Error[]): string[] => {
8+
return errors.map(error => {
9+
if (!(error instanceof TypeCheckerError)) return error.message
10+
return error.toReadableMessage(program)
11+
})
1012
}
1113

12-
export const typeCheck = (ast: Node): TypeCheckResult => {
14+
export const typeCheck = (program: string): TypeCheckResult => {
15+
const ast = parse(program)
1316
const result = check(ast)
1417
return {
1518
hasTypeErrors: result.errors.length > 0,
16-
errors: result.errors
19+
errorMsgs: convertErrorsToReadableMsgs(program, result.errors)
1720
}
1821
}
19-
20-
export const convertErrorsToReadableMsgs = (program: string, errors: Error[]): string[] => {
21-
return errors.map(error => {
22-
if (!(error instanceof TypeCheckerError)) return error.message
23-
return error.toReadableMessage(program)
24-
})
25-
}

0 commit comments

Comments
 (0)