aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/parser.h
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2014-11-11 15:09:21 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2014-11-11 15:09:21 +0100
commit4048ee8150cad5253fd6f0245c9a357484eac3f2 (patch)
tree2434df63c0766d6c2f8f8294af9104697f4abae2 /src/parser.h
parent7206f6d1249da0dd8e879d0c0b26185fc6ef89d9 (diff)
downloadsciteco-4048ee8150cad5253fd6f0245c9a357484eac3f2.tar.gz
refactored SciTECO runtime errors: moved from parser.cpp to error.cpp
* the GError expection has been renamed to GlibError, to avoid nameclashes when working from the SciTECO namespace
Diffstat (limited to 'src/parser.h')
-rw-r--r--src/parser.h191
1 files changed, 2 insertions, 189 deletions
diff --git a/src/parser.h b/src/parser.h
index 3505a0c..0c94ba0 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -18,13 +18,10 @@
#ifndef __PARSER_H
#define __PARSER_H
-#include <exception>
-#include <typeinfo>
-
#include <glib.h>
-#include <glib/gprintf.h>
#include "undo.h"
+#include "error.h"
#include "sciteco.h"
namespace SciTECO {
@@ -32,191 +29,7 @@ namespace SciTECO {
/* TECO uses only lower 7 bits for commands */
#define MAX_TRANSITIONS 127
-/* thrown as exception, executed at cmdline macro level */
-class ReplaceCmdline {
-public:
- gchar *new_cmdline;
- gint pos;
-
- ReplaceCmdline();
-};
-
class State {
-public:
- class Error {
- gchar *description;
- GSList *frames;
-
- public:
- gint pos;
- gint line, column;
-
- class Frame {
- public:
- gint pos;
- gint line, column;
-
- virtual Frame *copy() const = 0;
- virtual ~Frame() {}
-
- virtual void display(gint nr) = 0;
- };
-
- class QRegFrame : public Frame {
- gchar *name;
-
- public:
- QRegFrame(const gchar *_name)
- : name(g_strdup(_name)) {}
-
- Frame *
- copy() const
- {
- Frame *frame = new QRegFrame(name);
-
- frame->pos = pos;
- frame->line = line;
- frame->column = column;
-
- return frame;
- }
-
- ~QRegFrame()
- {
- g_free(name);
- }
-
- void
- display(gint nr)
- {
- interface.msg(Interface::MSG_INFO,
- "#%d in Q-Register \"%s\" at %d (%d:%d)",
- nr, name, pos, line, column);
- }
- };
-
- class FileFrame : public Frame {
- gchar *name;
-
- public:
- FileFrame(const gchar *_name)
- : name(g_strdup(_name)) {}
-
- Frame *
- copy() const
- {
- Frame *frame = new FileFrame(name);
-
- frame->pos = pos;
- frame->line = line;
- frame->column = column;
-
- return frame;
- }
-
- ~FileFrame()
- {
- g_free(name);
- }
-
- void
- display(gint nr)
- {
- interface.msg(Interface::MSG_INFO,
- "#%d in file \"%s\" at %d (%d:%d)",
- nr, name, pos, line, column);
- }
- };
-
- class ToplevelFrame : public Frame {
- public:
- Frame *
- copy() const
- {
- Frame *frame = new ToplevelFrame;
-
- frame->pos = pos;
- frame->line = line;
- frame->column = column;
-
- return frame;
- }
-
- void
- display(gint nr)
- {
- interface.msg(Interface::MSG_INFO,
- "#%d in toplevel macro at %d (%d:%d)",
- nr, pos, line, column);
- }
- };
-
- Error(const gchar *fmt, ...) G_GNUC_PRINTF(2, 3);
- Error(const Error &inst);
- ~Error();
-
- void add_frame(Frame *frame);
-
- void display_short(void);
- void display_full(void);
- };
-
- class StdError : public Error {
- public:
- StdError(const gchar *type, const std::exception &error)
- : Error("%s: %s", type, error.what()) {}
- StdError(const std::exception &error)
- : Error("%s: %s", typeid(error).name(), error.what()) {}
- };
-
- class GError : public Error {
- public:
- GError(const ::GError *gerror)
- : Error("%s", gerror->message) {}
- };
-
- class SyntaxError : public Error {
- public:
- SyntaxError(gchar chr)
- : 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)
- : Error("Attempt to move pointer off page with <%s>",
- cmd) {}
- MoveError(gchar cmd)
- : Error("Attempt to move pointer off page with <%c>",
- cmd) {}
- };
-
- class RangeError : public Error {
- public:
- RangeError(const gchar *cmd)
- : Error("Invalid range specified for <%s>", cmd) {}
- RangeError(gchar cmd)
- : Error("Invalid range specified for <%c>", cmd) {}
- };
-
- class InvalidQRegError : public Error {
- public:
- InvalidQRegError(const gchar *name, bool local = false)
- : Error("Invalid Q-Register \"%s%s\"",
- local ? "." : "", name) {}
- InvalidQRegError(gchar name, bool local = false)
- : Error("Invalid Q-Register \"%s%c\"",
- local ? "." : "", name) {}
- };
-
protected:
/* static transitions */
State *transitions[MAX_TRANSITIONS];
@@ -471,7 +284,7 @@ extern gchar escape_char;
namespace Execute {
void step(const gchar *macro, gint stop_pos)
- throw (State::Error, ReplaceCmdline);
+ throw (Error, ReplaceCmdline);
void macro(const gchar *macro, bool locals = true);
void file(const gchar *filename, bool locals = true);
}