diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-11-11 07:49:06 +0100 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-11-11 07:49:06 +0100 |
commit | e6d7baf883ef3e75a9e5bd616a59df9405f63872 (patch) | |
tree | ec19062976da870780c50bc47056c0ab74c733eb | |
parent | ef8196da650f70758e1366cb7be1a799f1455f8e (diff) | |
download | sciteco-e6d7baf883ef3e75a9e5bd616a59df9405f63872.tar.gz |
added <n>O...$ GOTO command
-rw-r--r-- | goto.cpp | 33 | ||||
-rw-r--r-- | goto.h | 8 | ||||
-rw-r--r-- | parser.cpp | 1 |
3 files changed, 40 insertions, 2 deletions
@@ -4,13 +4,15 @@ #include <glib/gprintf.h> #include "sciteco.h" +#include "expressions.h" #include "parser.h" #include "undo.h" #include "rbtree.h" #include "goto.h" namespace States { - StateLabel label; + StateLabel label; + StateGotoCmd gotocmd; } static gchar *skip_label = NULL; @@ -199,3 +201,32 @@ StateLabel::custom(gchar chr) return this; } + +State * +StateGotoCmd::done(const gchar *str) +{ + gint64 value; + gchar **labels; + + BEGIN_EXEC(&States::start); + + value = expressions.pop_num_calc(); + labels = g_strsplit(str, ",", -1); + + if (value > 0 && value <= g_strv_length(labels) && *labels[value-1]) { + gint pc = table.find(labels[value-1]); + + if (pc >= 0) { + macro_pc = pc; + } else { + /* skip till label is defined */ + undo.push_str(skip_label); + skip_label = g_strdup(labels[value-1]); + undo.push_var<Mode>(mode); + mode = MODE_PARSE_ONLY; + } + } + + g_strfreev(labels); + return &States::start; +} @@ -18,8 +18,14 @@ private: State *custom(gchar chr); }; +class StateGotoCmd : public StateExpectString { +private: + State *done(const gchar *str); +}; + namespace States { - extern StateLabel label; + extern StateLabel label; + extern StateGotoCmd gotocmd; } void goto_table_clear(void); @@ -200,6 +200,7 @@ StateStart::StateStart() : State() init(" \f\r\n\v"); transitions['!'] = &States::label; + transitions['O'] = &States::gotocmd; transitions['^'] = &States::control; transitions['F'] = &States::flowcommand; transitions['"'] = &States::condcommand; |