Doxygen
Loading...
Searching...
No Matches
ParserManager Class Reference

Manages programming language parsers. More...

#include <src/parserintf.h>

+ Collaboration diagram for ParserManager:

Classes

struct  ParserPair
 

Public Member Functions

 ParserManager (const OutlineParserFactory &outlineParserFactory, const CodeParserFactory &codeParserFactory)
 Create the parser manager.
 
void registerParser (const QCString &name, const OutlineParserFactory &outlineParserFactory, const CodeParserFactory &codeParserFactory)
 Registers an additional parser.
 
bool registerExtension (const QCString &extension, const QCString &parserName)
 Registers a file extension with a parser with name parserName.
 
std::unique_ptr< OutlineParserInterfacegetOutlineParser (const QCString &extension)
 Gets the interface to the parser associated with a given extension.
 
std::unique_ptr< CodeParserInterfacegetCodeParser (const QCString &extension)
 Gets the interface to the parser associated with a given extension.
 
CodeParserFactorygetCodeParserFactory (const QCString &extension)
 Get the factory for create code parser objects with a given extension.
 
QCString getParserName (const QCString &extension)
 Gets the name of the parser associated with given extension.
 

Private Member Functions

ParserPairgetParsers (const QCString &extension)
 

Private Attributes

std::map< std::string, ParserPairm_parsers
 
std::map< std::string, ParserPair & > m_extensions
 
ParserPair m_defaultParsers
 

Detailed Description

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.

Definition at line 144 of file parserintf.h.

Constructor & Destructor Documentation

◆ ParserManager()

ParserManager::ParserManager ( const OutlineParserFactory & outlineParserFactory,
const CodeParserFactory & codeParserFactory )
inline

Create the parser manager.

Parameters
outlineParserFactorythe fallback outline parser factory to use for unknown extensions
codeParserFactorythe fallback code parser factory to use for unknown extensions

Definition at line 164 of file parserintf.h.

166 : m_defaultParsers(outlineParserFactory,codeParserFactory, QCString())
167 {
168 }
ParserPair m_defaultParsers
Definition parserintf.h:252
This is an alternative implementation of QCString.
Definition qcstring.h:94

Member Function Documentation

◆ getCodeParser()

std::unique_ptr< CodeParserInterface > ParserManager::getCodeParser ( const QCString & extension)
inline

Gets the interface to the parser associated with a given extension.

If there is no parser explicitly registered for the supplied extension, the interface to the default parser will be returned.

Definition at line 216 of file parserintf.h.

217 {
218 auto factory = getCodeParserFactory(extension);
219 return factory();
220 }
CodeParserFactory & getCodeParserFactory(const QCString &extension)
Get the factory for create code parser objects with a given extension.
Definition parserintf.h:223

Referenced by MemberDefImpl::_writeMultiLineInitializer(), generateExampleDocs(), CodeFragmentManager::parseCodeFragment(), FileDefImpl::parseSource(), ConceptDefImpl::writeDefinition(), DefinitionImpl::writeInlineCode(), VhdlDocGen::writeSource(), FileDefImpl::writeSourceBody(), and writeXMLCodeBlock().

◆ getCodeParserFactory()

CodeParserFactory & ParserManager::getCodeParserFactory ( const QCString & extension)
inline

Get the factory for create code parser objects with a given extension.

Definition at line 223 of file parserintf.h.

224 {
225 return getParsers(extension).codeParserFactory;
226 }
ParserPair & getParsers(const QCString &extension)
Definition parserintf.h:238
CodeParserFactory codeParserFactory
Definition parserintf.h:155

Referenced by DocVisitor::getCodeParser().

◆ getOutlineParser()

std::unique_ptr< OutlineParserInterface > ParserManager::getOutlineParser ( const QCString & extension)
inline

Gets the interface to the parser associated with a given extension.

If there is no parser explicitly registered for the supplied extension, the interface to the default parser will be returned.

Definition at line 207 of file parserintf.h.

