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

168 : m_defaultParsers(outlineParserFactory,codeParserFactory, QCString())
169 {
170 }
ParserPair m_defaultParsers
Definition parserintf.h:254

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

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

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

226 {
227 return getParsers(extension).codeParserFactory;
228 }
ParserPair & getParsers(const QCString &extension)
Definition parserintf.h:240
CodeParserFactory codeParserFactory
Definition parserintf.h:157

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

210 {
211 return getParsers(extension).outlineParserFactory();
212 }
OutlineParserFactory outlineParserFactory
Definition parserintf.h:156

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

235 {
236 return getParsers(extension).parserName;
237 }

References getParsers().

◆ getParsers()

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

Definition at line 240 of file parserintf.h.

241 {
242 QCString ext = extension.lower();
243 if (ext.isEmpty()) ext=".no_extension";
244 auto it = m_extensions.find(ext.data());
245 if (it==m_extensions.end() && ext.length()>4)
246 {
247 it = m_extensions.find(ext.left(4).data());
248 }
249 return it!=m_extensions.end() ? it->second : m_defaultParsers;
250 }
std::map< std::string, ParserPair & > m_extensions
Definition parserintf.h:253
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:153
QCString lower() const
Definition qcstring.h:234
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:150
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:159
QCString left(size_t len) const
Definition qcstring.h:214

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

190 {
191 if (parserName.isEmpty() || extension.isEmpty()) return FALSE;
192
193 const auto &parserIt = m_parsers.find(parserName.str());
194 if (parserIt == m_parsers.end()) return FALSE;
195
196 auto extensionIt = m_extensions.find(extension.str());
197 if (extensionIt != m_extensions.end()) // extension already exists
198 {
199 m_extensions.erase(extensionIt); // remove it (e.g. user specified extension overrules built in one)
200 }
201 m_extensions.emplace(extension.str(),parserIt->second); // add new mapping
202 return TRUE;
203 }
std::map< std::string, ParserPair > m_parsers
Definition parserintf.h:252
const std::string & str() const
Definition qcstring.h:537
#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 180 of file parserintf.h.

182 {
183 m_parsers.emplace(name.str(),ParserPair(outlineParserFactory,codeParserFactory,name));
184 }

References m_parsers, and QCString::str().

Member Data Documentation

◆ m_defaultParsers

ParserPair ParserManager::m_defaultParsers
private

Definition at line 254 of file parserintf.h.

Referenced by getParsers(), and ParserManager().

◆ m_extensions

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

Definition at line 253 of file parserintf.h.

Referenced by getParsers(), and registerExtension().

◆ m_parsers

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

Definition at line 252 of file parserintf.h.

Referenced by registerExtension(), and registerParser().


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