mstring  1.3.1
Generates C++ message functions and classes from localized message definitions
MStringParser Class Reference

#include <MStringParser.hh>

+ Inheritance diagram for MStringParser:
+ Collaboration diagram for MStringParser:

Classes

struct  Abort
 Thrown by error() after it recorded the diagnostic; caught in start(). More...
 
struct  Location
 

Public Member Functions

 MStringParser (ParseContext &context)
 
std::string getGrammarName () const noexcept override
 
bool parseFile (const std::string &path)
 Parse the message file path (as the user or $IMPORT named it). More...
 
bool parseStream (const std::string &name, std::istream &input)
 Parse input (standard input), reported as name. More...
 

Protected Member Functions

bool start () override
 
bool skipComments () override
 

Private Member Functions

char peek ()
 
char next ()
 
bool atEnd ()
 
bool atEndOfLine ()
 
Location here () const
 
void skipBlanks ()
 
void skipEmptyLines ()
 
void expectEndOfLine ()
 
std::string readWhile (bool(*accept)(char))
 
std::string readIdentifier ()
 
std::string requireIdentifier (const std::string &what)
 
std::string requireWord (bool(*accept)(char), const std::string &what)
 
std::string readQualifiedName (const std::string &what)
 
std::string readRestOfLine ()
 
std::string readKeyword ()
 
void error (const std::string &message, Location location)
 
void error (const std::string &message)
 
void warning (const std::string &message, Location location)
 
void directive ()
 
void languageDirective ()
 
void charsetDirective ()
 
void classDirective (ClassConcept &concept, const std::string &directive, bool exception)
 
void functionDirective (FunctionConcept &concept, const std::string &directive)
 
void errorDirective ()
 
void syslogDirective ()
 
void includeDirective ()
 
void importDirective ()
 
void usingDirective ()
 
void namespaceDirective ()
 
void moduleDirective ()
 
void messageDirective ()
 
bool commonOption (Concept &concept, const std::string &option)
 
bool classOption (ClassConcept &concept, const std::string &option)
 
bool functionOption (FunctionConcept &concept, const std::string &option, Location location)
 
void unknownOption (const std::string &option, const std::string &directive, Location location)
 
void messageLine ()
 
void parameterLine ()
 
void setHeaderLine ()
 
void quotedTextLine (char quote)
 
void barTextLine ()
 
void escapeSequence (std::string &text)
 
void macro (LocaleMessage &locale, Location open)
 
LocaleMessage & currentLocale ()
 
Message & currentMessage ()
 
std::string resolveImport (const std::string &filename) const
 
void closeMessage ()
 

Private Attributes

ParseContext & _Context
 
std::string _DisplayName
 The file name diagnostics use. More...
 
char _Last { '\n' }
 The last consumed character. More...
 
bool _InMessage { false }
 
std::size_t _MessageIndex { 0 }
 
Location _MessageLocation { 0, 0 }
 
bool _TextStarted { false }
 A text or set header was seen: no more parameters. More...
 
std::string _MessageLanguage
 
std::string _MessageCharset
 

Constructor & Destructor Documentation

◆ MStringParser()

MStringParser::MStringParser ( ParseContext &  context)
explicit

Member Function Documentation

◆ getGrammarName()

std::string MStringParser::getGrammarName ( ) const
overridenoexcept

◆ parseFile()

bool MStringParser::parseFile ( const std::string &  path)

Parse the message file path (as the user or $IMPORT named it).

Returns
false on error; the reason is in ParseContext::diagnostics.

References _Context, _DisplayName, ParseContext::diagnostics, ParseContext::failed(), and ParseContext::importStack.

Referenced by importDirective(), and main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseStream()

bool MStringParser::parseStream ( const std::string &  name,
std::istream &  input 
)

Parse input (standard input), reported as name.

References _Context, _DisplayName, ParseContext::failed(), and start().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ start()

bool MStringParser::start ( )
overrideprotected

References atEnd(), closeMessage(), directive(), messageLine(), peek(), and skipEmptyLines().

Referenced by parseStream().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ skipComments()

bool MStringParser::skipComments ( )
overrideprotected

References atEnd(), next(), and peek().

Referenced by expectEndOfLine(), and skipEmptyLines().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ peek()

char MStringParser::peek ( )
private

◆ next()

char MStringParser::next ( )
private

References _Last.

Referenced by barTextLine(), classOption(), directive(), escapeSequence(), expectEndOfLine(), importDirective(), includeDirective(), macro(), messageDirective(), parameterLine(), quotedTextLine(), readQualifiedName(), readRestOfLine(), readWhile(), setHeaderLine(), skipBlanks(), skipComments(), and skipEmptyLines().

