Skip to content

Commit

Permalink
refactor(compiler): compile() function
Browse files Browse the repository at this point in the history
  • Loading branch information
minenwerfer committed Jan 21, 2025
1 parent 0a8ed68 commit f44dcc5
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/compiler/src/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,36 @@ import { parse } from './parser.js'
import { analyze } from './semantic.js'

export type CompilationResult = {
success: boolean
ast: AST.ProgramNode
errors: Diagnostic[]
errorCount: number
success: boolean
emittedFiles: string[]
}

export type CompilationOptions = {
outDir: string
}

export const compile = async (input: string): Promise<CompilationResult> => {
const { tokens, errors: lexerErrors } = tokenize(input)
const { ast, errors: parserErrors } = parse(Array.from(tokens))
export const parseAndCheck = async (input: string): Promise<CompilationResult> => {
const { errors: lexerErrors, tokens } = tokenize(input)
const { errors: parserErrors, ast } = parse(Array.from(tokens))
const { errors: semanticErrors } = await analyze(ast)

const errors = lexerErrors.concat(parserErrors, semanticErrors)
const errorCount = errors.length

return {
success: !errorCount,
ast,
errors,
errorCount,
success: !errorCount,
emittedFiles: [],
}
}

export const compileFromFiles = async (fileList: string[], options: CompilationOptions) => {
// @ts-expect-error
export const compile = async (fileList: string[], options: CompilationOptions): Promise<CompilationResult> => {
//
}

0 comments on commit f44dcc5

Please sign in to comment.