From 3fc1b4e5b19a8d2150e9272ab894b678ce90c7d6 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 25 Feb 2024 14:39:49 +0200 Subject: (awk-edits) Reverted to old MEL parser file name --- awk-edits/MEL--Parser.awk | 99 ----------------------------------------------- awk-edits/MEL-parser.awk | 99 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 99 deletions(-) delete mode 100644 awk-edits/MEL--Parser.awk create mode 100644 awk-edits/MEL-parser.awk diff --git a/awk-edits/MEL--Parser.awk b/awk-edits/MEL--Parser.awk deleted file mode 100644 index 248eff2..0000000 --- a/awk-edits/MEL--Parser.awk +++ /dev/null @@ -1,99 +0,0 @@ -# .*html -# -# == About == -# -# MEL is the "Markdown Extensions Language" -# It's a general metalanguage (I made) for adding custom syntax to Markdown (via awk) -# The idea is it provides parsing for general constructs, and you only need to define -# the names of those constructs and with what they get replaced with -# -# Slightly based on ftags, this system allows you to easily implement the following construts: -# &(name ... &) Multiline "tag", everything inside is formatted by "name" -# &{name ... &} In practice, it just replaces "&[name" and "&]" with the appropriate HTML -# &[name ... &] All three can be used interchangeably, though it's preferrable if -# you use the matching braces and semantically, in your "language" -# square brackets are used for the largest components -# curly for structural components and normal braces for styling -# &:name Format/encapsulate everything until the end of the paragraph -# &::name Format/encapsulate everything until the end of the line -# &.name Insert standalone element as-is -# -# Though it's not decided (or implemented) yet, potentially there will also be: -# &)-( Used to simplify cases of &(name1 ... &) &(name1 ... &) &(name1 ... &) -# &}-{ into &(name1 ... &)-( ... &)-( ... &) -# &]-[ Or maybe for special cases, where rather than doing something like -# &{elementsList &(element1 ... &) &(element2 ... &) &} -# you could simply do -# &{elementsList ... &}-{ ... &}-{ ... &} -# So it will surf as a separator between direct subelements - -BEGIN { - usesMEL() - newStack("mel") -} - -function usesMEL() { - MELOPEN = "o" - MELCLOSE = "c" - MELINSERT = "i" - MELPARAGRAPH = "p" - MELLINE = "l" -} - -// { - melInsideCode = 1 -} - -/<\/code>/ { - melInsideCode = 0 -} - -melInsideCode == 0 && /^[ \t]*(

|

)?&[{[()\]}:.]/ { - newLine = "" - lineCopy = $0 - paragraphed = 0 - while (match(lineCopy, /&(((::|[[{(:.])[^[:space:].:;[{(<>)}\]&]+)|[\]})])/)) { - RSTART += 5 - RLENGTH -= 5 - - # Inside closing tag - if (RLENGTH == 1) { - replaceWith = MEL[topStack("mel"), MELCLOSE] - popStack("mel") - } - # Inside insert - else if (substr(lineCopy, RSTART, 1) == ".") { - name = substr(lineCopy, RSTART + 1, RLENGTH - 1) - - 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 opening tag - else { - name = substr(lineCopy, RSTART + 1, RLENGTH - 1) - - replaceWith = MEL[name, MELOPEN] - pushStack("mel", name) - } - newLine = newLine substr(lineCopy, 0, RSTART - 6) replaceWith - lineCopy = substr(lineCopy, RSTART + RLENGTH) - } - $0 = newLine lineCopy - if (paragraphed == 0 && length(newLine) > 0) - gsub(/(

|<\/p>)/, "") -} diff --git a/awk-edits/MEL-parser.awk b/awk-edits/MEL-parser.awk new file mode 100644 index 0000000..248eff2 --- /dev/null +++ b/awk-edits/MEL-parser.awk @@ -0,0 +1,99 @@ +# .*html +# +# == About == +# +# MEL is the "Markdown Extensions Language" +# It's a general metalanguage (I made) for adding custom syntax to Markdown (via awk) +# The idea is it provides parsing for general constructs, and you only need to define +# the names of those constructs and with what they get replaced with +# +# Slightly based on ftags, this system allows you to easily implement the following construts: +# &(name ... &) Multiline "tag", everything inside is formatted by "name" +# &{name ... &} In practice, it just replaces "&[name" and "&]" with the appropriate HTML +# &[name ... &] All three can be used interchangeably, though it's preferrable if +# you use the matching braces and semantically, in your "language" +# square brackets are used for the largest components +# curly for structural components and normal braces for styling +# &:name Format/encapsulate everything until the end of the paragraph +# &::name Format/encapsulate everything until the end of the line +# &.name Insert standalone element as-is +# +# Though it's not decided (or implemented) yet, potentially there will also be: +# &)-( Used to simplify cases of &(name1 ... &) &(name1 ... &) &(name1 ... &) +# &}-{ into &(name1 ... &)-( ... &)-( ... &) +# &]-[ Or maybe for special cases, where rather than doing something like +# &{elementsList &(element1 ... &) &(element2 ... &) &} +# you could simply do +# &{elementsList ... &}-{ ... &}-{ ... &} +# So it will surf as a separator between direct subelements + +BEGIN { + usesMEL() + newStack("mel") +} + +function usesMEL() { + MELOPEN = "o" + MELCLOSE = "c" + MELINSERT = "i" + MELPARAGRAPH = "p" + MELLINE = "l" +} + +// { + melInsideCode = 1 +} + +/<\/code>/ { + melInsideCode = 0 +} + +melInsideCode == 0 && /^[ \t]*(

|

)?&[{[()\]}:.]/ { + newLine = "" + lineCopy = $0 + paragraphed = 0 + while (match(lineCopy, /&(((::|[[{(:.])[^[:space:].:;[{(<>)}\]&]+)|[\]})])/)) { + RSTART += 5 + RLENGTH -= 5 + + # Inside closing tag + if (RLENGTH == 1) { + replaceWith = MEL[topStack("mel"), MELCLOSE] + popStack("mel") + } + # Inside insert + else if (substr(lineCopy, RSTART, 1) == ".") { + name = substr(lineCopy, RSTART + 1, RLENGTH - 1) + + 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 opening tag + else { + name = substr(lineCopy, RSTART + 1, RLENGTH - 1) + + replaceWith = MEL[name, MELOPEN] + pushStack("mel", name) + } + newLine = newLine substr(lineCopy, 0, RSTART - 6) replaceWith + lineCopy = substr(lineCopy, RSTART + RLENGTH) + } + $0 = newLine lineCopy + if (paragraphed == 0 && length(newLine) > 0) + gsub(/(

|<\/p>)/, "") +} -- cgit v1.3.1-23-gd82d