File tree Expand file tree Collapse file tree 2 files changed +11
-14
lines changed
Expand file tree Collapse file tree 2 files changed +11
-14
lines changed Original file line number Diff line number Diff line change 11import * as JVM from './jvm'
2+ import { typeCheck } from './types'
23
3- export { JVM }
4+ export { JVM , typeCheck }
Original file line number Diff line number Diff line change 11import { check } from './checker'
2- import { Node } from './ast/types'
32import { parse } from './ast'
43import { 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- }
You can’t perform that action at this time.
0 commit comments