+ Here is the caller graph for this function:

◆ atEnd()

bool MStringParser::atEnd ( )
private

References peek().

Referenced by barTextLine(), expectEndOfLine(), importDirective(), includeDirective(), macro(), quotedTextLine(), skipComments(), and start().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ atEndOfLine()

bool MStringParser::atEndOfLine ( )
private

References peek().

Referenced by classDirective(), directive(), errorDirective(), functionDirective(), messageDirective(), moduleDirective(), namespaceDirective(), readRestOfLine(), and syslogDirective().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ here()

MStringParser::Location MStringParser::here ( ) const
private

◆ skipBlanks()

void MStringParser::skipBlanks ( )
private

References next(), and peek().

Referenced by charsetDirective(), classDirective(), classOption(), directive(), errorDirective(), expectEndOfLine(), functionDirective(), importDirective(), includeDirective(), messageDirective(), moduleDirective(), namespaceDirective(), parameterLine(), readKeyword(), readQualifiedName(), requireIdentifier(), requireWord(), setHeaderLine(), skipEmptyLines(), syslogDirective(), and usingDirective().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ skipEmptyLines()

void MStringParser::skipEmptyLines ( )
private

References next(), peek(), skipBlanks(), and skipComments().

Referenced by start().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ expectEndOfLine()

void MStringParser::expectEndOfLine ( )
private

References atEnd(), error(), next(), peek(), skipBlanks(), and skipComments().

Referenced by charsetDirective(), classDirective(), directive(), errorDirective(), functionDirective(), importDirective(), includeDirective(), languageDirective(), messageDirective(), moduleDirective(), namespaceDirective(), parameterLine(), quotedTextLine(), setHeaderLine(), syslogDirective(), and usingDirective().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readWhile()

std::string MStringParser::readWhile ( bool(*)(char)  accept)
private

References next(), and peek().

Referenced by readIdentifier(), requireWord(), and syslogDirective().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readIdentifier()

std::string MStringParser::readIdentifier ( )
private

References peek(), and readWhile().

Referenced by classOption(), includeDirective(), readKeyword(), and requireIdentifier().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ requireIdentifier()

std::string MStringParser::requireIdentifier ( const std::string &  what)
private

References error(), here(), peek(), readIdentifier(), and skipBlanks().

Referenced by classDirective(), classOption(), commonOption(), directive(), functionOption(), messageDirective(), parameterLine(), and readQualifiedName().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ requireWord()

std::string MStringParser::requireWord ( bool(*)(char)  accept,
const std::string &  what 
)
private

References error(), here(), peek(), readWhile(), and skipBlanks().

Referenced by charsetDirective(), languageDirective(), moduleDirective(), and setHeaderLine().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readQualifiedName()

std::string MStringParser::readQualifiedName ( const std::string &  what)
private

References error(), here(), next(), peek(), requireIdentifier(), and skipBlanks().

Referenced by classOption(), functionOption(), and namespaceDirective().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readRestOfLine()

std::string MStringParser::readRestOfLine ( )
private

References atEndOfLine(), next(), and Trim().

Referenced by errorDirective(), importDirective(), parameterLine(), and usingDirective().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readKeyword()

std::string MStringParser::readKeyword ( )
private

References readIdentifier(), and skipBlanks().

Referenced by classDirective(), commonOption(), directive(), errorDirective(), functionDirective(), functionOption(), messageDirective(), moduleDirective(), and syslogDirective().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ error() [1/2]

void MStringParser::error ( const std::string &  message,
Location  location 
)
private

◆ error() [2/2]

void MStringParser::error ( const std::string &  message)
private

References error(), and here().

+ Here is the call graph for this function:

◆ warning()

void MStringParser::warning ( const std::string &  message,
Location  location 
)
private

References _Context, _DisplayName, MStringParser::Location::col, ParseContext::diagnostics, and MStringParser::Location::line.

Referenced by charsetDirective(), closeMessage(), moduleDirective(), and setHeaderLine().

+ Here is the caller graph for this function:

◆ directive()

void MStringParser::directive ( )
private

References _Context, MessageSettings::_Exception, MessageSettings::_Streamable, MessageSettings::_String, MessageSettings::_Throw, atEndOfLine(), charsetDirective(), classDirective(), closeMessage(), error(), errorDirective(), expectEndOfLine(), Module::Export, functionDirective(), here(), importDirective(), includeDirective(), languageDirective(), messageDirective(), ParseContext::module, moduleDirective(), namespaceDirective(), next(), readKeyword(), requireIdentifier(), ParseContext::settings, skipBlanks(), syslogDirective(), and usingDirective().

