implement --parser-option allow-line-continuation-with-escaping + add skeleton for allow-line-continuation-with-space v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Tue, 21 Sep 2021 21:02:43 +0200
branchv_0
changeset 34 7eb3dcacba7b
parent 33 3b81fbeb5f3b
child 35 930f17f16fd7
implement --parser-option allow-line-continuation-with-escaping + add skeleton for allow-line-continuation-with-space
bash-completion.sh
src/lib/INIReader.cpp
src/lib/uri.h
--- a/bash-completion.sh	Sun Dec 13 17:34:26 2020 +0100
+++ b/bash-completion.sh	Tue Sep 21 21:02:43 2021 +0200
@@ -30,6 +30,8 @@
 	# TODO: introspection: after moving to alt2xml the available options and their values should be provided by the parser
 
 	PARSER_OPTIONS=(
+		"allow-line-continuation-with-escaping"
+		"allow-line-continuation-with-space"
 		"trim-continuing-lines"
 		"allow-sections"
 		"allow-section-tags"
@@ -56,6 +58,8 @@
 	elif [[ "$w1" == "--enable-line-numbers"                            ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
 	elif [[ "$w1" == "--enable-event-numbers"                           ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
 	elif [[ "$w1" == "--parser-option"                                  ]];    then COMPREPLY=($(compgen -W "${PARSER_OPTIONS[*]}" -- "$w0"))
+	elif [[ "$w2" == "--parser-option" && "$w1" == "allow-line-continuation-with-escaping"    ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
+	elif [[ "$w2" == "--parser-option" && "$w1" == "allow-line-continuation-with-space"       ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
 	elif [[ "$w2" == "--parser-option" && "$w1" == "trim-continuing-lines"                    ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
 	elif [[ "$w2" == "--parser-option" && "$w1" == "allow-sections"                           ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
 	elif [[ "$w2" == "--parser-option" && "$w1" == "allow-section-tags"                       ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
--- a/src/lib/INIReader.cpp	Sun Dec 13 17:34:26 2020 +0100
+++ b/src/lib/INIReader.cpp	Tue Sep 21 21:02:43 2021 +0200
@@ -58,6 +58,20 @@
 
 	std::vector<ConfiguredDialect> dialects;
 
+	/**
+	 * If there is a „\“ backspace at the end of a physical line, the logical line continues on the next physical line.
+	 *
+	 * Disabling this option makes sense only if we also disable the unescaping processors (unescape-basic, unescape-backspace).
+	 * Otherwise they will complain about „Missing escape sequence“ because they got „\“ at the end of the value.
+	 */
+	bool allowLineContinuationsWithEscaping = true;
+
+	/**
+	 * If a line starts with a space, it is continuation of the previous line.
+	 * This rule conflicts with default ignorance of such insignificant whitespace and is quite specific to the Java MANIFEST.MF dialect.
+	 */
+	bool allowLineContinuationsWithSpace = false;
+
 	/** 
 	 * By default, we ignore all leading whitespace on continuing lines.
 	 * If there should be some spaces or tabs, they should be placed on the previous line before the „\“.
@@ -189,7 +203,7 @@
 		std::stringstream result;
 
 		for (char ch = peek(); input.good() && !oneOf(ch, until); ch = peek()) {
-			if (ch == '\\') {
+			if (allowLineContinuationsWithEscaping && ch == '\\') {
 				get();
 				ch = get();
 				if (oneOf(ch, until) && ch == '\n') processContinuingLine(result);
@@ -309,7 +323,9 @@
 	}
 
 	void setOption(const std::string& uri, const std::string& value) override {
-		if (uri == option::TrimContinuingLines) trimLeadingSpacesOnContinuingLines = parseBoolean(value); // TODO: continuing lines modes (enum), not just boolean
+		if (uri == option::AllowLineContinuationWithEscaping) allowLineContinuationsWithEscaping = parseBoolean(value);
+		else if (uri == option::AllowLineContinuationWithSpace) allowLineContinuationsWithSpace = parseBoolean(value);
+		else if (uri == option::TrimContinuingLines) trimLeadingSpacesOnContinuingLines = parseBoolean(value);
 		else if (uri == option::AllowSections) allowSections = parseBoolean(value);
 		else if (uri == option::AllowSectionTags) allowSectionTags = parseBoolean(value);
 		else if (uri == option::AllowSubKeys) allowSubKeys = parseBoolean(value);
--- a/src/lib/uri.h	Sun Dec 13 17:34:26 2020 +0100
+++ b/src/lib/uri.h	Tue Sep 21 21:02:43 2021 +0200
@@ -25,6 +25,8 @@
 
 /** general options of the INI parser */
 namespace option {
+static const char* AllowLineContinuationWithEscaping = "allow-line-continuation-with-escaping";
+static const char* AllowLineContinuationWithSpace = "allow-line-continuation-with-space";
 static const char* TrimContinuingLines = "trim-continuing-lines";
 static const char* AllowSections = "allow-sections";
 static const char* AllowSectionTags = "allow-section-tags";