| 52 | } |
| 53 | |
| 54 | function parseTag(content: string, line: number, contentStart: number) { |
| 55 | try { |
| 56 | return parse(content, { Variable, Function }); |
| 57 | } catch (error) { |
| 58 | if (!(error instanceof SyntaxError)) throw error; |
| 59 | const { |
| 60 | message, |
| 61 | location: { start, end }, |
| 62 | } = error as SyntaxError; |
| 63 | const location = { |
| 64 | start: { line, character: start.offset + contentStart }, |
| 65 | end: { line: line + 1, character: end.offset + contentStart }, |
| 66 | }; |
| 67 | |
| 68 | return { type: 'error', meta: { error: { message, location } } }; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | export function parseTags(content: string, firstLine = 0): Token[] { |
| 73 | let line = firstLine + 1; |