Skip to content

Commit

Permalink
feat(compiler): add export stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
minenwerfer committed Jan 18, 2025
1 parent 32414bb commit 23bfdb4
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 34 deletions.
1 change: 1 addition & 0 deletions packages/cli/src/buildAeriaLang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const buildAeriaLang = async () => {
try {
return await build(['schemas/*.aeria'], {
outDir: '.aeria/out',
// deprecated: new compiler only outputs esnext
module: tsConfig.compilerOptions.module === ts.ModuleKind.CommonJS
? 'commonjs'
: 'esnext',
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aeriajs/compiler",
"version": "0.0.111",
"version": "0.0.0",
"description": "",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down
37 changes: 37 additions & 0 deletions packages/compiler/src/compile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type * as AST from './ast.js'
import type { Diagnostic } from './diagnostic.js'
import { tokenize } from './lexer.js'
import { parse } from './parser.js'
import { analyze } from './semantic.js'

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

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))
const { errors: semanticErrors } = await analyze(ast)

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

return {
ast,
errors,
errorCount,
success: !errorCount,
}
}

export const compileFromFiles = async (fileList: string[], options: CompilationOptions) => {
//
}

39 changes: 6 additions & 33 deletions packages/compiler/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,7 @@
import { tokenize } from './lexer.js'
import { parse } from './parser.js'
// import { generateCode } from './codegen.js'
import { analyze } from './semantic.js'

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

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

const result = {
ast,
errors,
errorCount,
success: !errorCount,
}

console.log(JSON.stringify(result, null, 2))
}

const inputCode = `
collection Pet {
properties {
name str
}
}
`

const output = compile(inputCode)
console.log(JSON.stringify(output, null, 2))
export * from './ast.js'
export * from './compile.js'
export * from './parser.js'
export * from './lexer.js'
export * from './semantic.js'
export * from './token.js'

0 comments on commit 23bfdb4

Please sign in to comment.