« get me outta code hell

add hash to tag syntax - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <towerofnix@gmail.com>2021-04-16 13:53:27 -0300
committer(quasar) nebula <towerofnix@gmail.com>2021-04-16 13:53:27 -0300
commit32448fb8ff1c5474e25847c0cae397bdf1c6f5ab (patch)
tree5f5b49eb5b33f1437c0dcd0c61923aa56067d737
parentc6a8b367a5a1a243e5112a33aedee9e9147f7a0f (diff)
add hash to tag syntax
-rwxr-xr-xupd8.js27
1 files changed, 23 insertions, 4 deletions
diff --git a/upd8.js b/upd8.js
index 6986ac82..504cd6d0 100755
--- a/upd8.js
+++ b/upd8.js
@@ -965,6 +965,7 @@ const replacerSpec = {
     const tagBeginning = '[[';
     const tagEnding = ']]';
     const tagReplacerValue = ':';
+    const tagHash = '#';
     const tagArgument = '*';
     const tagArgumentValue = '=';
     const tagLabel = '|';
@@ -972,6 +973,7 @@ const replacerSpec = {
     const R_tagBeginning = escapeRegex(tagBeginning);
     const R_tagEnding = escapeRegex(tagEnding);
     const R_tagReplacerValue = escapeRegex(tagReplacerValue);
+    const R_tagHash = escapeRegex(tagHash);
     const R_tagArgument = escapeRegex(tagArgument);
     const R_tagArgumentValue = escapeRegex(tagArgumentValue);
     const R_tagLabel = escapeRegex(tagLabel);
@@ -1066,7 +1068,7 @@ const replacerSpec = {
 
                 // Replacer key (or value)
 
-                N = parseOneTextNode(input, i, [R_tagReplacerValue, R_tagArgument, R_tagLabel, R_tagEnding]);
+                N = parseOneTextNode(input, i, [R_tagReplacerValue, R_tagHash, R_tagArgument, R_tagLabel, R_tagEnding]);
 
                 if (!stopped) throw endOfInput(i, `reading replacer key`);
 
@@ -1074,8 +1076,9 @@ const replacerSpec = {
                     switch (stop_literal) {
                         case tagReplacerValue:
                         case tagArgument:
-                        case tagLabel:
                             throw makeError(i, `Expected text (replacer key).`);
+                        case tagLabel:
+                        case tagHash:
                         case tagEnding:
                             throw makeError(i, `Expected text (replacer key/value).`);
                     }
@@ -1089,7 +1092,7 @@ const replacerSpec = {
                 let replacerSecond;
 
                 if (stop_literal === tagReplacerValue) {
-                    N = parseNodes(input, i, [R_tagArgument, R_tagLabel, R_tagEnding]);
+                    N = parseNodes(input, i, [R_tagHash, R_tagArgument, R_tagLabel, R_tagEnding]);
 
                     if (!stopped) throw endOfInput(i, `reading replacer value`);
                     if (!N.length) throw makeError(i, `Expected content (replacer value).`);
@@ -1114,6 +1117,22 @@ const replacerSpec = {
                     replacerValue = [replacerFirst];
                 }
 
+                // Hash
+
+                let hash;
+
+                if (stop_literal === tagHash) {
+                    N = parseNodes(input, i, [R_tagArgument, R_tagLabel, R_tagEnding]);
+
+                    if (!stopped) throw endOfInput(i, `reading hash`);
+
+                    if (!N)
+                        throw makeError(i, `Expected content (hash).`);
+
+                    hash = N;
+                    i = stop_iParse;
+                }
+
                 // Arguments
 
                 const args = [];
@@ -1155,7 +1174,7 @@ const replacerSpec = {
                     i = stop_iParse;
                 }
 
-                nodes.push({i: iTag, type: 'tag', data: {replacerKey, replacerValue, args, label}});
+                nodes.push({i: iTag, type: 'tag', data: {replacerKey, replacerValue, hash, args, label}});
 
                 continue;
             }