* initial types Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * start using generated types Signed-off-by: Jess Frazelle <github@jessfraz.com> * generate ast types Signed-off-by: Jess Frazelle <github@jessfraz.com> * cleanup Signed-off-by: Jess Frazelle <github@jessfraz.com> * generate for error types as well Signed-off-by: Jess Frazelle <github@jessfraz.com> --------- Signed-off-by: Jess Frazelle <github@jessfraz.com>
29 lines
685 B
TypeScript
29 lines
685 B
TypeScript
import { lexer_js } from '../wasm-lib/pkg/wasm_lib'
|
|
import { initPromise } from './rust'
|
|
import { Token } from '../wasm-lib/bindings/Token'
|
|
|
|
export type { Token } from '../wasm-lib/bindings/Token'
|
|
|
|
export async function asyncLexer(str: string): Promise<Token[]> {
|
|
await initPromise
|
|
try {
|
|
const tokens: Token[] = lexer_js(str)
|
|
return tokens
|
|
} catch (e) {
|
|
// TODO: do something real with the error.
|
|
console.log('lexer', e)
|
|
throw e
|
|
}
|
|
}
|
|
|
|
export function lexer(str: string): Token[] {
|
|
try {
|
|
const tokens: Token[] = lexer_js(str)
|
|
return tokens
|
|
} catch (e) {
|
|
// TODO: do something real with the error.
|
|
console.log('lexer', e)
|
|
throw e
|
|
}
|
|
}
|