aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2012-11-19 21:43:39 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2012-11-20 06:07:33 +0100
commitb804417f36ef398f1223e439fd5ac9f2ade046eb (patch)
tree5d19cde8c5f6bfe7c3e839661b90ee1f4f0bbca4
parent3db5b1a40bf6b503b26827355f40033b1047a123 (diff)
downloadsciteco-b804417f36ef398f1223e439fd5ac9f2ade046eb.tar.gz
support special "{" alternate escape character: is only terminated by a matching *balanced* "}"
this eases writing nested macros
-rw-r--r--parser.cpp30
-rw-r--r--parser.h4
-rwxr-xr-xteco.ini4
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<bool>(Modifiers::at);
+ undo.push_var(Modifiers::at);
Modifiers::at = false;
- undo.push_var<gchar>(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 !