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 +++++++++++++++++++++++------- parser.h | 4 +++- teco.ini | 4 ++-- 3 files changed, 28 insertions(+), 10 deletions(-) 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; } diff --git a/parser.h b/parser.h index ba3a632..a704c83 100644 --- a/parser.h +++ b/parser.h @@ -110,11 +110,13 @@ class StateExpectString : public State { mode(MODE_NORMAL), toctl(false) {} } machine; + gint nesting; + bool string_building; public: StateExpectString(bool _building = true) - : State(), string_building(_building) {} + : State(), nesting(1), string_building(_building) {} private: gchar *machine_input(gchar key) throw (Error); diff --git a/teco.ini b/teco.ini index e7c1a42..97ae766 100755 --- a/teco.ini +++ b/teco.ini @@ -2,7 +2,7 @@ ! TECO.INI ! -@0/ +@0{ Oadd,edit,close,quit !add! [f[r[0[1[2 @@ -42,7 +42,7 @@ !quit! ! fall through ! -!end!/ +!end!} ED#32ED ! open all files specified on the commandline ! -- cgit v1.2.3