blob: be722496e3642a89d4a4110723113a202711ce58 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
#ifndef __PARSER_H
#define __PARSER_H
#include <glib.h>
#include <glib/gprintf.h>
#include "sciteco.h"
class State {
protected:
/* static transitions */
State *transitions[MAX_TRANSITIONS];
inline void
init(const gchar *chars, State &state)
{
while (*chars)
transitions[(int)*chars++] = &state;
}
inline void
init(const gchar *chars)
{
init(chars, *this);
}
public:
State();
static bool input(gchar chr);
State *get_next_state(gchar chr);
protected:
static bool eval_colon(void);
virtual State *
custom(gchar chr)
{
return NULL;
}
};
/*
* Super-class for states accepting string arguments
* Opaquely cares about alternative-escape characters,
* string building commands and accumulation into a string
*/
class StateExpectString : public State {
public:
StateExpectString() : State() {}
private:
State *custom(gchar chr);
protected:
virtual void initial(void) {}
virtual void process(const gchar *str, gint new_chars) {}
virtual State *done(const gchar *str) = 0;
};
class QRegister;
/*
* Super class for states accepting Q-Register specifications
*/
class StateExpectQReg : public State {
public:
StateExpectQReg();
private:
State *custom(gchar chr);
protected:
/*
* FIXME: would be nice to pass reg as reference, but there are
* circular header dependencies...
*/
virtual State *got_register(QRegister *reg) = 0;
};
class StateStart : public State {
public:
StateStart();
private:
void move(gint64 n);
void move_lines(gint64 n);
State *custom(gchar chr);
};
class StateControl : public State {
public:
StateControl();
private:
State *custom(gchar chr);
};
class StateECommand : public State {
public:
StateECommand();
private:
State *custom(gchar chr);
};
class StateInsert : public StateExpectString {
private:
void initial(void);
void process(const gchar *str, gint new_chars);
State *done(const gchar *str);
};
extern gint macro_pc;
namespace States {
extern StateStart start;
extern StateControl control;
extern StateECommand ecommand;
extern StateInsert insert;
extern State *current;
}
extern enum Mode {
MODE_NORMAL = 0,
MODE_PARSE_ONLY
} mode;
#define BEGIN_EXEC(STATE) G_STMT_START { \
if (mode != MODE_NORMAL) \
return STATE; \
} G_STMT_END
extern gchar *strings[2];
extern gchar escape_char;
bool macro_execute(const gchar *macro);
#endif
|