Doxygen
Loading...
Searching...
No Matches
sqlcode.l
Go to the documentation of this file.
-1/******************************************************************************
2 *
3 * Copyright (C) 1997-2020 by Dimitri van Heesch.
4 *
5 * Permission to use, copy, modify, and distribute this software and its
6 * documentation under the terms of the GNU General Public License is hereby
7 * granted. No representations are made about the suitability of this software
8 * for any purpose. It is provided "as is" without express or implied warranty.
9 * See the GNU General Public License for more details.
10 *
11 * Documents produced by Doxygen are derivative works derived from the
12 * input used in their production; they are not affected by this license.
13 *
14 */
13
14%option never-interactive
15%option prefix="sqlcodeYY"
16%option noyywrap
17%option nounput
18%option reentrant
19%option extra-type="struct sqlcodeYY_state *"
20%top{
21#include <stdint.h>
22// forward declare yyscan_t to improve type safety
23#define YY_TYPEDEF_YY_SCANNER_T
24struct yyguts_t;
25typedef yyguts_t *yyscan_t;
yyguts_t * yyscan_t
Definition code.l:24
26}
28%{
29
30#include <stdio.h>
31
32#include "sqlcode.h"
33
34#include "entry.h"
35#include "doxygen.h"
36#include "outputlist.h"
37#include "util.h"
38#include "membername.h"
39#include "searchindex.h"
40#include "config.h"
41#include "filedef.h"
42#include "tooltip.h"
43#include "message.h"
44#include "debug.h"
45
46#define YY_NEVER_INTERACTIVE 1
47#define YY_NO_INPUT 1
48#define YY_NO_UNISTD_H 1
51{
52 OutputCodeList * code = nullptr;
53 const char *inputString = nullptr; //!< the code fragment as text
54 int inputPosition = 0; //!< read offset during parsing
56 int inputLines = 0; //!< number of line in the code fragment
57 int yyLineNr = 1; //!< current line number
58 bool insideCodeLine = false;
59 const Definition *searchCtx = nullptr;
61 bool stripCodeComments = true;
62 bool exampleBlock = false;
66 std::unique_ptr<FileDef> exampleFileDef;
67 const FileDef *sourceFileDef = nullptr;
68 const Definition *currentDefinition = nullptr;
69 const MemberDef *currentMemberDef = nullptr;
70 bool includeCodeFragment = false;
71 const char *currentFontClass = nullptr;
72};
74[[maybe_unused]] static const char *stateToString(int state);
75
76static void setCurrentDoc(yyscan_t yyscanner,const QCString &anchor);
77static void startCodeLine(yyscan_t yyscanner);
78static void endFontClass(yyscan_t yyscanner);
79static void endCodeLine(yyscan_t yyscanner);
80static void nextCodeLine(yyscan_t yyscanner);
81static void codifyLines(yyscan_t yyscanner,const char *text);
82static void startFontClass(yyscan_t yyscanner,const char *s);
83static int countLines(yyscan_t yyscanner);
84static int yyread(yyscan_t yyscanner,char *buf,int max_size);
85
86#undef YY_INPUT
87#define YY_INPUT(buf,result,max_size) result=yyread(yyscanner,buf,max_size);
88
89// otherwise the filename would be the name of the converted file (*.cpp instead of *.l)
90static inline const char *getLexerFILE() {return __FILE__;}
91#include "doxygen_lex.h"
The common base class of all entity definitions found in the sources.
Definition definition.h:76
A model of a file symbol.
Definition filedef.h:99
A model of a class/file/namespace member symbol.
Definition memberdef.h:48
Class representing a list of different code generators.
Definition outputlist.h:165
This is an alternative implementation of QCString.
Definition qcstring.h:101
static void endCodeLine(yyscan_t yyscanner)
Definition code.l:2478
static void nextCodeLine(yyscan_t yyscanner)
Definition code.l:2487
static void startCodeLine(yyscan_t yyscanner)
Definition code.l:2409
static void codifyLines(yyscan_t yyscanner, const QCString &text)
Definition code.l:2505
static int yyread(yyscan_t yyscanner, char *buf, int max_size)
Definition code.l:3971
static int countLines(yyscan_t yyscanner)
Definition code.l:3462
static const char * stateToString(int state)
static void startFontClass(yyscan_t yyscanner, const char *s, bool specialComment=false)
Definition code.l:3495
static void endFontClass(yyscan_t yyscanner, bool specialComment=false)
Definition code.l:3480
static const char * getLexerFILE()
Definition code.l:263
static void setCurrentDoc(yyscan_t yyscanner, const QCString &anchor)
Definition code.l:2277
Web server based search engine.
const char * currentFontClass
Definition sqlcode.l:73
const Definition * searchCtx
Definition sqlcode.l:61
bool includeCodeFragment
Definition sqlcode.l:72
bool exampleBlock
Definition sqlcode.l:64
const char * inputString
the code fragment as text
Definition sqlcode.l:55
QCString fileName
Definition sqlcode.l:57
const MemberDef * currentMemberDef
Definition sqlcode.l:71
bool insideCodeLine
Definition sqlcode.l:60
QCString classScope
Definition sqlcode.l:66
int yyLineNr
current line number
Definition sqlcode.l:59
QCString exampleName
Definition sqlcode.l:65
OutputCodeList * code
Definition sqlcode.l:54
int inputLines
number of line in the code fragment
Definition sqlcode.l:58
const FileDef * sourceFileDef
Definition sqlcode.l:69
std::unique_ptr< FileDef > exampleFileDef
Definition sqlcode.l:68
int inputPosition
read offset during parsing
Definition sqlcode.l:56
bool stripCodeComments
Definition sqlcode.l:63
const Definition * currentDefinition
Definition sqlcode.l:70
A bunch of utility functions.
93%}
94
95nl (\r\n|\r|\n)
96idchar [A-Za-z0-9\-_]+
97keywords1 ("ADD"|"ALL"|"ALLOCATE"|"ALTER"|"AND"|"ANY"|"ARE"|"AS"|"ASENSITIVE"|"ASYMMETRIC"|"AT"|"ATOMIC"|"AUTHORIZATION"|"BETWEEN"|"BOTH"|"BY"|"CALL"|"CALLED"|"CASCADED"|"CAST")
98keywords2 ("CHECK"|"CLOSE"|"COLLATE"|"COLUMN"|"COMMIT"|"CONNECT"|"CONSTRAINT"|"CONTINUE"|"CORRESPONDING"|"CREATE"|"CROSS"|"CUBE"|"CURRENT"|"CURRENT_DATE"|"CURRENT_DEFAULT_TRANSFORM_GROUP")
99keywords3 ("CURRENT_PATH"|"CURRENT_ROLE"|"CURRENT_TIME"|"CURRENT_TIMESTAMP"|"CURRENT_TRANSFORM_GROUP_FOR_TYPE"|"CURRENT_USER")
100keywords4 ("CURSOR"|"CYCLE"|"DAY"|"DEALLOCATE"|"DECLARE"|"DEFAULT"|"DELETE"|"DEREF"|"DESCRIBE"|"DETERMINISTIC"|"DISCONNECT"|"DISTINCT"|"DROP"|"DYNAMIC")
101keywords5 ("EACH"|"ELEMENT"|"END-EXEC"|"ESCAPE"|"EXCEPT"|"EXEC"|"EXECUTE"|"EXISTS"|"EXTERNAL"|"FETCH"|"FILTER"|"FOR"|"FOREIGN"|"FREE"|"FROM"|"FULL"|"FUNCTION")
102keywords6 ("GET"|"GLOBAL"|"GRANT"|"GROUP"|"GROUPING"|"HAVING"|"HOLD"|"HOUR"|"IDENTITY"|"IMMEDIATE"|"IN"|"INDICATOR"|"INNER"|"INOUT"|"INPUT"|"INSENSITIVE"|"INSERT"|"INTERSECT")
103keywords7 ("INTERVAL"|"INTO"|"IS"|"ISOLATION"|"JOIN"|"LANGUAGE"|"LARGE"|"LATERAL"|"LEADING"|"LEFT"|"LIKE"|"LOCAL"|"LOCALTIME"|"LOCALTIMESTAMP"|"MATCH"|"MEMBER"|"MERGE"|"METHOD"|"MINUTE")
104keywords8 ("MODIFIES"|"MODULE"|"MONTH"|"MULTISET"|"NATIONAL"|"NATURAL"|"NEW"|"NO"|"NONE"|"NOT"|"OF"|"OLD"|"ON"|"ONLY"|"OPEN"|"OR"|"ORDER"|"OUT"|"OUTER"|"OUTPUT")
105keywords9 ("OVER"|"OVERLAPS"|"PARAMETER"|"PARTITION"|"PRECISION"|"PREPARE"|"PRIMARY"|"PROCEDURE"|"RANGE"|"READS"|"RECURSIVE"|"REF"|"REFERENCES"|"REFERENCING"|"REGR_AVGX"|"REGR_AVGY")
106keywords10 ("REGR_COUNT"|"REGR_INTERCEPT"|"REGR_R2"|"REGR_SLOPE"|"REGR_SXX"|"REGR_SXY"|"REGR_SYY"|"RELEASE"|"RESULT"|"RETURN"|"RETURNS"|"REVOKE"|"RIGHT"|"ROLLBACK"|"ROLLUP"|"ROW"|"ROWS"|"SAVEPOINT")
107keywords11 ("SCROLL"|"SEARCH"|"SECOND"|"SELECT"|"SENSITIVE"|"SESSION_USER"|"SET"|"SIMILAR"|"SOME"|"SPECIFIC"|"SPECIFICTYPE"|"SQL"|"SQLEXCEPTION"|"SQLSTATE"|"SQLWARNING"|"START"|"STATIC")
108keywords12 ("SUBMULTISET"|"SYMMETRIC"|"SYSTEM"|"SYSTEM_USER"|"TABLE"|"THEN"|"TIMEZONE_HOUR"|"TIMEZONE_MINUTE"|"TO"|"TRAILING"|"TRANSLATION"|"TREAT"|"TRIGGER"|"UESCAPE"|"UNION")
109keywords13 ("UNIQUE"|"UNNEST"|"UPDATE"|"UPPER"|"USER"|"USING"|"VALUE"|"VALUES"|"VAR_POP"|"VAR_SAMP"|"VARYING"|"WHEN"|"WHENEVER"|"WHERE"|"WIDTH_BUCKET"|"WINDOW"|"WITH"|"WITHIN"|"WITHOUT"|"YEAR")
110
111/* Need multiple keyword definitions due to max length */
112keyword (?i:{keywords1}|{keywords2}|{keywords3}|{keywords4}|{keywords5}|{keywords6}|{keywords7}|{keywords8}|{keywords9}|{keywords10}|{keywords11}|{keywords12}|{keywords13})
113
114typekeyword (?i:"ARRAY"|"BIGINT"|"BINARY"|"BLOB"|"BOOLEAN"|"CHAR"|"CHARACTER"|"CLOB"|"DATE"|"DEC"|"DECIMAL"|"DOUBLE"|"FLOAT"|"INT"|"INTEGER"|"NCHAR"|"NCLOB"|"NUMERIC"|"NVARCHAR"|"REAL"|"SMALLINT"|"TIME"|"TIMESTAMP"|"VARCHAR")
115
116flowkeyword (?i:"CASE"|"IF"|"ELSE"|"BEGIN"|"END"|"WHILE")
117
118literalkeyword (?i:"false"|"true"|"NULL"|"UNKNOWN")
119stringliteral (\"[^\"]*\")|('[^']*')
120number [0-9]+
121literals ({literalkeyword}|{stringliteral}|{number})
122
123variable @{idchar}+
124
125simplecomment --.*
126commentopen "/\*"
127commentclose "\*\/"
128
129%x COMMENT
130
131%%
132
133{literals} {
134 startFontClass(yyscanner,"stringliteral");
135 codifyLines(yyscanner,yytext);
136 endFontClass(yyscanner);
137 }
138
139
140{keyword} {
141 startFontClass(yyscanner,"keyword");
142 codifyLines(yyscanner,yytext);
143 endFontClass(yyscanner);
144 }
145
146{flowkeyword} {
147 startFontClass(yyscanner,"keywordflow");
148 codifyLines(yyscanner,yytext);
149 endFontClass(yyscanner);
150 }
151
152{typekeyword} {
153 startFontClass(yyscanner,"keywordtype");
154 codifyLines(yyscanner,yytext);
155 endFontClass(yyscanner);
156 }
157
158{variable} {
159 startFontClass(yyscanner,"preprocessor");
160 codifyLines(yyscanner,yytext);
161 endFontClass(yyscanner);
162 }
163
164{simplecomment} {
165 startFontClass(yyscanner,"comment");
166 codifyLines(yyscanner,yytext);
167 endFontClass(yyscanner);
168 }
169
170{commentopen} {
171 startFontClass(yyscanner,"comment");
172 codifyLines(yyscanner,yytext);
173 BEGIN(COMMENT);
174 }
175
176<COMMENT>. {
177 codifyLines(yyscanner,yytext);
178
179 }
180<COMMENT>{nl} {
181 codifyLines(yyscanner,yytext);
182 }
183
184<COMMENT>{commentclose} {
185 codifyLines(yyscanner,yytext);
186 endFontClass(yyscanner);
187 BEGIN(INITIAL);
188 }
189
190{idchar} {
191 codifyLines(yyscanner,yytext);
192 }
193
194{nl} {
195 codifyLines(yyscanner,yytext);
196 }
197
198[\x80-\xFF]* { // keep utf8 characters together...
199 codifyLines(yyscanner,yytext);
200 }
201. {
202 codifyLines(yyscanner,yytext);
203 }
204
205%%
206
207
208static void setCurrentDoc(yyscan_t yyscanner,const QCString &anchor)
209{
210 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
211 if (Doxygen::searchIndex.enabled())
212 {
213 if (yyextra->searchCtx)
214 {
215 Doxygen::searchIndex.setCurrentDoc(yyextra->searchCtx,yyextra->searchCtx->anchor(),false);
216 }
217 else
218 {
219 Doxygen::searchIndex.setCurrentDoc(yyextra->sourceFileDef,anchor,true);
220 }
221 }
222}
223
224/*! start a new line of code, inserting a line number if yyextra->sourceFileDef
225 * is true. If a definition starts at the current line, then the line
226 * number is linked to the documentation of that definition.
227 */
228static void startCodeLine(yyscan_t yyscanner)
229{
230 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
231 if (yyextra->sourceFileDef)
232 {
233 const Definition *d = yyextra->sourceFileDef->getSourceDefinition(yyextra->yyLineNr);
234
235 if (!yyextra->includeCodeFragment && d && d->isLinkableInProject())
236 {
237 yyextra->currentDefinition = d;
238 yyextra->currentMemberDef = yyextra->sourceFileDef->getSourceMember(yyextra->yyLineNr);
239 yyextra->classScope = d->name();
240 QCString lineAnchor;
241 lineAnchor.sprintf("l%05d",yyextra->yyLineNr);
242 if (yyextra->currentMemberDef)
243 {
244 yyextra->code->writeLineNumber(yyextra->currentMemberDef->getReference(),
245 yyextra->currentMemberDef->getOutputFileBase(),
246 yyextra->currentMemberDef->anchor(),yyextra->yyLineNr,
247 !yyextra->includeCodeFragment);
248 setCurrentDoc(yyscanner,lineAnchor);
249 }
250 else
251 {
252 yyextra->code->writeLineNumber(d->getReference(),
254 QCString(),yyextra->yyLineNr,
255 !yyextra->includeCodeFragment);
256 setCurrentDoc(yyscanner,lineAnchor);
257 }
258 }
259 else
260 {
261 yyextra->code->writeLineNumber(QCString(),QCString(),QCString(),yyextra->yyLineNr,
262 !yyextra->includeCodeFragment);
263 }
264 }
265
266 yyextra->code->startCodeLine(yyextra->yyLineNr);
267 yyextra->insideCodeLine=true;
268
269 if (yyextra->currentFontClass)
270 {
271 yyextra->code->startFontClass(yyextra->currentFontClass);
272 }
273}
274
275static void endFontClass(yyscan_t yyscanner)
276{
277 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
278 if (yyextra->currentFontClass)
279 {
280 yyextra->code->endFontClass();
281 yyextra->currentFontClass=0;
282 }
283}
284
285static void endCodeLine(yyscan_t yyscanner)
286{
287 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
288 endFontClass(yyscanner);
289 yyextra->code->endCodeLine();
290 yyextra->insideCodeLine=false;
291}
292
293static void nextCodeLine(yyscan_t yyscanner)
294{
295 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
296 const char *fc = yyextra->currentFontClass;
297 if (yyextra->insideCodeLine)
298 {
299 endCodeLine(yyscanner);
300 }
301 if (yyextra->yyLineNr<yyextra->inputLines)
302 {
303 yyextra->currentFontClass = fc;
304 startCodeLine(yyscanner);
305 }
306}
307
308static void codifyLines(yyscan_t yyscanner,const char *text)
309{
310 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
311 const char *p=text,*sp=p;
312 char c;
313 bool done=false;
314 while (!done)
315 {
316 sp=p;
317 while ((c=*p++) && c!='\n') { }
318 if (c=='\n')
319 {
320 yyextra->yyLineNr++;
321 size_t l = static_cast<size_t>(p-sp-1);
322 yyextra->code->codify(QCString(sp,l));
323 nextCodeLine(yyscanner);
324 }
325 else
326 {
327 yyextra->code->codify(sp);
328 done=true;
329 }
330 }
331}
332
333static void startFontClass(yyscan_t yyscanner,const char *s)
334{
335 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
336 endFontClass(yyscanner);
337 yyextra->code->startFontClass(s);
338 yyextra->currentFontClass=s;
339}
340
341/*! counts the number of lines in the input */
342static int countLines(yyscan_t yyscanner)
343{
344 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
345 const char *p=yyextra->inputString;
346 char c;
347 int count=1;
348 while ((c=*p))
349 {
350 p++ ;
351 if (c=='\n') count++;
352 }
353 if (p>yyextra->inputString && *(p-1)!='\n')
354 { // last line does not end with a \n, so we add an extra
355 // line and explicitly terminate the line after parsing.
356 count++;
357 }
358 return count;
359}
360
361static int yyread(yyscan_t yyscanner,char *buf,int max_size)
362{
363 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
364 int inputPosition = yyextra->inputPosition;
365 const char *s = yyextra->inputString + inputPosition;
366 int c=0;
367 while( c < max_size && *s )
368 {
369 *buf++ = *s++;
370 c++;
371 }
372 yyextra->inputPosition += c;
373 return c;
374}
375
376
377// public interface -----------------------------------------------------------
378
380{
386{
387 sqlcodeYYlex_init_extra(&p->state, &p->yyscanner);
388#ifdef FLEX_DEBUG
389 sqlcodeYYset_debug(Debug::isFlagSet(Debug::Lex_sqlcode)?1:0,p->yyscanner);
390#endif
392}
393
395{
396 sqlcodeYYlex_destroy(p->yyscanner);
397}
398
400{
401 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
402 yyextra->currentDefinition = nullptr;
403 yyextra->currentMemberDef = nullptr;
404}
405
407 const QCString &/* scopeName */,
408 const QCString &input,
410 bool stripCodeComments,
411 const CodeParserOptions &options
412 )
413{
414 yyscan_t yyscanner = p->yyscanner;
415 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
416
417 if (input.isEmpty()) return;
418
419 DebugLex debugLex(Debug::Lex_sqlcode, __FILE__, options.fileDef() ? qPrint(options.fileDef()->fileName()): nullptr);
420 yyextra->fileName = options.fileDef() ? options.fileDef()->fileName():"";
421 yyextra->code = &codeOutIntf;
422 yyextra->inputString = input.data();
423 yyextra->inputPosition = 0;
424 yyextra->currentFontClass = nullptr;
425 yyextra->insideCodeLine = false;
426 yyextra->searchCtx = options.searchCtx();
427 yyextra->yyLineNr = options.startLine()!=-1 ? options.startLine() : 1;
428 yyextra->inputLines = options.endLine()!=-1 ? options.endLine()+1 : yyextra->yyLineNr + countLines(yyscanner) - 1;
429 yyextra->stripCodeComments = stripCodeComments;
430 yyextra->exampleBlock = options.isExample();
431 yyextra->exampleName = options.exampleName();
432 yyextra->sourceFileDef = options.fileDef();
433
434 if (options.isExample() && options.fileDef()==0)
435 {
436 // create a dummy filedef for the example
437 yyextra->exampleFileDef = createFileDef(QCString(),!options.exampleName().isEmpty() ? options.exampleName() : QCString("generated"));
438 yyextra->sourceFileDef = yyextra->exampleFileDef.get();
439 }
440
441 if (yyextra->sourceFileDef)
442 {
443 setCurrentDoc(yyscanner,"l00001");
444 }
445
446 yyextra->includeCodeFragment = options.inlineFragment();
447 // Starts line 1 on the output
448 startCodeLine(yyscanner);
449
450 sqlcodeYYrestart( nullptr, yyscanner );
451
452 sqlcodeYYlex(yyscanner);
453
454 if (yyextra->insideCodeLine)
455 {
456 endCodeLine(yyscanner);
457 }
458 if (yyextra->exampleFileDef)
459 {
460 // delete the temporary file definition used for this example
461 yyextra->exampleFileDef.reset();
462 yyextra->sourceFileDef=nullptr;
463 }
464}
465
466//---------------------------------------------------------------------------------
467
468#include "sqlcode.l.h"
@ Lex_sqlcode
Definition debug.h:68
static bool isFlagSet(const DebugMask mask)
Definition debug.cpp:132
virtual bool isLinkableInProject() const =0
virtual QCString getReference() const =0
virtual QCString getOutputFileBase() const =0
virtual const QCString & name() const =0
static SearchIndexIntf searchIndex
Definition doxygen.h:123
virtual QCString fileName() const =0
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:163
QCString & sprintf(const char *format,...)
Definition qcstring.cpp:29
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition qcstring.h:172
std::unique_ptr< Private > p
Definition sqlcode.h:46
void resetCodeParserState() override
Resets the state of the code parser.
Definition sqlcode.l:401
void parseCode(OutputCodeList &codeOutIntf, const QCString &scopeName, const QCString &input, SrcLangExt, bool stripCodeComments, const CodeParserOptions &options) override
Parses a source file or fragment with the goal to produce highlighted and cross-referenced output.
Definition sqlcode.l:408
~SQLCodeParser() override
Definition sqlcode.l:396
std::unique_ptr< FileDef > createFileDef(const QCString &p, const QCString &n, const QCString &ref, const QCString &dn)
Definition filedef.cpp:268
const char * qPrint(const char *s)
Definition qcstring.h:687
Options to configure the code parser.
Definition parserintf.h:78
bool isExample() const
Definition parserintf.h:81
const Definition * searchCtx() const
Definition parserintf.h:89
const FileDef * fileDef() const
Definition parserintf.h:83
int endLine() const
Definition parserintf.h:85
bool inlineFragment() const
Definition parserintf.h:86
QCString exampleName() const
Definition parserintf.h:82
int startLine() const
Definition parserintf.h:84
sqlcodeYY_state state
Definition sqlcode.l:384
SrcLangExt
Definition types.h:207