From 99ac4e7f5a389898673348449e4a522a86d07f1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sat, 30 Jan 2021 09:24:26 +0000 Subject: Keep track of open inline format, auto-close at block break --- aux/emparse | 91 ++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 54 insertions(+), 37 deletions(-) (limited to 'aux/emparse') diff --git a/aux/emparse b/aux/emparse index edafcae..929c1c7 100755 --- a/aux/emparse +++ b/aux/emparse @@ -60,37 +60,50 @@ function format(line) { else if (match(w[i], "^\\[[0-9a-z]+\\]\\)[.,:;?!]$")) w[i] = ref(substr(w[i], 2, RLENGTH-4)) substr(w[i], RLENGTH-1) - if (match(w[i], "^`")) - w[i] = "" substr(w[i], 2) - else if (match(w[i], "^\\*")) - w[i] = "" substr(w[i], 2) - else if (match(w[i], "^_")) - w[i] = "" substr(w[i], 2) - else if (match(w[i], "^\\(`")) - w[i] = "(" substr(w[i], 3) - else if (match(w[i], "^\\(\\*")) - w[i] = "(" substr(w[i], 3) - else if (match(w[i], "^\\(_")) - w[i] = "(" substr(w[i], 3) - - if (match(w[i], "`$")) - w[i] = substr(w[i], 1, RSTART-1) "" - else if (match(w[i], "\\*$")) - w[i] = substr(w[i], 1, RSTART-1) "" - else if (match(w[i], "_$")) - w[i] = substr(w[i], 1, RSTART-1) "" - else if (match(w[i], "`[.,:;?!)]$")) - w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) - else if (match(w[i], "\\*[.,:;?!)]$")) - w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) - else if (match(w[i], "_[.,:;?!)]$")) - w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) - else if (match(w[i], "`\\)[.,:;?!]$")) - w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) - else if (match(w[i], "\\*\\)[.,:;?!]$")) - w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) - else if (match(w[i], "_\\)[.,:;?!]$")) - w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) + if (!openformat) { + if (match(w[i], "^`")) { + w[i] = "" substr(w[i], 2) + openformat = "tt" + } else if (match(w[i], "^\\*")) { + w[i] = "" substr(w[i], 2) + openformat = "i" + } else if (match(w[i], "^_")) { + w[i] = "" substr(w[i], 2) + openformat = "b" + } else if (match(w[i], "^\\(`")) { + w[i] = "(" substr(w[i], 3) + openformat = "tt" + } else if (match(w[i], "^\\(\\*")) { + w[i] = "(" substr(w[i], 3) + openformat = "i" + } else if (match(w[i], "^\\(_")) { + w[i] = "(" substr(w[i], 3) + openformat = "b" + } + } + + if (openformat) { + orig = w[i] + if (match(w[i], "`$")) + w[i] = substr(w[i], 1, RSTART-1) "" + else if (match(w[i], "\\*$")) + w[i] = substr(w[i], 1, RSTART-1) "" + else if (match(w[i], "_$")) + w[i] = substr(w[i], 1, RSTART-1) "" + else if (match(w[i], "`[.,:;?!)]$")) + w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) + else if (match(w[i], "\\*[.,:;?!)]$")) + w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) + else if (match(w[i], "_[.,:;?!)]$")) + w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) + else if (match(w[i], "`\\)[.,:;?!]$")) + w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) + else if (match(w[i], "\\*\\)[.,:;?!]$")) + w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) + else if (match(w[i], "_\\)[.,:;?!]$")) + w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) + if (w[i] != orig) openformat = "" + } printf "%s", w[i] if (i < n) printf " " @@ -98,35 +111,39 @@ function format(line) { printf "\n" } -function beginblock(name) { +function opentag(name) { if (name == "nl") printf "
    \n" else printf "<%s>\n", name } -function endblock(name) { +function closetag(name) { if (name == "nl") printf "
\n" else printf "\n", name } function newblock(name) { - beginblock(name) + opentag(name) openblock = name - openitem = 0 expectblock = 0 } function breakblock() { + if (openformat) { + printf "", openformat + printf "(%s:%d) warning: open <%s> closed at block break\n", ARGV[1], NR, openformat > "/dev/stderr" + } if (openitem) { printf "\n" while (itemlevel-- > 1) - endblock(openblock) + closetag(openblock) itemlevel = 1 } if (opendef) printf "\n" - if (openblock) endblock(openblock) + if (openblock) closetag(openblock) openitem = 0 opendef = 0 openblock = 0 + openformat = "" expectblock = 1 } -- cgit v1.2.3