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
|
/******************************************************************************
*
*
*
* Copyright (C) 1997-2005 by Dimitri van Heesch.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation under the terms of the GNU General Public License is hereby
* granted. No representations are made about the suitability of this software
* for any purpose. It is provided "as is" without express or implied warranty.
* See the GNU General Public License for more details.
*
* Documents produced by Doxygen are derivative works derived from the
* input used in their production; they are not affected by this license.
*
*/
#ifndef PARSERINTF_H
#define PARSERINTF_H
#include <qdict.h>
class Entry;
class FileDef;
class CodeOutputInterface;
class MemberDef;
/** \brief Abstract interface for programming language parsers.
*
* By implementing the methods of this interface one can add
* a new language parser to doxygen. The parser can make use of the
* comment block parser to parse the contents of special comment blocks.
*/
class ParserInterface
{
public:
/** Parses a single input file with the goal to build an Entry tree.
* @param[in] fileName The full name of the file.
* @param[in] fileBuf The contents of the file (zero terminated).
* @param[in,out] root The root of the tree of Entry *nodes
* representing the information extracted from the file.
*/
virtual void parseInput(const char *fileName,
const char *fileBuf,
Entry *root) = 0;
/** Returns TRUE if the language identified by \a extension needs
* the C preprocessor to be run before feed the result to the input
* parser.
* @see parseInput()
*/
virtual bool needsPreprocessing(const QCString &extension) = 0;
/** Parses a source file or fragment with the goal to produce
* highlighted and cross-referenced output.
* @param[in] codeOutIntf Abstract interface for writing the result.
* @param[in] scopeName Name of scope to which the code belongs.
* @param[in] input Actual code in the form of a string
* @param[in] isExampleBlock TRUE iff the code is part of an example.
* @param[in] exampleName Name of the example.
* @param[in] fileDef File definition to which the code
* is associated.
* @param[in] startLine Starting line in case of a code fragment.
* @param[in] endLine Ending line of the code fragment.
* @param[in] inlineFragment Code fragment that is to be shown inline
* as part of the documentation.
* @param[in] memberDef Member definition to which the code
* is associated (non null in case of an inline fragment
* for a member).
*/
virtual void parseCode(CodeOutputInterface &codeOutIntf,
const char *scopeName,
const QCString &input,
bool isExampleBlock,
const char *exampleName=0,
FileDef *fileDef=0,
int startLine=-1,
int endLine=-1,
bool inlineFragment=FALSE,
MemberDef *memberDef=0
) = 0;
/** Resets the state of the code parser.
* Since multiple code fragments can together form a single example, an
* explicit function is used to reset the code parser state.
* @see parseCode()
*/
virtual void resetCodeParserState() = 0;
/** Callback function called by the comment block scanner.
* It provides a string \a text containing the prototype of a function
* or variable. The parser should parse this and store the information
* in the Entry node that corresponds with the node for which the
* comment block parser was invoked.
*/
virtual void parsePrototype(const char *text) = 0;
};
//-----------------------------------------------------------------------------
/** \brief Manages programming language parsers.
*
* This class manages the language parsers in the system. One can
* register parsers, and obtain a parser given a file extension.
*/
class ParserManager
{
public:
/** Creates the parser manager object.
* @param defaultParser The default parser that is used when
* no explicit extension has been registered for
* a given input file.
*/
ParserManager(ParserInterface *defaultParser)
: m_defaultParser(defaultParser) {}
/** Registers an additional parser.
* @param[in] extension The file extension that will trigger
* the use of this parser (e.g. ".py", or ".bas").
* @param[in] parser The parser that is to be used for the
* given extension.
*/
void registerParser(const char *extension,ParserInterface *parser)
{
m_parsers.insert(extension,parser);
}
/** Gets the interface to the parser associated with given \a extension.
* If there is no parser explicitly registered for the supplied extension,
* the interface to the default parser will be returned.
*/
ParserInterface *getParser(const char *extension)
{
if (extension==0) return m_defaultParser;
ParserInterface *intf = m_parsers.find(extension);
return intf ? intf : m_defaultParser;
}
private:
QDict<ParserInterface> m_parsers;
ParserInterface *m_defaultParser;
};
#endif
|