-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
32414bb
commit 23bfdb4
Showing
4 changed files
with
45 additions
and
34 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 |
---|---|---|
@@ -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) => { | ||
// | ||
} | ||
|
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,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' | ||
|