diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-11-11 07:24:04 +0100 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-11-11 07:24:04 +0100 |
commit | ef8196da650f70758e1366cb7be1a799f1455f8e (patch) | |
tree | 7ac2b2e2e8e88aa80386b21a2c8975b0a06d2827 | |
parent | 1962b1ff6571d3ed161abc44c7eb90cae7e85a1c (diff) | |
download | sciteco-ef8196da650f70758e1366cb7be1a799f1455f8e.tar.gz |
implemented conditionals (<n>"x...|...')
-rw-r--r-- | parser.cpp | 82 | ||||
-rw-r--r-- | parser.h | 9 |
2 files changed, 91 insertions, 0 deletions
@@ -18,6 +18,7 @@ namespace States { StateStart start; StateControl control; StateFlowCommand flowcommand; + StateCondCommand condcommand; StateECommand ecommand; StateInsert insert; @@ -201,6 +202,7 @@ StateStart::StateStart() : State() transitions['!'] = &States::label; transitions['^'] = &States::control; transitions['F'] = &States::flowcommand; + transitions['"'] = &States::condcommand; transitions['E'] = &States::ecommand; transitions['I'] = &States::insert; transitions['Q'] = &States::getqreginteger; @@ -592,6 +594,86 @@ StateFlowCommand::custom(gchar chr) return &States::start; } +StateCondCommand::StateCondCommand() : State() +{ + transitions['\0'] = this; +} + +State * +StateCondCommand::custom(gchar chr) +{ + gint64 value; + bool result; + + if (mode == MODE_PARSE_ONLY) { + undo.push_var<gint>(nest_level); + nest_level++; + } else { + value = expressions.pop_num_calc(); + } + + switch (g_ascii_toupper(chr)) { + case 'A': + BEGIN_EXEC(&States::start); + result = g_ascii_isalpha((gchar)value); + break; + case 'C': + BEGIN_EXEC(&States::start); + /* FIXME */ + result = g_ascii_isalnum((gchar)value); + break; + case 'D': + BEGIN_EXEC(&States::start); + result = g_ascii_isdigit((gchar)value); + break; + case 'E': + case 'F': + case 'U': + case '=': + BEGIN_EXEC(&States::start); + result = value == 0; + break; + case 'G': + case '>': + BEGIN_EXEC(&States::start); + result = value > 0; + break; + case 'L': + case 'S': + case 'T': + case '<': + BEGIN_EXEC(&States::start); + result = value < 0; + break; + case 'N': + BEGIN_EXEC(&States::start); + result = value != 0; + break; + case 'R': + BEGIN_EXEC(&States::start); + result = g_ascii_isalnum((gchar)value); + break; + case 'V': + BEGIN_EXEC(&States::start); + result = g_ascii_islower((gchar)value); + break; + case 'W': + BEGIN_EXEC(&States::start); + result = g_ascii_isupper((gchar)value); + break; + default: + return NULL; + } + + if (!result) { + /* skip to ELSE-part or end of conditional */ + undo.push_var<Mode>(mode); + mode = MODE_PARSE_ONLY; + } + + return &States::start; +} + StateControl::StateControl() : State() { transitions['\0'] = this; @@ -104,6 +104,14 @@ private: State *custom(gchar chr); }; +class StateCondCommand : public State { +public: + StateCondCommand(); + +private: + State *custom(gchar chr); +}; + class StateECommand : public State { public: StateECommand(); @@ -125,6 +133,7 @@ namespace States { extern StateStart start; extern StateControl control; extern StateFlowCommand flowcommand; + extern StateCondCommand condcommand; extern StateECommand ecommand; extern StateInsert insert; |