From b804417f36ef398f1223e439fd5ac9f2ade046eb Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Mon, 19 Nov 2012 21:43:39 +0100 Subject: support special "{" alternate escape character: is only terminated by a matching *balanced* "}" this eases writing nested macros --- parser.cpp | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'parser.cpp') diff --git a/parser.cpp b/parser.cpp index b75e3bf..89486a1 100644 --- a/parser.cpp +++ b/parser.cpp @@ -259,24 +259,38 @@ StateExpectString::custom(gchar chr) throw (Error) * String termination handling */ if (Modifiers::at) { - undo.push_var(Modifiers::at); + undo.push_var(Modifiers::at); Modifiers::at = false; - undo.push_var(escape_char); + undo.push_var(escape_char); escape_char = g_ascii_toupper(chr); return this; } - if (g_ascii_toupper(chr) == escape_char) { + if (escape_char == '{') { + switch (chr) { + case '{': + undo.push_var(nesting); + nesting++; + break; + case '}': + undo.push_var(nesting); + nesting--; + break; + } + } else if (g_ascii_toupper(chr) == escape_char) { + undo.push_var(nesting); + nesting--; + } + + if (!nesting) { + State *next; gchar *string = strings[0]; undo.push_str(strings[0]); strings[0] = NULL; - - State *next = done(string ? : ""); - g_free(string); - undo.push_var(escape_char); escape_char = '\x1B'; + nesting = 1; if (string_building) { undo.push_var(machine); @@ -285,6 +299,8 @@ StateExpectString::custom(gchar chr) throw (Error) machine.toctl = false; } + next = done(string ? : ""); + g_free(string); return next; } -- cgit v1.2.3