(tokens: NestedToken[])
| 94 | // and flatten it so content is always a string |
| 95 | // and type the type of the leaf |
| 96 | function flattenTokens(tokens: NestedToken[]) { |
| 97 | const flatList: FlatToken[] = []; |
| 98 | tokens.forEach(token => { |
| 99 | const { type, content } = token; |
| 100 | if (Array.isArray(content)) { |
| 101 | flatList.push(...flattenTokens(content)); |
| 102 | } else { |
| 103 | flatList.push({ type, content }); |
| 104 | } |
| 105 | }); |
| 106 | return flatList; |
| 107 | } |
| 108 | |
| 109 | export class MissingGrammarError extends Error { |
| 110 | lang: string; |