/ {
melInsideCode = 1
}
/<\/code>/ {
melInsideCode = 0
}
melInsideCode == 0 && /^[ \t]*(|
)?&[{[()\]}:.]/ {
newLine = ""
lineCopy = $0
paragraphed = 0
append = ""
while (match(lineCopy, /&(((::|[[{(:.])[^[:space:].:;[{(<>)}\]&]+)|[\]})])/)) {
RSTART += 5
RLENGTH -= 5
# Inside closing tag
if (RLENGTH == 1) {
replaceWith = MEL[topStack("mel"), MELCLOSE]
if (replaceWith == "")
printErr("Missing closing tag for \"" topStack("mel") "\"")
popStack("mel")
}
# Inside insert
else if (substr(lineCopy, RSTART, 1) == ".") {
name = substr(lineCopy, RSTART + 1, RLENGTH - 1)
replaceWith = MEL[name, MELINSERT]
if (replaceWith == "")
printErr("Unknown insertion tag \"" name "\"")
}
# Inside one line
else if (substr(lineCopy, RSTART, 2) == "::") {
name = substr(lineCopy, RSTART + 2, RLENGTH - 2)
replaceWith = MEL[name, MELLINEOPEN]
append = append MEL[name, MELLINECLOSE]
if (replaceWith == "")
printErr("Missing beginning for line tag \"" name "\"")
else if (MEL[name, MELLINECLOSE] == "")
printErr("Missing ending for line tag \"" name "\"")
else if (replaceWith == "" && MEL[name, MELLINECLOSE] == "")
printErr("Unknown single line tag \"" name "\"")
}
# Inside paragraph
else if (substr(lineCopy, RSTART, 1) == ":") {
name = substr(lineCopy, RSTART + 1, RLENGTH - 1)
replaceWith = " " MEL[name, MELPARAGRAPH]
if (replaceWith == " ")
printErr("Unknown paragraph tag \"" name "\"")
RSTART -= 1
RLENGTH += 1
paragraphed = 1
}
# Inside opening tag
else {
name = substr(lineCopy, RSTART + 1, RLENGTH - 1)
replaceWith = MEL[name, MELOPEN]
pushStack("mel", name)
if (replaceWith == "")
printErr("Unknown opening tag \"" name "\"")
}
newLine = newLine substr(lineCopy, 0, RSTART - 6) replaceWith
lineCopy = substr(lineCopy, RSTART + RLENGTH)
}
$0 = newLine lineCopy append
if (paragraphed == 0 && newLine != "")
gsub(/(|<\/p>)/, "")
}