-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from source-academy/move-exported-methods
Move exported methods to src
- Loading branch information
Showing
4 changed files
with
20 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
} |
32fa487
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage report
Test suite run success
1074 tests passing in 52 suites.
Report generated by 🧪jest coverage report action from 32fa487