From 6d437b04c4517783e682e2309cc9e0056883c488 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 25 Feb 2024 15:48:19 +0200 Subject: (awk-edits/MEL) Added error messages --- awk-edits/MEL-parser.awk | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/awk-edits/MEL-parser.awk b/awk-edits/MEL-parser.awk index 6cf0514..af1e26d 100644 --- a/awk-edits/MEL-parser.awk +++ b/awk-edits/MEL-parser.awk @@ -42,6 +42,11 @@ function usesMEL() { MELLINE = "l" } +function printErr(message) { + print "ERROR by MEL-parser.awk: " message " | Found in " FILENAME " at line " FNR " & column " RSTART + length(newLine) - 5 ":\n" $0 > "/dev/stderr" + print > "/dev/stderr" +} + // { melInsideCode = 1 } @@ -62,6 +67,10 @@ melInsideCode == 0 && /^[ \t]*(

|

)?&[{[()\]}:.]/ { # Inside closing tag if (RLENGTH == 1) { replaceWith = MEL[topStack("mel"), MELCLOSE] + + if (replaceWith == "") + printErr("Missing closing tag for \"" topStack("mel") "\"") + popStack("mel") } # Inside insert @@ -69,6 +78,9 @@ melInsideCode == 0 && /^[ \t]*(

|

)?&[{[()\]}:.]/ { 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) == "::") { @@ -76,6 +88,14 @@ melInsideCode == 0 && /^[ \t]*(

|

)?&[{[()\]}:.]/ { replaceWith = MEL[name, MELLINEOPEN] append = append MEL[name, MELLINECLOSE] + + + if (replaceWith == "" && append == "") + printErr("Unknown single line tag \"" name "\"") + else if (replaceWith == "") + printErr("Missing beginning for line tag \"" name "\"") + else + printErr("Missing ending for line tag \"" name "\"") } # Inside paragraph else if (substr(lineCopy, RSTART, 1) == ":") { @@ -85,6 +105,9 @@ melInsideCode == 0 && /^[ \t]*(

|

)?&[{[()\]}:.]/ { RSTART -= 1 RLENGTH += 1 paragraphed = 1 + + if (replaceWith == "") + printErr("Unknown paragraph tag \"" name "\"") } # Inside opening tag else { @@ -92,6 +115,9 @@ melInsideCode == 0 && /^[ \t]*(

|

)?&[{[()\]}:.]/ { 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) -- cgit v1.3.1-23-gd82d