Skip to content

Commit

Permalink
Merge pull request #51 from source-academy/move-exported-methods
Browse files Browse the repository at this point in the history
Move exported methods to src
  • Loading branch information
martin-henz authored Apr 13, 2024
2 parents 8f08da5 + 07c7183 commit 32fa487
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "java-slang",
"version": "1.0.12",
"version": "1.0.13",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": ["dist"],
Expand Down
5 changes: 5 additions & 0 deletions src/ec-evaluator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { RuntimeError } from "./errors";
import { evaluate } from "./interpreter";
import { Context, Error, Finished, Result } from "./types";

export * from './components';
export * from './errors';
export * from './types';
export { isInstr, isNode } from './utils';

export const runECEvaluator = (
code: string,
targetStep: number = STEP_LIMIT,
Expand Down
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { astToString } from './ast/utils/astToString'
import * as ECE from './ec-evaluator'
import * as JVM from './jvm'
import { typeCheck } from './types'
import { compile, compileFromSource} from './compiler'

export { JVM }
export { astToString, ECE, JVM, typeCheck, compile, compileFromSource }
22 changes: 9 additions & 13 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
import { check } from './checker'
import { Node } from './ast/types'
import { parse } from './ast'
import { TypeCheckerError } from './errors'

export type TypeCheckResult = { hasTypeErrors: boolean; errors: Error[] }
type TypeCheckResult = { hasTypeErrors: boolean; errorMsgs: string[] }

export const parseProgram = (program: string): Node => {
return parse(program)
const convertErrorsToReadableMsgs = (program: string, errors: Error[]): string[] => {
return errors.map(error => {
if (!(error instanceof TypeCheckerError)) return error.message
return error.toReadableMessage(program)
})
}

export const typeCheck = (ast: Node): TypeCheckResult => {
export const typeCheck = (program: string): TypeCheckResult => {
const ast = parse(program)
const result = check(ast)
return {
hasTypeErrors: result.errors.length > 0,
errors: result.errors
errorMsgs: convertErrorsToReadableMsgs(program, result.errors)
}
}

export const convertErrorsToReadableMsgs = (program: string, errors: Error[]): string[] => {
return errors.map(error => {
if (!(error instanceof TypeCheckerError)) return error.message
return error.toReadableMessage(program)
})
}

1 comment on commit 32fa487

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements 76.2% 6847/8985
🟡 Branches 64.51% 2205/3418
🟡 Functions 75.6% 1193/1578
🟡 Lines 76.56% 6498/8487

Test suite run success

1074 tests passing in 52 suites.

Report generated by 🧪jest coverage report action from 32fa487

Please sign in to comment.