Referenced by classDirective(), functionDirective(), start(), and unknownOption().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ languageDirective()

void MStringParser::languageDirective ( )
private

References _Context, expectEndOfLine(), ParseContext::language, and requireWord().

Referenced by directive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ charsetDirective()

void MStringParser::charsetDirective ( )
private

References _Context, ParseContext::charset, expectEndOfLine(), here(), requireWord(), skipBlanks(), and warning().

Referenced by directive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ classDirective()

void MStringParser::classDirective ( ClassConcept &  concept,
const std::string &  directive,
bool  exception 
)
private

References ClassConcept::_Override, atEndOfLine(), classOption(), commonOption(), directive(), expectEndOfLine(), here(), readKeyword(), requireIdentifier(), skipBlanks(), and unknownOption().

Referenced by directive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ functionDirective()

void MStringParser::functionDirective ( FunctionConcept &  concept,
const std::string &  directive 
)
private

References atEndOfLine(), commonOption(), directive(), expectEndOfLine(), functionOption(), here(), readKeyword(), skipBlanks(), and unknownOption().

Referenced by directive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ errorDirective()

void MStringParser::errorDirective ( )
private

References _Context, MessageSettings::_Error, ErrorConcept::_ExitCall, atEndOfLine(), commonOption(), error(), expectEndOfLine(), functionOption(), here(), readKeyword(), readRestOfLine(), ParseContext::settings, skipBlanks(), Trim(), and unknownOption().

Referenced by directive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ syslogDirective()

void MStringParser::syslogDirective ( )
private

References _Context, LogConcept::_Facility, LogConcept::_Level, MessageSettings::_Log, atEndOfLine(), commonOption(), error(), expectEndOfLine(), functionOption(), here(), readKeyword(), readWhile(), ParseContext::settings, skipBlanks(), and unknownOption().

Referenced by directive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ includeDirective()

void MStringParser::includeDirective ( )
private

References _Context, atEnd(), error(), expectEndOfLine(), here(), Module::Includes, ParseContext::module, next(), peek(), readIdentifier(), skipBlanks(), and Trim().

Referenced by directive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ importDirective()

void MStringParser::importDirective ( )
private

References _Context, atEnd(), error(), expectEndOfLine(), here(), next(), parseFile(), peek(), readRestOfLine(), resolveImport(), and skipBlanks().

Referenced by directive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ usingDirective()

void MStringParser::usingDirective ( )
private

References _Context, error(), expectEndOfLine(), here(), ParseContext::module, readRestOfLine(), skipBlanks(), Trim(), and Module::Usings.

Referenced by directive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ namespaceDirective()

void MStringParser::namespaceDirective ( )
private

References _Context, atEndOfLine(), expectEndOfLine(), ParseContext::module, Module::Namespaces, readQualifiedName(), and skipBlanks().

Referenced by directive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ moduleDirective()

void MStringParser::moduleDirective ( )
private

References _Context, atEndOfLine(), expectEndOfLine(), Module::HeaderExtension, here(), Module::Inline, ParseContext::module, Module::Name, readKeyword(), requireWord(), skipBlanks(), Module::SourceExtension, unknownOption(), and warning().

Referenced by directive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ messageDirective()

void MStringParser::messageDirective ( )
private

References Concept::_Active, _Context, _DisplayName, MessageSettings::_Error, MessageSettings::_Exception, _InMessage, MessageSettings::_Log, _MessageCharset, _MessageIndex, _MessageLanguage, _MessageLocation, MessageSettings::_Streamable, MessageSettings::_String, _TextStarted, MessageSettings::_Throw, atEndOfLine(), ParseContext::charset, MStringParser::Location::col, error(), expectEndOfLine(), Module::FindMessage(), here(), ParseContext::language, MStringParser::Location::line, Module::Messages, ParseContext::module, next(), peek(), readKeyword(), requireIdentifier(), ParseContext::settings, skipBlanks(), and ParseContext::trace.

Referenced by directive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ commonOption()

bool MStringParser::commonOption ( Concept &  concept,
const std::string &  option 
)
private

References Concept::_Active, Concept::_Customized, Concept::_LocaleExtra, Concept::_Postfix, Concept::_Prefix, error(), here(), readKeyword(), and requireIdentifier().

Referenced by classDirective(), errorDirective(), functionDirective(), and syslogDirective().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ classOption()

bool MStringParser::classOption ( ClassConcept &  concept,
const std::string &  option 
)
private

