๐Ÿ๐Ÿ๐Ÿ
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

clean up trash files

autumn db41cf13 144ab243

-349
-178
webui/js/code/orbpast/orb.js
··· 1 - 2 - export async function main(target) { 3 - const response = await fetch("test.orb"); 4 - if (!response.ok) { 5 - throw new Error(`Failed to load test.orb`); 6 - } 7 - const orbSource = await response.text(); 8 - 9 - console.log(orbSource); 10 - 11 - console.log(dumpNodes(parseOrb(orbSource), orbSource)); 12 - } 13 - 14 - function parseOrb(input, startIndex = 0, endIndex = input.length) { 15 - const nodes = []; 16 - let scanPosition = startIndex; 17 - let escapeNext = false; 18 - 19 - while (scanPosition < endIndex) { 20 - let current_node = { 21 - tag: 'NONE', 22 - content_start: scanPosition, 23 - content_end: scanPosition, 24 - last_nonws_start: -1, 25 - last_nonws_end: -1 26 - }; 27 - 28 - while (scanPosition < endIndex) { 29 - const char = input[scanPosition]; 30 - 31 - if (escapeNext) { 32 - current_node.content_end = scanPosition + 1; 33 - escapeNext = false; 34 - scanPosition++; 35 - continue; 36 - } 37 - 38 - if (char === '\\') { 39 - escapeNext = true; 40 - current_node.content_end = scanPosition + 1; 41 - scanPosition++; 42 - continue; 43 - } 44 - 45 - if (char === '{') { 46 - let tag = 'NONE'; 47 - let contentEndBeforeTag = current_node.content_end; 48 - 49 - // Extract tag if we have non-whitespace 50 - if (current_node.last_nonws_start !== -1) { 51 - tag = input.substring(current_node.last_nonws_start, current_node.last_nonws_end); 52 - contentEndBeforeTag = current_node.last_nonws_start; 53 - } 54 - 55 - // Push text node before the tag (if any content exists) 56 - if (contentEndBeforeTag > current_node.content_start) { 57 - nodes.push({ 58 - tag: 'NONE', 59 - content_start: current_node.content_start, 60 - content_end: contentEndBeforeTag 61 - }); 62 - } 63 - 64 - scanPosition++; // skip the { 65 - 66 - const closing_pos = findClosingBracket(input, scanPosition); 67 - 68 - if (!shouldParseContent(tag)) { 69 - const raw_content = input.substring(scanPosition, closing_pos); 70 - nodes.push({ 71 - tag: tag, 72 - raw_content: raw_content, 73 - content_start: scanPosition, 74 - content_end: closing_pos 75 - }); 76 - } else { 77 - const nested_content = parseOrb(input, scanPosition, closing_pos); 78 - nodes.push({ 79 - tag: tag, 80 - content: nested_content, 81 - content_start: scanPosition, 82 - content_end: closing_pos 83 - }); 84 - } 85 - 86 - scanPosition = closing_pos + 1; // skip } 87 - break; 88 - } 89 - 90 - if (char === '}') { 91 - break; 92 - } 93 - 94 - // Update content end and track non-whitespace 95 - current_node.content_end = scanPosition + 1; 96 - 97 - if (!/\s/.test(char)) { 98 - if (current_node.last_nonws_start === -1 || 99 - (scanPosition > 0 && /\s/.test(input[scanPosition - 1]))) { 100 - // Starting a new word (either first word or after whitespace) 101 - current_node.last_nonws_start = scanPosition; 102 - } 103 - current_node.last_nonws_end = scanPosition + 1; 104 - } 105 - 106 - scanPosition++; 107 - } 108 - 109 - // Finish the current node if it has content 110 - if (current_node.content_end > current_node.content_start) { 111 - nodes.push({ 112 - tag: current_node.tag, 113 - content_start: current_node.content_start, 114 - content_end: current_node.content_end 115 - }); 116 - } 117 - 118 - // Break if we hit end or closing bracket 119 - if (scanPosition >= endIndex || (scanPosition < input.length && input[scanPosition] === '}')) { 120 - break; 121 - } 122 - } 123 - 124 - return nodes; 125 - } 126 - 127 - function findClosingBracket(input, startIndex) { 128 - let scanPosition = startIndex; 129 - let depth = 1; 130 - let escapeNext = false; 131 - 132 - while (scanPosition < input.length && depth > 0) { 133 - const char = input[scanPosition]; 134 - 135 - if (escapeNext) { 136 - escapeNext = false; 137 - } else if (char === '\\') { 138 - escapeNext = true; 139 - } else if (char === '{') { 140 - depth++; 141 - } else if (char === '}') { 142 - depth--; 143 - } 144 - 145 - scanPosition++; 146 - } 147 - 148 - return scanPosition - 1; 149 - } 150 - 151 - function shouldParseContent(tag) { 152 - return tag !== "fractal"; 153 - } 154 - 155 - function dumpNodes(nodes, input) { 156 - if (!Array.isArray(nodes)) { 157 - throw new Error('nodes must be an array'); 158 - } 159 - if (typeof input !== 'string') { 160 - throw new Error('input must be a string'); 161 - } 162 - 163 - for (const node of nodes) { 164 - let content; 165 - 166 - if (node.raw_content !== undefined) { 167 - content = node.raw_content; 168 - } else if (node.content !== undefined) { 169 - dumpNodes(node.content, input); 170 - content = `[${node.content.length} nested nodes]`; 171 - } else { 172 - content = input.substring(node.content_start, node.content_end); 173 - } 174 - 175 - console.log(`TAG{${node.tag}} | CONTENT{${content}}`); 176 - } 177 - } 178 -
-171
webui/js/code/orbpast/orb_prev.js
··· 1 - 2 - export async function main(target) { 3 - 4 - const response = await fetch("test.orb"); 5 - if (!response.ok) { 6 - throw new Error(`Failed to load test.orb`); 7 - } 8 - const orbSource = await response.text(); 9 - 10 - console.log(orbSource); 11 - 12 - console.log(dumpNodes(parseOrb(orbSource), orbSource)); 13 - 14 - } 15 - 16 - function parseOrb(input, startIndex = 0, endIndex = input.length) { 17 - const nodes = []; 18 - let scanPosition = startIndex; 19 - let escapeNext = false; 20 - 21 - while (scanPosition < endIndex) { 22 - let current_node = { 23 - tag: 'NONE', 24 - scan_index: scanPosition, 25 - content_start: scanPosition, 26 - content_end: scanPosition, 27 - last_nonws_start: -1, 28 - last_nonws_end: -1 29 - }; 30 - 31 - while (scanPosition < endIndex) { 32 - const char = input[scanPosition]; 33 - 34 - if (escapeNext) { 35 - current_node.content_end = scanPosition + 1; 36 - escapeNext = false; 37 - scanPosition++; 38 - continue; 39 - } 40 - 41 - if (char === '\\') { 42 - escapeNext = true; 43 - current_node.content_end = scanPosition + 1; 44 - scanPosition++; 45 - continue; 46 - } 47 - 48 - if (char === '{') { 49 - scanPosition++; // don't collect the { 50 - 51 - // extract tag 52 - if (current_node.last_nonws_start !== -1) { 53 - const tag = input.substring(current_node.last_nonws_start, current_node.last_nonws_end); 54 - current_node.tag = tag; 55 - // exclude tag 56 - current_node.content_end = current_node.last_nonws_start; 57 - } 58 - 59 - // finish off the NONE node 60 - if (current_node.content_end > current_node.content_start) { 61 - nodes.push(current_node); 62 - } 63 - 64 - if (!shouldParseContent(current_node.tag)) { 65 - const closing_pos = findClosingBracket(input, scanPosition); 66 - const raw_content = input.substring(scanPosition, closing_pos); 67 - nodes.push({ 68 - tag: current_node.tag, 69 - raw_content: raw_content, 70 - content_start: scanPosition, 71 - content_end: closing_pos 72 - }); 73 - scanPosition = closing_pos + 1; // skip } 74 - } else { 75 - const closing_pos = findClosingBracket(input, scanPosition); 76 - const nested_content = parseOrb(input, scanPosition, closing_pos); 77 - nodes.push({ 78 - tag: current_node.tag, 79 - content: nested_content, 80 - content_start: scanPosition, 81 - content_end: closing_pos 82 - }); 83 - scanPosition = closing_pos + 1; // skip } 84 - } 85 - break; 86 - } 87 - 88 - if (char === '}') break; 89 - 90 - // Update content endIndex and track non-whitespace 91 - current_node.content_end = scanPosition + 1; 92 - 93 - if (!/\s/.test(char)) { 94 - if (current_node.last_nonws_start === -1) { 95 - current_node.last_nonws_start = scanPosition; 96 - } 97 - current_node.last_nonws_end = scanPosition + 1; 98 - } else if (current_node.last_nonws_start !== -1) { 99 - // Hit whitespace after non-whitespace - complete the run 100 - // (last_nonws_end is already set correctly) 101 - } 102 - 103 - scanPosition++; 104 - } 105 - 106 - // finish node 107 - if (current_node.content_end > current_node.content_start) { 108 - nodes.push(current_node); 109 - } 110 - 111 - // if we hit endIndex of input or closing bracket, we're done 112 - if (scanPosition >= endIndex || input[scanPosition] === '}') { 113 - break; 114 - } 115 - } 116 - 117 - return nodes; 118 - } 119 - 120 - function findClosingBracket(input, startIndex) { 121 - let scanPosition = startIndex; 122 - let depth = 1; 123 - let escapeNext = false; 124 - 125 - while (scanPosition < input.length && depth > 0) { 126 - const char = input[scanPosition]; 127 - 128 - if (escapeNext) { 129 - escapeNext = false; 130 - } else if (char === '\\') { 131 - escapeNext = true; 132 - } else if (char === '{') { 133 - depth++; 134 - } else if (char === '}') { 135 - depth--; 136 - } 137 - 138 - scanPosition++; 139 - } 140 - 141 - return scanPosition - 1; 142 - } 143 - 144 - function shouldParseContent(tag) { 145 - return tag !== "fractal"; 146 - } 147 - 148 - function dumpNodes(nodes, input) { 149 - if (!Array.isArray(nodes)) { 150 - throw new Error('nodes must be an array'); 151 - } 152 - if (typeof input !== 'string') { 153 - throw new Error('input must be a string'); 154 - } 155 - 156 - for (const node of nodes) { 157 - let content; 158 - 159 - if (node.raw_content !== undefined) { 160 - content = node.raw_content; 161 - } else if (node.content !== undefined) { 162 - dumpNodes(node.content, input); 163 - content = `[${node.content.length} nested nodes]`; 164 - } else { 165 - content = input.substring(node.content_start, node.content_end); 166 - } 167 - 168 - console.log(`TAG{${node.tag}} | CONTENT{${content}}`); 169 - } 170 - } 171 -