File: pgsScanner.h

package info (click to toggle)
pgadmin3 1.20.0~beta2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 73,704 kB
  • ctags: 18,591
  • sloc: cpp: 193,786; ansic: 18,736; sh: 5,154; pascal: 1,120; yacc: 927; makefile: 516; lex: 421; xml: 126; perl: 40
file content (87 lines) | stat: -rw-r--r-- 2,510 bytes parent folder | download
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
//////////////////////////////////////////////////////////////////////////
//
// pgScript - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////////////////


#ifndef PGSSCANNER_H_
#define PGSSCANNER_H_

// Flex expects the signature of yylex to be defined in the macro YY_DECL, and
// the C++ parser expects it to be declared. We can factor both as follows.

#ifndef YY_DECL

#define	YY_DECL						\
	pgscript::pgsParser::token_type				\
	pgscript::pgsScanner::lex(				\
	pgscript::pgsParser::semantic_type* yylval,		\
	pgscript::pgsParser::location_type* yylloc		\
	)
#endif

#ifndef __FLEX_LEXER_H
#define yyFlexLexer pgsFlexLexer
#include "pgscript/FlexLexer.h"
#undef  yyFlexLexer
#endif

#include "pgscript/parser.tab.hh"
#include <iostream>
#include <fstream>
#include <sstream>

namespace pgscript
{

/** pgsScanner is a derived class to add some extra function to the scanner
 * class. Flex itself creates a class named yyFlexLexer, which is renamed using
 * macros to pgsFlexLexer. However we change the context of the generated
 * yylex() function to be contained within the pgsScanner class. This is required
 * because the yylex() defined in pgsFlexLexer has no parameters. */
class pgsScanner : public pgsFlexLexer
{
public:
	/** Create a new scanner object. The streams arg_yyin and arg_yyout default
	 * to cin and cout, but that assignment is only made when initializing in
	 * yylex(). */
	pgsScanner(wxMBConv &conv, std::istream *arg_yyin = 0,
	           std::ostream *arg_yyout = 0);

	/** Required for virtual functions */
	virtual ~pgsScanner();

	/** This is the main lexing function. It is generated by flex according to
	 * the macro declaration YY_DECL above. The generated bison parser then
	 * calls this virtual function to fetch new tokens. */
	virtual pgsParser::token_type lex(pgsParser::semantic_type *yylval,
	                                  pgsParser::location_type *yylloc);

	/** Enable debug output (via arg_yyout) if compiled into the scanner. */
	void set_debug(bool b);

private:

	/** Corrects column count because of multi-byte UTF8 characters. */
	int columns(const char &c);

	/** To count parenthesis. */
	int m_parent;

	std::string query, dollar, str;

	int comment_caller, string_caller;

	pgscript::pgsParser::token_type query_token;

	wxMBConv &m_conv;

};

} // namespace pgscript

#endif // PGSSCANNER_H_