Debian Codegraph @

CodeLite/XMLLexerAPI.h

raw
1 //////////////////////////////////////////////////////////////////////////////
2 //////////////////////////////////////////////////////////////////////////////
3 //
4 // Copyright : (C) 2015 Eran Ifrah
5 // File name : XMLLexerAPI.h
6 //
7 // -------------------------------------------------------------------------
8 // A
9 // _____ _ _ _ _
10 // / __ \ | | | | (_) |
11 // | / \/ ___ __| | ___| | _| |_ ___
12 // | | / _ \ / _ |/ _ \ | | | __/ _ )
13 // | \__/\ (_) | (_| | __/ |___| | || __/
14 // \____/\___/ \__,_|\___\_____/_|\__\___|
15 //
16 // F i l e
17 //
18 // This program is free software; you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation; either version 2 of the License, or
21 // (at your option) any later version.
22 //
23 //////////////////////////////////////////////////////////////////////////////
24 //////////////////////////////////////////////////////////////////////////////
25
26 #ifndef XMLLexerAPI_H__
27 #define XMLLexerAPI_H__
28
29 #include <wx/filename.h>
30 #include <wx/string.h>
31 #include <wx/variant.h>
32 #include <map>
33 #include <vector>
34 #include <codelite_exports.h>
35
36 struct WXDLLIMPEXP_CL XMLLexerToken {
37 int lineNumber;
38 int column;
39 wxString text;
40 int type;
41 wxString comment;
42 XMLLexerToken()
43 : lineNumber(0)
44 , column(0)
45 , type(0)
46 {
47 }
48
49 XMLLexerToken(int tokenType)
50 : lineNumber(0)
51 , column(0)
52 , type(tokenType)
53 {
54 }
55
56 void Clear()
57 {
58 lineNumber = 0;
59 column = 0;
60 type = 0;
61 text.Clear();
62 }
63 typedef std::vector<XMLLexerToken> Vec_t;
64 };
65
66 /**
67 * @class XMLLexerUserData
68 */
69 struct WXDLLIMPEXP_CL XMLLexerUserData {
70 public:
71 FILE* m_currentPF;
72 void* parserData;
73
74 public:
75 void Clear()
76 {
77 if(m_currentPF) {
78 ::fclose(m_currentPF);
79 m_currentPF = NULL;
80 }
81 parserData = NULL;
82 }
83
84 XMLLexerUserData()
85 : m_currentPF(NULL)
86 , parserData(NULL)
87 {
88 }
89
90 ~XMLLexerUserData() { Clear(); }
91 void SetCurrentPF(FILE* currentPF) { this->m_currentPF = currentPF; }
92 };
93
94 typedef void* XMLScanner_t;
95
96 /**
97 * @brief create a new Lexer for a file content
98 */
99 WXDLLIMPEXP_CL XMLScanner_t xmlLexerNew(const wxString& content);
100
101 /**
102 * @brief create a scanner for a given file name
103 */
104 WXDLLIMPEXP_CL XMLScanner_t xmlLexerNew(const wxFileName& filename);
105
106 /**
107 * @brief destroy the current lexer and perform cleanup
108 */
109 WXDLLIMPEXP_CL void xmlLexerDestroy(XMLScanner_t* scanner);
110
111 /**
112 * @brief return the next token, its type, line number and columns
113 */
114 WXDLLIMPEXP_CL bool xmlLexerNext(XMLScanner_t scanner, XMLLexerToken& token);
115
116 /**
117 * @brief unget the last token
118 */
119 WXDLLIMPEXP_CL void xmlLexerUnget(XMLScanner_t scanner);
120
121 /**
122 * @brief return the current lexer token
123 */
124 WXDLLIMPEXP_CL wxString xmlLexerCurrentToken(XMLScanner_t scanner);
125
126 /**
127 * @brief return the associated data with this scanner
128 */
129 WXDLLIMPEXP_CL XMLLexerUserData* xmlLexerGetUserData(XMLScanner_t scanner);
130
131 #endif