| 1 | import init from './yaml.wasm?init'; |
| 2 | |
| 3 | export interface GoValueType { |
| 4 | response: string |
| 5 | error: string |
| 6 | } |
| 7 | |
| 8 | export interface YAMLGoFuncMap { |
| 9 | decode: (v: string) => GoValueType; |
| 10 | tokenize: (v: string) => GoValueType; |
| 11 | parseGroup: (v: string) => GoValueType; |
| 12 | parse: (v: string) => GoValueType; |
| 13 | } |
| 14 | |
| 15 | export interface YAMLFuncMap { |
| 16 | decode: (code: string) => Promise<YAMLProcessResult> |
| 17 | tokenize: (code: string) => Promise<YAMLProcessResult> |
| 18 | parseGroup: (code: string) => Promise<YAMLProcessResult> |
| 19 | parse: (code: string) => Promise<YAMLProcessResult> |
| 20 | } |
| 21 | |
| 22 | export enum YAMLProcessResultType { |
| 23 | Decode, |
| 24 | Lexer, |
| 25 | ParserGroup, |
| 26 | Parser, |
| 27 | } |
| 28 | |
| 29 | export interface YAMLProcessResult { |
| 30 | type: YAMLProcessResultType |
| 31 | result: Token[] | GroupedToken[] | string |
| 32 | } |
| 33 | |
| 34 | export interface Token { |
| 35 | type: string |
| 36 | value: string |
| 37 | origin: string |
| 38 | error: string |
| 39 | line: number |
| 40 | column: number |
| 41 | offset: number |
| 42 | } |
| 43 | |
| 44 | export interface GroupedToken { |
| 45 | token: Token |
| 46 | group: TokenGroup |
| 47 | lineComment: Token |
| 48 | } |
| 49 | |
| 50 | export interface TokenGroup { |
| 51 | type: string |
| 52 | tokens: GroupedToken[] |
| 53 | } |
| 54 | |
| 55 | declare function decode(v: string): GoValueType; |
| 56 | declare function tokenize(v: string): GoValueType; |
| 57 | declare function parseGroup(v: string): GoValueType; |
| 58 | declare function parse(v: string): GoValueType; |
| 59 | |
| 60 | export const initWASM = async (): Promise<YAMLGoFuncMap> => { |
| 61 | const go = new Go(); |
| 62 | return new Promise(resolve => { |
| 63 | init( |
| 64 | go.importObject, |
| 65 | ).then((instance) => { |
| 66 | go.run(instance); |
| 67 | resolve({ |
| 68 | decode: decode, |
| 69 | tokenize: tokenize, |
| 70 | parseGroup: parseGroup, |
| 71 | parse: parse, |
| 72 | }); |
| 73 | }); |
| 74 | }); |
| 75 | }; |