KVIrc 5.2.6
Developer APIs
KviKvsParser.h
Go to the documentation of this file.
1#ifndef _KVI_KVS_PARSER_H_
2#define _KVI_KVS_PARSER_H_
3//=============================================================================
4//
5// File : KviKvsParser.h
6// Creation date : Thu 25 Sep 2003 05.12 CEST by Szymon Stefanek
7//
8// This file is part of the KVIrc IRC client distribution
9// Copyright (C) 2003-2010 Szymon Stefanek (pragma at kvirc dot net)
10//
11// This program is FREE software. You can redistribute it and/or
12// modify it under the terms of the GNU General Public License
13// as published by the Free Software Foundation; either version 2
14// of the License, or (at your option) any later version.
15//
16// This program is distributed in the HOPE that it will be USEFUL,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19// See the GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program. If not, write to the Free Software Foundation,
23// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24//
25//=============================================================================
26
27#include "kvi_settings.h"
28#include "KviQString.h"
29#include "KviPointerList.h"
30#include "KviPointerHashTable.h"
31
32class KviKvsScript;
33class KviKvsKernel;
34class KviWindow;
35class KviKvsTreeNode;
42class KviKvsTreeNodeVariableReference;
51
52// This is an ONE-TIME parser used by KviKvsScript
53
55{
56 friend class KviKvsKernel;
57
58public:
59 KviKvsParser(KviKvsScript * pScript, KviWindow * pOutputWindow);
61
62private:
63 const QChar * m_pBuffer = nullptr; // the local pointer to the beginning of the buffer
64 const QChar * m_ptr = nullptr; // the parsing pointer
65 // parsing state
66 KviPointerHashTable<QString, QString> * m_pGlobals; // the dict of the vars declared with global in this script
67 int m_iFlags = 0; // the current parsing flags
68 bool m_bError = false; // error(..) was called ?
69 // this stuff is used only for reporting errors and warnings
70 KviKvsScript * m_pScript; // parent script
71 KviWindow * m_pWindow; // output window
72public: // public interface
73 enum Flags
74 {
77 };
78 // was there an error ?
79 bool error() const { return m_bError; };
80 // parses the buffer pointed by pBuffer and returns
81 // a syntax tree or 0 in case of failure
82 // if the parsing fails, the error code can be retrieved by calling error()
83 KviKvsTreeNodeInstruction * parse(const QChar * pBuffer, int iFlags = 0);
84 KviKvsTreeNodeInstruction * parseAsExpression(const QChar * pBuffer, int iFlags = 0);
85 KviKvsTreeNodeInstruction * parseAsParameter(const QChar * pBuffer, int iFlags = 0);
86
87private: // parsing helpers
88 // generic
89 void skipSpaces(); // skips only spaces and tabs (eventually with \‍)
90 bool skipSpacesAndNewlines(); // skips space and newlines
91 void skipToNextLine(); // skips up to a new line
92 // dedicated
94 // dedicated to parseSpecialCommandFor() : in KviKvsParser_specialCommands.cpp
96 // error handlers
97 void error(const QChar * pLocation, QString szMsgFmt, ...);
98 void warning(const QChar * pLocation, QString szMsgFmt, ...);
99 void errorBadChar(const QChar * pLocation, char cExpected, const char * szCommandName);
100
101protected:
102 // this is called by KviKvsKernel to register the parsing routines
103 static void init();
104
105private:
106 // returns nullptr only in case of error
107 // starts on the first char of a buffer
108 // stops at the first null char encountered
110 // may return nullptr (empty instruction), check error() for error conditions
111 // starts on the first character of an instruction
112 // if the first char is ';' '\n' or null it just returns nullptr without error
113 // stops after the ending char of the instruction
115 // may return nullptr (empty block), check error() for error conditions
116 // starts at the leading '{' of the block
117 // stops after the trailing '}' of the block
119 // returns nullptr only in case of error
120 // starts on the first character of the parameters
121 // ends after the end of the command
123 // returns nullptr only in case of error
124 // starts on the leading '(' or a ',' in the middle of the list
125 // ends after the trailing ')'
126 // if started in the middle of the list returns only the remaining
127 // parameters.
130 // returns nullptr in case of error or if it starts on a terminating character (null parameter)
131 // check error() to see if there was an error condition (unless you already know that
132 // there was a valid first character)
133 // start on the first character of the parameter
134 // ends after the first character not included in the param (';','\n','\0',' ')
135 // If bPreferNumeric is true then when a single literal parameter
136 // is extracted an attempt to convert it to a numeric format is made.
137 // This optimizes assignments, self-sums etc...
138 KviKvsTreeNodeData * parseCommandParameter(bool bPreferNumeric = false);
139 // returns nullptr only in case of error
140 // start on the first character of the parameter
141 // ends after the first character not included in the param (')','\n','\0',',')
143 // returns nullptr only in case of error
144 // start on the first character of the parameter
145 // ends after the first character not included in the param (')','\n','\0')
147 // never returns nullptr
149 // never returns nullptr
151 // never returns nullptr
153 // returns nullptr only in case of error
154 // starts at the leading '"'
155 // ends after the trailing '"'
157 // never returns nullptr
159 // returns nullptr in case of error or of an empty switch list (check the error code!)
160 // starts at the leading '-' of the first switch
161 // ends after the last switch
163 // returns nullptr only in case of error
164 // starts at '%' or '$'
165 // and ends after the end of the data reference
166 // or just after the '%' or '$' if this was only a ConstandData (not a var or func)
168 // returns nullptr only in case of error
169 // starts at '%' or '$'
170 // ends after the end of the complete data reference (including scope operators!)
171 KviKvsTreeNodeData * parsePercentOrDollar(bool bInObjScope = false);
172 // returns nullptr only in case of error
173 // starts at '%'
174 // ends after the end of the structured data
175 KviKvsTreeNodeVariable * parsePercent(bool bInObjectScope = false);
176 // returns nullptr only in case of error
178 // never returns nullptr
180
181 //
182 // KviKvsParser_specialCommands.cpp
183 //
184
185 // return nullptr only in case of error
186 // starts at the leading '(' of the if command (after the switches)
187 // and stops after the end of the else block
188 // if the first character is not '(' then this function fails with an error
190 // always returns nullptr
191 // check error() for error conditions
192 // starts after the switches of the "global" keyword
193 // and stops at the end of the command
194 // if the first character is not '%' of a variable then this function fails with an error
196 // returns nullptr only in case of error
197 // starts at the leading '(' of the while command (after the switches)
198 // and stops after the end of the command block
199 // if the first character is not '(' then this function fails with an error
201 // returns nullptr only in case of error
202 // starts at the leading '(' of the while command (after the switches)
203 // and stops after the end of the command block
204 // if the first character is not '(' then this function fails with an error
206 // returns nullptr only in case of error
207 // and stops after the end of the break command
209 // returns nullptr only in case of error
210 // and jumps to the next iteration after the end of the continue command
212 // returns nullptr only in case of error
213 // and stops after the end of the for command block
215 // returns nullptr only in case of error
216 // and stops after the end of the foreach command block
218 // returns nullptr only in case of error
219 // and stops after the end of the switch command block
221 // returns nullptr only in case of error
222 // and stops after the end of the defpopup command block
224 // returns nullptr only in case of error
225 // and stops after the end of the defpopup command block
228 // returns nullptr only in case of error
229 // stops after the class command block
231 // returns nullptr only in case of error
232 // stops after the perl.end statement
234 // returns nullptr only in case of error
235 // stops after the perl.end statement
237 // returns nullptr only in case of error
238 // and stops after the end of the help command
240
241 //
242 // KviKvsParser_command.cpp
243 //
244
245 // may return nullptr (empty command), check error() for error conditions
246 // starts at the beginning of a command (can be non valid)
247 // ends after the ending char of the command
249
250 //
251 // KviKvsParser_comment.cpp
252 //
253
254 // always returns nullptr, and it CAN be an error!
255 // starts at the beginning of a comment (must be '#' or '/')
256 // ends after the ending char of the comment
258
259 //
260 // KviKvsParser_dollar.cpp
261 //
262
263 // returns nullptr only in case of error
264 // starts at '$'
265 // ends after the end of the function call
266 KviKvsTreeNodeData * parseDollar(bool bInObjScope = false);
267
268 // returns nullptr only in case of error
269 // starts at '@'
270 // ends after the end of the function call
271 KviKvsTreeNodeData * parseAt(bool bInObjScope = false);
272
273 //
274 // KviKvsParser_lside.cpp
275 //
276
277 // returns nullptr only in case of error
278 // returns after the command terminator
280 // returns nullptr only in case of error
281 // returns after the command terminator
283 // returns nullptr only in case of error
284 // returns after the command terminator
285 // If bPreferNumeric is propagated to parseCommandParameter() function
286 KviKvsTreeNodeData * parseOperationRightSide(bool bPreferNumeric = false);
287 // return nullptr only in case of error
288 // returns after the command terminator
292
293 //
294 // KviKvsParser_expression.cpp
295 //
296
297 // returns nullptr only in case of error
298 // starts AFTER the leading char of the expression
299 // ends after the first terminator found
300 KviKvsTreeNodeExpression * parseExpression(char terminator);
305
306 void report(bool bError, const QChar * pLocation, const QString & szMsgFmt, kvi_va_list va);
307};
308
309#endif
Pointer Hash Table.
C++ Template based double linked pointer list class.
Helper functions for the QString class.
Definition KviKvsKernel.h:71
KviKvsTreeNodeCommand * parseSpecialCommandPythonBegin()
KviKvsTreeNodeInstruction * parseVoidFunctionCallOrOperation()
Definition KviKvsParser_lside.cpp:923
KviPointerList< QString > * parseCommaSeparatedParameterListNoTree()
Definition KviKvsParser.cpp:2786
KviKvsTreeNodeExpressionBinaryOperator * parseExpressionBinaryOperator()
Definition KviKvsParser_expression.cpp:101
bool m_bError
Definition KviKvsParser.h:68
void warning(const QChar *pLocation, QString szMsgFmt,...)
Definition KviKvsParser.cpp:127
KviKvsTreeNodeData * parseHashKey()
KviKvsTreeNodeInstruction * parseInstructionBlock()
Definition KviKvsParser.cpp:2581
KviKvsTreeNodeData * parseParameterPercentOrDollar()
Definition KviKvsParser.cpp:2222
KviKvsTreeNodeVariable * parsePercent(bool bInObjectScope=false)
Definition KviKvsParser.cpp:2466
KviKvsTreeNodeData * parseDollar(bool bInObjScope=false)
Definition KviKvsParser_dollar.cpp:32
KviKvsTreeNodeConstantData * parseCommaSeparatedLiteralParameter()
KviKvsTreeNodeDataList * parseCommaSeparatedParameterList()
Definition KviKvsParser.cpp:2853
void skipToEndOfCStyleComment()
KviKvsTreeNodeCommand * parseSpecialCommandContinue()
Definition KviKvsParser_specialCommands.cpp:172
KviKvsTreeNodeConstantData * parseCommandLiteralParameter()
bool error() const
Definition KviKvsParser.h:79
KviKvsTreeNodeCommand * parseSpecialCommandHelp()
Definition KviKvsParser_specialCommands.cpp:2083
int m_iFlags
Definition KviKvsParser.h:67
KviKvsTreeNodeData * parseOperationRightSide(bool bPreferNumeric=false)
Definition KviKvsParser_lside.cpp:79
KviKvsTreeNodeData * parseAt(bool bInObjScope=false)
KviKvsTreeNodeExpression * parseExpressionOperandCore(char terminator)
Definition KviKvsParser_expression.cpp:344
KviKvsTreeNodeOperation * parseOperation()
Definition KviKvsParser_lside.cpp:681
KviPointerHashTable< QString, QString > * m_pGlobals
Definition KviKvsParser.h:66
KviKvsTreeNodeCommand * parseSpecialCommandClass()
Definition KviKvsParser_specialCommands.cpp:351
friend class KviKvsKernel
Definition KviKvsParser.h:56
KviKvsTreeNodeInstruction * parseInstruction()
Definition KviKvsParser.cpp:2536
KviKvsParser(KviKvsScript *pScript, KviWindow *pOutputWindow)
Definition KviKvsParser.cpp:36
KviWindow * m_pWindow
Definition KviKvsParser.h:71
KviKvsTreeNodeCommand * parseSpecialCommandPerlBegin()
KviKvsTreeNodeCommand * parseCommand()
Definition KviKvsParser_command.cpp:34
KviKvsTreeNodeCommand * parseSpecialCommandIf()
Definition KviKvsParser_specialCommands.cpp:867
KviKvsTreeNodeExpression * parseExpressionOperand(char terminator)
Definition KviKvsParser_expression.cpp:288
KviKvsTreeNodeConstantData * parseHashKeyLiteralParameter()
const QChar * m_ptr
Definition KviKvsParser.h:64
KviKvsTreeNodeCommand * parseSpecialCommandDefpopup()
Definition KviKvsParser_specialCommands.cpp:1958
KviKvsTreeNodeCommand * parseSpecialCommandBreak()
Definition KviKvsParser_specialCommands.cpp:140
KviKvsTreeNodeExpression * parseExpression(char terminator)
Definition KviKvsParser_expression.cpp:488
KviKvsTreeNodeData * parseCommaSeparatedParameter()
Definition KviKvsParser.cpp:3332
KviKvsTreeNodeSwitchList * parseCommandSwitchList()
Definition KviKvsParser.cpp:2644
KviKvsTreeNodeCommand * parseSpecialCommandUnset()
Definition KviKvsParser_specialCommands.cpp:202
KviKvsTreeNodeCommand * parseSpecialCommandForeach()
Definition KviKvsParser_specialCommands.cpp:1231
KviKvsTreeNodeData * parseStringParameter()
Definition KviKvsParser.cpp:3516
KviKvsTreeNodeData * parseBindingOperationParameter()
Definition KviKvsParser_lside.cpp:504
const QChar * m_pBuffer
Definition KviKvsParser.h:63
KviKvsTreeNodeConstantData * parseStringLiteralParameter()
void errorBadChar(const QChar *pLocation, char cExpected, const char *szCommandName)
Definition KviKvsParser.cpp:107
Flags
Definition KviKvsParser.h:74
@ Pedantic
Definition KviKvsParser.h:76
@ AssumeLocals
Definition KviKvsParser.h:75
void report(bool bError, const QChar *pLocation, const QString &szMsgFmt, kvi_va_list va)
Definition KviKvsParser.cpp:76
KviKvsTreeNodeCommand * parseSpecialCommandGlobal()
Definition KviKvsParser_specialCommands.cpp:278
KviKvsTreeNodeOperation * parseBindingOperation()
Definition KviKvsParser_lside.cpp:578
KviKvsScript * m_pScript
Definition KviKvsParser.h:70
KviKvsTreeNodeCommand * parseSpecialCommandWhile()
Definition KviKvsParser_specialCommands.cpp:652
KviKvsTreeNodeConstantData * parseSingleLiteralParameterInParenthesis()
KviKvsTreeNodeCommand * parseSpecialCommandSwitch()
Definition KviKvsParser_specialCommands.cpp:1350
KviKvsTreeNodeData * parseCommandParameter(bool bPreferNumeric=false)
Definition KviKvsParser.cpp:3603
KviKvsTreeNodeData * parsePercentOrDollar(bool bInObjScope=false)
Definition KviKvsParser.cpp:2252
bool skipToEndOfForControlBlock()
Definition KviKvsParser_specialCommands.cpp:1022
KviKvsTreeNodeData * parseSingleParameterInParenthesis()
Definition KviKvsParser.cpp:3423
KviKvsTreeNodeSpecialCommandDefpopupLabelPopup * parseSpecialCommandDefpopupLabelPopup()
Definition KviKvsParser_specialCommands.cpp:1668
KviKvsTreeNodeCommand * parseSpecialCommandDo()
Definition KviKvsParser_specialCommands.cpp:738
bool parseExpressionMightPointToOperator()
Definition KviKvsParser_expression.cpp:269
KviKvsTreeNodeInstruction * parseInstructionList()
Definition KviKvsParser.cpp:2175
KviKvsTreeNode * parseComment()
Definition KviKvsParser_comment.cpp:32
KviKvsTreeNodeCommand * parseSpecialCommandFor()
Definition KviKvsParser_specialCommands.cpp:1068
KviKvsTreeNodeDataList * parseCommandParameterList()
Definition KviKvsParser.cpp:2749
KviKvsTreeNodeConstantData * parseBindingOperationLiteralParameter()
The KVIrc Script class.
Definition KviKvsScript.h:60
Definition KviKvsTreeNodeCommand.h:35
Definition KviKvsTreeNodeConstantData.h:32
Definition KviKvsTreeNodeDataList.h:36
Definition KviKvsTreeNodeData.h:35
Definition KviKvsTreeNodeExpression.h:186
Definition KviKvsTreeNodeExpression.h:68
Definition KviKvsTreeNodeFunctionCall.h:32
Definition KviKvsTreeNodeInstructionBlock.h:36
Treenode class to handle instructions.
Definition KviKvsTreeNodeInstruction.h:43
Definition KviKvsTreeNodeOperation.h:35
Definition KviKvsTreeNodeSpecialCommandDefpopup.h:173
Definition KviKvsTreeNodeSpecialCommand.h:32
Definition KviKvsTreeNodeSwitchList.h:39
Definition KviKvsTreeNodeVariable.h:35
Treenode class.
Definition KviKvsTreeNodeBase.h:41
A fast pointer hash table implementation.
Definition KviPointerHashTable.h:450
A template double linked list of pointers.
Definition KviPointerList.h:371
Base class for all windows in KVIrc.
Definition KviWindow.h:75
This file contains compile time settings.
#define KVIRC_API
Definition kvi_settings.h:127
#define kvi_va_list
Definition kvi_stdarg.h:30
int init()
Definition winamp.cpp:118