MCPcopy Create free account
hub / github.com/denoland/std / createCollector

Function createCollector

xml/_tokenizer_test.ts:24–99  ·  view source on GitHub ↗

Creates callbacks that collect tokens into an array.

()

Source from the content-addressed store, hash-verified

22
23/** Creates callbacks that collect tokens into an array. */
24function 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",

Callers 4

collectTokensFunction · 0.85
collectChunkedTokensFunction · 0.85
_tokenizer_test.tsFile · 0.85
collectTokensXml11Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected