Creates callbacks that collect tokens into an array.
()
| 22 | |
| 23 | /** Creates callbacks that collect tokens into an array. */ |
| 24 | function createCollector(): { |
| 25 | tokens: XmlToken[]; |
| 26 | callbacks: XmlTokenCallbacks; |
| 27 | } { |
| 28 | const tokens: XmlToken[] = []; |
| 29 | const callbacks: XmlTokenCallbacks = { |
| 30 | onStartTagOpen(name, line, column, offset) { |
| 31 | tokens.push({ |
| 32 | type: "start_tag_open", |
| 33 | name, |
| 34 | position: { line, column, offset }, |
| 35 | }); |
| 36 | }, |
| 37 | onAttribute(name, value) { |
| 38 | tokens.push({ type: "attribute", name, value }); |
| 39 | }, |
| 40 | onStartTagClose(selfClosing) { |
| 41 | tokens.push({ type: "start_tag_close", selfClosing }); |
| 42 | }, |
| 43 | onEndTag(name, line, column, offset) { |
| 44 | tokens.push({ |
| 45 | type: "end_tag", |
| 46 | name, |
| 47 | position: { line, column, offset }, |
| 48 | }); |
| 49 | }, |
| 50 | onText(content, line, column, offset) { |
| 51 | tokens.push({ |
| 52 | type: "text", |
| 53 | content, |
| 54 | position: { line, column, offset }, |
| 55 | }); |
| 56 | }, |
| 57 | onCData(content, line, column, offset) { |
| 58 | tokens.push({ |
| 59 | type: "cdata", |
| 60 | content, |
| 61 | position: { line, column, offset }, |
| 62 | }); |
| 63 | }, |
| 64 | onComment(content, line, column, offset) { |
| 65 | tokens.push({ |
| 66 | type: "comment", |
| 67 | content, |
| 68 | position: { line, column, offset }, |
| 69 | }); |
| 70 | }, |
| 71 | onProcessingInstruction(target, content, line, column, offset) { |
| 72 | tokens.push({ |
| 73 | type: "processing_instruction", |
| 74 | target, |
| 75 | content, |
| 76 | position: { line, column, offset }, |
| 77 | }); |
| 78 | }, |
| 79 | onDeclaration(version, encoding, standalone, line, column, offset) { |
| 80 | tokens.push({ |
| 81 | type: "declaration", |
no outgoing calls
no test coverage detected