-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcommandindex.h
More file actions
165 lines (145 loc) · 3.67 KB
/
commandindex.h
File metadata and controls
165 lines (145 loc) · 3.67 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#ifndef COMMANDINDEX_H
#define COMMANDINDEX_H
#include <QObject>
#include <QList>
#include <QMap>
#include <QStringList>
#include <QXmlStreamReader>
enum CommandType
{
CmdTypeCommand,
CmdTypeVariable,
CmdTypeOption,
CmdTypeConstant,
CmdTypeKeyword,
CmdTypeOperator
};
enum CommandParameterType
{
ParamTypeNone,
ParamTypeObject,
ParamTypeCommand,
ParamTypeCharacter,
ParamTypeFile,
ParamTypeFunction,
ParamTypeString,
ParamTypeBoolean,
ParamTypeTable,
ParamTypeMatrix,
ParamTypeExpression,
ParamTypeVariable,
ParamTypeInterval,
ParamTypeReal,
ParamTypeInteger,
ParamTypeComplex,
ParamTypeCycle,
ParamTypePermutation,
ParamTypeUnit,
ParamTypePolynomial,
ParamTypePoint,
ParamTypeLine,
ParamTypePlane,
ParamTypeCircle,
ParamTypeSegment,
ParamTypeGeometricObject,
ParamTypeGeometricObject2D,
ParamTypeGeometricObject3D,
ParamTypeOption,
ParamTypeEquation,
ParamTypeSequence,
ParamTypeList,
ParamTypeVector,
ParamTypeSet,
ParamTypeQuoted,
ParamTypeChoice,
ParamTypeElement,
ParamTypeEllipsis,
ParamTypeEmpty,
ParamTypeZero
};
enum ParameterStyle
{
ParamStyleNormal,
ParamStyleItalic,
ParamStyleBold,
ParamStyleMono
};
struct CommandParameter
{
CommandParameterType type;
bool optional;
bool explicite;
bool optionalLhs;
bool optionalRhs;
QList<int> domain;
int dimension;
CommandParameterType elementType;
CommandParameterType alternateType;
QString text;
QList<CommandParameter> children;
CommandParameter() { }
CommandParameter(const QString &name, const QXmlStreamAttributes &attributes);
QString format(ParameterStyle elementStyle = ParamStyleNormal);
bool isComposite();
bool isFixed();
bool isValid() { return type != ParamTypeNone; }
static CommandParameterType parseParameterName(const QString &name);
static QString toMono(const QString &text) { return QString("<font face=\"freemono\">%1</font>").arg(text); }
static QString formatText(const QString &text, ParameterStyle parameterStyle);
ParameterStyle style(bool isElement = false);
};
struct ReturnType
{
CommandParameterType type;
CommandParameterType subtype;
};
struct InputSyntax
{
QList<CommandParameter> parameters;
QList<ReturnType> returnTypes;
};
struct Reference
{
QString title;
QString source;
QString language;
};
struct Description
{
QString text;
QString language;
};
struct Command
{
CommandType type;
QStringList names;
QStringList categories;
QList<InputSyntax> syntaxes;
QList<Description> descriptions;
QStringList related;
QStringList examples;
QList<Reference> references;
QString description(const QString &lang) const;
};
class CommandIndex : public QObject
{
Q_OBJECT
QList<Command> commands;
static QString lastName;
static QString lastElement;
bool loadCommands();
QString parseHTMLBlock(QXmlStreamReader &reader);
public:
explicit CommandIndex(QObject *parent = 0);
int commandCount() { return commands.length(); }
const Command &commandAt(int index) { Q_ASSERT(index < commandCount()); return commands.at(index); }
static bool parseParameters(Command &cmd, QXmlStreamReader &reader);
static CommandParameter parseParameter(QXmlStreamReader &reader);
static QString paramTypeToString(CommandParameterType paramType, int mode);
static QString optionalNotice() { return tr("optional"); }
static QString orSeparator() { return tr("or"); }
static QString inSeparator() { return tr("in"); }
signals:
public slots:
};
#endif // COMMANDINDEX_H