208 {
209 return getParsers(extension).outlineParserFactory();
210 }
OutlineParserFactory outlineParserFactory
Definition parserintf.h:154

Referenced by VhdlDocGen::createFlowChart(), getParserForFile(), and MarkdownOutlineParser::parsePrototype().

◆ getParserName()

QCString ParserManager::getParserName ( const QCString & extension)
inline

Gets the name of the parser associated with given extension.

If there is no parser explicitly registered for the supplied extension, te empty string will be reurned.

Definition at line 232 of file parserintf.h.

233 {
234 return getParsers(extension).parserName;
235 }

Referenced by convertFileNameFortranParserCode().

◆ getParsers()

ParserPair & ParserManager::getParsers ( const QCString & extension)
inlineprivate

Definition at line 238 of file parserintf.h.

239 {
240 QCString ext = extension.lower();
241 if (ext.isEmpty()) ext=".no_extension";
242 auto it = m_extensions.find(ext.data());
243 if (it==m_extensions.end() && ext.length()>4)
244 {
245 it = m_extensions.find(ext.left(4).data());
246 }
247 return it!=m_extensions.end() ? it->second : m_defaultParsers;
248 }
std::map< std::string, ParserPair & > m_extensions
Definition parserintf.h:251
int find(char c, int index=0, bool cs=TRUE) const
Definition qcstring.cpp:43
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:146
QCString lower() const
Definition qcstring.h:227
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:143
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:152
QCString left(size_t len) const
Definition qcstring.h:207

References QCString::data(), QCString::find(), QCString::isEmpty(), QCString::left(), QCString::length(), and QCString::lower().

◆ registerExtension()

bool ParserManager::registerExtension ( const QCString & extension,
const QCString & parserName )
inline

Registers a file extension with a parser with name parserName.

Returns TRUE if the extension was successfully registered.

Definition at line 187 of file parserintf.h.

188 {
189 if (parserName.isEmpty() || extension.isEmpty()) return FALSE;
190
191 const auto &parserIt = m_parsers.find(parserName.str());
192 if (parserIt == m_parsers.end()) return FALSE;
193
194 auto extensionIt = m_extensions.find(extension.str());
195 if (extensionIt != m_extensions.end()) // extension already exists
196 {
197 m_extensions.erase(extensionIt); // remove it (e.g. user specified extension overrules built in one)
198 }
199 m_extensions.emplace(extension.str(),parserIt->second); // add new mapping
200 return TRUE;
201 }
std::map< std::string, ParserPair > m_parsers
Definition parserintf.h:250
const std::string & str() const
Definition qcstring.h:517
#define TRUE
Definition qcstring.h:37
#define FALSE
Definition qcstring.h:34

References FALSE, QCString::isEmpty(), QCString::str(), and TRUE.

◆ registerParser()

void ParserManager::registerParser ( const QCString & name,
const OutlineParserFactory & outlineParserFactory,
const CodeParserFactory & codeParserFactory )
inline

Registers an additional parser.

Parameters
[in]nameA symbolic name of the parser, i.e. "c", "python", "fortran", "vhdl", ...
[in]outlineParserFactoryA factory method to create a language parser (scanner) that is to be used for the given name.
[in]codeParserFactoryA factory method to create a code parser that is to be used for the given name.

Definition at line 178 of file parserintf.h.

180 {
181 m_parsers.emplace(name.str(),ParserPair(outlineParserFactory,codeParserFactory,name));
182 }

References QCString::str().

Referenced by initDoxygen().

Member Data Documentation

◆ m_defaultParsers

ParserPair ParserManager::m_defaultParsers
private

Definition at line 252 of file parserintf.h.

◆ m_extensions

std::map<std::string,ParserPair &> ParserManager::m_extensions
private

Definition at line 251 of file parserintf.h.

◆ m_parsers

std::map<std::string,ParserPair> ParserManager::m_parsers
private

Definition at line 250 of file parserintf.h.


The documentation for this class was generated from the following file: