Summary Files Commits Branches @commit @diff @stats
path: root / awk-edits / MEL-parser.awk
diff options
context:
space:
mode:
1 files changed, 35 insertions, 18 deletions
-rw-r--r--awk-edits/MEL-parser.awk53
diff --git a/awk-edits/MEL-parser.awk b/awk-edits/MEL-parser.awk
index ebd68bd..d1eb4d5 100644
--- a/awk-edits/MEL-parser.awk
+++ b/awk-edits/MEL-parser.awk
@@ -1,4 +1,4 @@
-# .*(slides|teaching)/.*html
+# .*html
#
# == About ==
#
@@ -29,9 +29,11 @@
BEGIN {
newStack("mel")
- MELSINGLE = "s"
- MELOPEN = "o"
- MELCLOSE = "c"
+ MELOPEN = "o"
+ MELCLOSE = "c"
+ MELINSERT = "s"
+ MELPARAGRAPH = "p"
+ MELLINE = "l"
}
/<code>/ {
@@ -42,37 +44,52 @@ BEGIN {
melInsideCode = 0
}
-melInsideCode == 0 && /^[ \t]*(<p>)?&#38;/ {
+melInsideCode == 0 && /^[ \t]*(<p>|<dt>)?&#38;[{[()\]}:.]/ {
newLine = ""
lineCopy = $0
- while (match(lineCopy, /&#38;(((::|[[{(:.])[^[:space:].:[{(<>)}\]&]+)|[\]})])/)) {
- RSTART = RSTART + 5
- RLENGTH = RLENGTH - 5
+ paragraphed = 0
+ while (match(lineCopy, /&#38;(((::|[[{(:.])[^[:space:].:;[{(<>)}\]&]+)|[\]})])/)) {
+ RSTART += 5
+ RLENGTH -= 5
# Inside closing tag
if (RLENGTH == 1) {
replaceWith = MEL[topStack("mel"), MELCLOSE]
popStack("mel")
}
- # Inside opening tag
- else if (substr(lineCopy, RSTART, 1) ~ /[[{(]/) {
+ # Inside insert
+ else if (substr(lineCopy, RSTART, 1) == ".") {
name = substr(lineCopy, RSTART + 1, RLENGTH - 1)
- replaceWith = MEL[name, MELOPEN]
- pushStack("mel", name)
+ replaceWith = MEL[name, MELINSERT]
+ }
+ # Inside one line TODO
+ else if (substr(lineCopy, RSTART, 2) == "::") {
+ name = substr(lineCopy, RSTART + 2, RLENGTH - 2)
+
+ # RLENGTH = length(lineCopy)
+ replaceWith = MEL[name, MELLINE]
+ }
+ # Inside paragraph
+ else if (substr(lineCopy, RSTART, 1) == ":") {
+ name = substr(lineCopy, RSTART + 1, RLENGTH - 1)
+
+ replaceWith = " " MEL[name, MELPARAGRAPH]
+ RSTART -= 1
+ RLENGTH += 1
+ paragraphed = 1
}
- # Inside paragraph/one line/insert
- # TODO: currently all work as insert
+ # Inside opening tag
else {
- nameStart = 1 + (substr(lineCopy, RSTART + 1, 1) == ":")
- name = substr(lineCopy, RSTART + nameStart, RLENGTH - nameStart)
+ name = substr(lineCopy, RSTART + 1, RLENGTH - 1)
- replaceWith = MEL[name, MELSINGLE]
+ replaceWith = MEL[name, MELOPEN]
+ pushStack("mel", name)
}
newLine = newLine substr(lineCopy, 0, RSTART - 6) replaceWith
lineCopy = substr(lineCopy, RSTART + RLENGTH)
}
$0 = newLine lineCopy
- if (length(newLine) > 0)
+ if (paragraphed == 0 && length(newLine) > 0)
gsub(/(<p>|<\/p>)/, "")
}