References ClassConcept::_InheritanceType, ClassConcept::_Parent, error(), here(), next(), peek(), PRIVATE_INHERITANCE, PROTECTED_INHERITANCE, PUBLIC_INHERITANCE, readIdentifier(), readQualifiedName(), requireIdentifier(), and skipBlanks().

Referenced by classDirective().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ functionOption()

bool MStringParser::functionOption ( FunctionConcept &  concept,
const std::string &  option,
Location  location 
)
private

References FunctionConcept::_Constness, FunctionConcept::_Naming, FunctionConcept::_Type, error(), here(), MEMBER_AS, MEMBER_OF, NONMEMBER, readKeyword(), readQualifiedName(), and requireIdentifier().

Referenced by errorDirective(), functionDirective(), and syslogDirective().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unknownOption()

void MStringParser::unknownOption ( const std::string &  option,
const std::string &  directive,
Location  location 
)
private

References directive(), error(), and peek().

Referenced by classDirective(), errorDirective(), functionDirective(), moduleDirective(), and syslogDirective().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ messageLine()

void MStringParser::messageLine ( )
private

References _InMessage, barTextLine(), error(), parameterLine(), peek(), quotedTextLine(), and setHeaderLine().

Referenced by start().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parameterLine()

void MStringParser::parameterLine ( )
private

References _TextStarted, currentMessage(), error(), expectEndOfLine(), Message::FindParameter(), here(), Message::Name, next(), Message::Parameters, readRestOfLine(), requireIdentifier(), and skipBlanks().

Referenced by messageLine().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setHeaderLine()

void MStringParser::setHeaderLine ( )
private

References _Context, _MessageCharset, _MessageLanguage, _TextStarted, ParseContext::charset, error(), expectEndOfLine(), here(), next(), peek(), requireWord(), skipBlanks(), and warning().

Referenced by messageLine().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ quotedTextLine()

void MStringParser::quotedTextLine ( char  quote)
private

References _TextStarted, LocaleMessage::AppendText(), atEnd(), currentLocale(), error(), escapeSequence(), expectEndOfLine(), here(), macro(), next(), and peek().

Referenced by messageLine().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ barTextLine()

void MStringParser::barTextLine ( )
private

References _TextStarted, LocaleMessage::AppendText(), atEnd(), currentLocale(), escapeSequence(), here(), macro(), next(), and peek().

Referenced by messageLine().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ escapeSequence()

void MStringParser::escapeSequence ( std::string &  text)
private

References next(), and peek().

Referenced by barTextLine(), and quotedTextLine().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ macro()

void MStringParser::macro ( LocaleMessage &  locale,
Location  open 
)
private

References atEnd(), error(), TextElement::Formats, next(), peek(), TextElement::Text, LocaleMessage::TextElements, and Trim().

Referenced by barTextLine(), and quotedTextLine().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ currentLocale()

LocaleMessage & MStringParser::currentLocale ( )
private

References _MessageCharset, _MessageLanguage, currentMessage(), and Message::Locale().

Referenced by barTextLine(), and quotedTextLine().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ currentMessage()

Message & MStringParser::currentMessage ( )
private

References _Context, _MessageIndex, Module::Messages, and ParseContext::module.

Referenced by closeMessage(), currentLocale(), and parameterLine().

+ Here is the caller graph for this function:

◆ resolveImport()

std::string MStringParser::resolveImport ( const std::string &  filename) const
private

References _Context, _DisplayName, and ParseContext::importFolders.

Referenced by importDirective().

+ Here is the caller graph for this function:

◆ closeMessage()

void MStringParser::closeMessage ( )
private

References _InMessage, _MessageLocation, currentMessage(), and warning().

Referenced by directive(), and start().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ _Context

◆ _DisplayName

std::string MStringParser::_DisplayName
private

The file name diagnostics use.

Referenced by error(), messageDirective(), parseFile(), parseStream(), resolveImport(), and warning().

◆ _Last

char MStringParser::_Last { '\n' }
private

The last consumed character.

Referenced by here(), and next().

◆ _InMessage

bool MStringParser::_InMessage { false }
private

◆ _MessageIndex

std::size_t MStringParser::_MessageIndex { 0 }
private

Referenced by currentMessage(), and messageDirective().

◆ _MessageLocation

Location MStringParser::_MessageLocation { 0, 0 }
private

Referenced by closeMessage(), and messageDirective().

◆ _TextStarted

bool MStringParser::_TextStarted { false }
private

A text or set header was seen: no more parameters.

Referenced by barTextLine(), messageDirective(), parameterLine(), quotedTextLine(), and setHeaderLine().

◆ _MessageLanguage

std::string MStringParser::_MessageLanguage
private

◆ _MessageCharset

std::string MStringParser::_MessageCharset
private

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