aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2014-11-09 22:56:50 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2014-11-09 22:56:50 +0100
commitfa128671e2c4115f79200e69bde21a1bd484cad9 (patch)
treee599cd8fe4f4f607f5d55abd0367352fa95ce273
parent01a4211b9bc358a80b306a720fad488585422b8b (diff)
downloadsciteco-fa128671e2c4115f79200e69bde21a1bd484cad9.tar.gz
revised U command: fail if no argument is provided
* there is no reasonable default value for U * omitting the parameter for U might be a frequent programming error * U can be colon-modified now, in which case it may be used * to check for the presence of arguments in macros
-rw-r--r--lib/fnkeys.tes4
-rw-r--r--src/parser.h8
-rw-r--r--src/qregisters.cpp27
3 files changed, 32 insertions, 7 deletions
diff --git a/lib/fnkeys.tes b/lib/fnkeys.tes
index c40be40..94c886d 100644
--- a/lib/fnkeys.tes
+++ b/lib/fnkeys.tes
@@ -18,11 +18,11 @@
@[DC]{}
@[HOME]{(-(.-(0L.))M#c}
@[END]{(-(.-(:L"S.-1|Z'))M#c}
-@[NPAGE]{(-(.-(M#p.))M#c}
+@[NPAGE]{(-(.-(1M#p.))M#c}
@[PPAGE]{(-(.-(-M#p.))M#c}
@[LEFT]{(-M#c}
@[SLEFT]{(-(.--W.)M#c}
-@[RIGHT]{(M#c}
+@[RIGHT]{(1M#c}
@[SRIGHT]{(-(.-W.)M#c}
@[UP]{(-(.-B.)M#c}
@[DOWN]{(-(.-L.)M#c}
diff --git a/src/parser.h b/src/parser.h
index c19ef14..9cc8f07 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -179,6 +179,14 @@ public:
: Error("Syntax error \"%c\" (%d)", chr, chr) {}
};
+ class ArgExpectedError : public Error {
+ public:
+ ArgExpectedError(const gchar *cmd)
+ : Error("Argument expected for <%s>", cmd) {}
+ ArgExpectedError(gchar cmd)
+ : Error("Argument expected for <%c>", cmd) {}
+ };
+
class MoveError : public Error {
public:
MoveError(const gchar *cmd)
diff --git a/src/qregisters.cpp b/src/qregisters.cpp
index 1a7ba34..115cd36 100644
--- a/src/qregisters.cpp
+++ b/src/qregisters.cpp
@@ -617,21 +617,38 @@ StateGetQRegInteger::got_register(QRegister &reg)
}
/*$
- * [n]Uq -- Set Q-Register integer
+ * nUq -- Set Q-Register integer
+ * -Uq
+ * [n]:Uq -> Success|Failure
*
* Sets the integer-part of Q-Register <q> to <n>.
- * If <n> is omitted, the sign prefix is implied.
+ * \(lq-U\(rq is equivalent to \(lq-1U\(rq, otherwise
+ * the command fails if <n> is missing.
+ *
+ * If the command is colon-modified, it returns a success
+ * boolean if <n> or \(lq-\(rq is given.
+ * Otherwise it returns a failure boolean and does not
+ * modify <q>.
*
* The register is defined if it does not exist.
*/
-/** @bug perhaps it's better to imply 0! */
State *
StateSetQRegInteger::got_register(QRegister &reg)
{
BEGIN_EXEC(&States::start);
- reg.undo_set_integer();
- reg.set_integer(expressions.pop_num_calc());
+ expressions.eval();
+ if (expressions.args() || expressions.num_sign < 0) {
+ reg.undo_set_integer();
+ reg.set_integer(expressions.pop_num_calc());
+
+ if (eval_colon())
+ expressions.push(SUCCESS);
+ } else if (eval_colon()) {
+ expressions.push(FAILURE);
+ } else {
+ throw ArgExpectedError('U');
+ }
return &States::start;
}