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 182 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 202 of file parserintf.h.

204 : m_defaultParsers(outlineParserFactory,codeParserFactory, QCString())
205 {
206 }
ParserPair m_defaultParsers
Definition parserintf.h:290

References m_defaultParsers.

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 254 of file parserintf.h.

255 {
256 auto factory = getCodeParserFactory(extension);
257 return factory();
258 }
CodeParserFactory & getCodeParserFactory(const QCString &extension)
Get the factory for create code parser objects with a given extension.
Definition parserintf.h:261

References getCodeParserFactory().

◆ getCodeParserFactory()

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

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

Definition at line 261 of file parserintf.h.

262 {
263 return getParsers(extension).codeParserFactory;
264 }
ParserPair & getParsers(const QCString &extension)
Definition parserintf.h:276
CodeParserFactory codeParserFactory
Definition parserintf.h:193

References getParsers().

Referenced by 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 245 of file parserintf.h.

246 {
247 return getParsers(extension).outlineParserFactory();
248 }
OutlineParserFactory outlineParserFactory
Definition parserintf.h:192

References getParsers().

◆ 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, the empty string will be returned.

Definition at line 270 of file parserintf.h.

271 {
272 return getParsers(extension).parserName;
273 }

References getParsers().

◆ getParsers()

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

Definition at line 276 of file parserintf.h.

277 {
278 QCString ext = extension.lower();
279 if (ext.isEmpty()) ext=".no_extension";
280 auto it = m_extensions.find(ext.data());
281 if (it==m_extensions.end() && ext.length()>4)
282 {
283 it = m_extensions.find(ext.left(4).data());
284 }
285 return it!=m_extensions.end() ? it->second : m_defaultParsers;
286 }
std::map< std::string, ParserPair & > m_extensions
Definition parserintf.h:289
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:166
QCString lower() const
Definition qcstring.h:249
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:163
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
QCString left(size_t len) const
Definition qcstring.h:229

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

Referenced by getCodeParserFactory(), getOutlineParser(), and getParserName().

◆ 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 225 of file parserintf.h.

226 {
227 if (parserName.isEmpty() || extension.isEmpty()) return FALSE;
228
229 const auto &parserIt = m_parsers.find(parserName.str());
230 if (parserIt == m_parsers.end()) return FALSE;
231
232 auto extensionIt = m_extensions.find(extension.str());
233 if (extensionIt != m_extensions.end()) // extension already exists
234 {
235 m_extensions.erase(extensionIt); // remove it (e.g. user specified extension overrules built in one)
236 }
237 m_extensions.emplace(extension.str(),parserIt->second); // add new mapping
238 return TRUE;
239 }
std::map< std::string, ParserPair > m_parsers
Definition parserintf.h:288
const std::string & str() const
Definition qcstring.h:552
#define TRUE
Definition qcstring.h:37
#define FALSE
Definition qcstring.h:34

References FALSE, QCString::isEmpty(), m_extensions, m_parsers, 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 216 of file parserintf.h.

218 {
219 m_parsers.emplace(name.str(),ParserPair(outlineParserFactory,codeParserFactory,name));
220 }

References m_parsers, and QCString::str().

Member Data Documentation

◆ m_defaultParsers

ParserPair ParserManager::m_defaultParsers
private

Definition at line 290 of file parserintf.h.

Referenced by getParsers(), and ParserManager().

◆ m_extensions

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

Definition at line 289 of file parserintf.h.

Referenced by getParsers(), and registerExtension().

◆ m_parsers

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

Definition at line 288 of file parserintf.h.

Referenced by registerExtension(), and registerParser().


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