ArkScript
A small, fast, functional and scripting language for video games
Ark::internal::BaseParser Class Reference

#include <BaseParser.hpp>

Inheritance diagram for Ark::internal::BaseParser:
[legend]
Collaboration diagram for Ark::internal::BaseParser:
[legend]

Public Member Functions

 BaseParser ()=default
 

Protected Member Functions

void initParser (const std::string &filename, const std::string &code)
 
FilePosition getCursor () const
 
void error (const std::string &error, std::string exp)
 
void errorWithNextToken (const std::string &message)
 Fetch the next token (space and paren delimited) to generate an error.
 
void errorMissingSuffix (char suffix, const std::string &node_name)
 Generate an error for a given node when a suffix is missing.
 
long getCount ()
 
std::size_t getSize () const
 
bool isEOF () const
 
void backtrack (long n)
 
bool accept (const CharPred &t, std::string *s=nullptr)
 check if a Character Predicate was able to parse, call next() if matching
 
bool expect (const CharPred &t, std::string *s=nullptr)
 heck if a Character Predicate was able to parse, call next() if matching ; throw a CodeError if it doesn't match
 
bool space (std::string *s=nullptr)
 
bool inlineSpace (std::string *s=nullptr)
 
bool comment (std::string *s=nullptr)
 
bool spaceComment (std::string *s=nullptr)
 
bool newlineOrComment (std::string *s=nullptr)
 
bool prefix (char c)
 
bool suffix (char c)
 
bool number (std::string *s=nullptr)
 
bool signedNumber (std::string *s=nullptr)
 
bool hexNumber (unsigned length, std::string *s=nullptr)
 
bool name (std::string *s=nullptr)
 
bool sequence (const std::string &s)
 
bool packageName (std::string *s=nullptr)
 
bool anyUntil (const CharPred &delim, std::string *s=nullptr)
 Match any char that do not match the predicate.
 
bool oneOf (std::initializer_list< std::string > words, std::string *s=nullptr)
 Fetch a token and try to match one of the given words.
 

Protected Attributes

std::string m_filename
 

Private Member Functions

void registerNewLine (std::string::iterator it, std::size_t row)
 Register the position of a new line, with an iterator pointing to the new line and the row number.
 
void next ()
 getting next character and changing the values of count/row/col/sym
 

Private Attributes

std::string m_str
 
std::vector< std::pair< std::string::iterator, std::size_t > > m_it_to_row
 A crude map of
position to line number to speed up line number computing.
 
std::string::iterator m_it
 
std::string::iterator m_next_it
 
utf8_char_t m_sym
 The current utf8 character we're on.
 
FilePosition m_filepos
 The position of the cursor in the file.
 

Detailed Description

Definition at line 23 of file BaseParser.hpp.

Constructor & Destructor Documentation

◆ BaseParser()

Ark::internal::BaseParser::BaseParser ( )
default

Member Function Documentation

◆ accept()

bool Ark::internal::BaseParser::accept ( const CharPred & t,
std::string * s = nullptr )
protected

◆ anyUntil()

bool Ark::internal::BaseParser::anyUntil ( const CharPred & delim,
std::string * s = nullptr )
protected

Match any char that do not match the predicate.

Parameters
delimdelimiter predicate
soptional string to append the matching chars to
Returns
true if matched

Definition at line 322 of file BaseParser.cpp.

References accept().

Referenced by errorWithNextToken().

◆ backtrack()

◆ comment()

◆ error()

void Ark::internal::BaseParser::error ( const std::string & error,
std::string exp )
protected
Parameters
erroran error message
expthe expression causing the error

Definition at line 118 of file BaseParser.cpp.

References error(), getCursor(), m_filename, and m_sym.

Referenced by error(), errorWithNextToken(), expect(), Ark::internal::Parser::functionArgs(), Ark::internal::Parser::import_(), initParser(), and Ark::internal::Parser::letMutSet().

◆ errorMissingSuffix()

void Ark::internal::BaseParser::errorMissingSuffix ( char suffix,
const std::string & node_name )
protected

Generate an error for a given node when a suffix is missing.

Parameters
suffixa suffix char, eg " or ) @param node_name can be "string", "node" ; represents a structure

Definition at line 135 of file BaseParser.cpp.

References errorWithNextToken(), and suffix().

Referenced by Ark::internal::Parser::wrapped().

◆ errorWithNextToken()

void Ark::internal::BaseParser::errorWithNextToken ( const std::string & message)
protected

◆ expect()

bool Ark::internal::BaseParser::expect ( const CharPred & t,
std::string * s = nullptr )
protected

heck if a Character Predicate was able to parse, call next() if matching ; throw a CodeError if it doesn't match

Parameters
ta char predicate to match
soptional string to append the matching chars to
Returns
true if matched

Definition at line 156 of file BaseParser.cpp.

References Ark::internal::utf8_char_t::c_str(), Ark::internal::utf8_char_t::codepoint(), error(), m_sym, Ark::internal::CharPred::name, and next().

Referenced by Ark::internal::Parser::block(), Ark::internal::Parser::functionArgs(), Ark::internal::Parser::functionCall(), Ark::internal::Parser::import_(), Ark::internal::Parser::list(), and Ark::internal::Parser::macro().

◆ getCount()

◆ getCursor()

◆ getSize()

std::size_t Ark::internal::BaseParser::getSize ( ) const
inlineprotected
Returns
file size in bytes

Definition at line 87 of file BaseParser.hpp.

◆ hexNumber()

bool Ark::internal::BaseParser::hexNumber ( unsigned length,
std::string * s = nullptr )
protected

Definition at line 279 of file BaseParser.cpp.

References accept().

◆ initParser()

void Ark::internal::BaseParser::initParser ( const std::string & filename,
const std::string & code )
protected

Definition at line 64 of file BaseParser.cpp.

References error(), m_filename, m_it, m_next_it, m_str, m_sym, and next().

Referenced by Ark::internal::Parser::process().

◆ inlineSpace()

bool Ark::internal::BaseParser::inlineSpace ( std::string * s = nullptr)
protected

Definition at line 182 of file BaseParser.cpp.

References accept().

Referenced by spaceComment().

◆ isEOF()

bool Ark::internal::BaseParser::isEOF ( ) const
inlinenodiscardprotected

◆ name()

◆ newlineOrComment()

◆ next()

void Ark::internal::BaseParser::next ( )
private

◆ number()

bool Ark::internal::BaseParser::number ( std::string * s = nullptr)
protected

Definition at line 248 of file BaseParser.cpp.

References accept().

Referenced by signedNumber().

◆ oneOf()

bool Ark::internal::BaseParser::oneOf ( std::initializer_list< std::string > words,
std::string * s = nullptr )
protected

Fetch a token and try to match one of the given words.

Parameters
wordslist of words to match against
soptional string to append the matching chars to
Returns
true if matched

Definition at line 333 of file BaseParser.cpp.

References name().

Referenced by Ark::internal::Parser::block(), Ark::internal::Parser::condition(), Ark::internal::Parser::del(), Ark::internal::Parser::function(), Ark::internal::Parser::import_(), Ark::internal::Parser::letMutSet(), Ark::internal::Parser::loop(), Ark::internal::Parser::macro(), and Ark::internal::Parser::macroCondition().

◆ packageName()

bool Ark::internal::BaseParser::packageName ( std::string * s = nullptr)
protected

Definition at line 311 of file BaseParser.cpp.

References accept().

Referenced by Ark::internal::Parser::import_().

◆ prefix()

bool Ark::internal::BaseParser::prefix ( char c)
protected

Definition at line 236 of file BaseParser.cpp.

References accept().

Referenced by Ark::internal::Parser::wrapped().

◆ registerNewLine()

void Ark::internal::BaseParser::registerNewLine ( std::string::iterator it,
std::size_t row )
private

Register the position of a new line, with an iterator pointing to the new line and the row number.

Parameters
it
row

Definition at line 11 of file BaseParser.cpp.

References m_it_to_row, m_str, and next().

Referenced by next().

◆ sequence()

bool Ark::internal::BaseParser::sequence ( const std::string & s)
protected

Definition at line 304 of file BaseParser.cpp.

References accept().

Referenced by Ark::internal::Parser::macroArgs().

◆ signedNumber()

bool Ark::internal::BaseParser::signedNumber ( std::string * s = nullptr)
protected

Definition at line 261 of file BaseParser.cpp.

References accept(), Ark::internal::IsMinus, and number().

◆ space()

bool Ark::internal::BaseParser::space ( std::string * s = nullptr)
protected

Definition at line 168 of file BaseParser.cpp.

References accept().

Referenced by Ark::internal::Parser::import_(), and newlineOrComment().

◆ spaceComment()

bool Ark::internal::BaseParser::spaceComment ( std::string * s = nullptr)
protected

Definition at line 208 of file BaseParser.cpp.

References comment(), inlineSpace(), and isEOF().

Referenced by Ark::internal::Parser::process(), and Ark::internal::Parser::wrapped().

◆ suffix()

bool Ark::internal::BaseParser::suffix ( char c)
protected

Definition at line 243 of file BaseParser.cpp.

References accept().

Referenced by errorMissingSuffix(), and Ark::internal::Parser::wrapped().

Member Data Documentation

◆ m_filename

std::string Ark::internal::BaseParser::m_filename
protected

Definition at line 49 of file BaseParser.hpp.

Referenced by error(), initParser(), and Ark::internal::Parser::setNodePosAndFilename().

◆ m_filepos

FilePosition Ark::internal::BaseParser::m_filepos
private

The position of the cursor in the file.

Definition at line 33 of file BaseParser.hpp.

Referenced by backtrack(), getCursor(), and next().

◆ m_it

std::string::iterator Ark::internal::BaseParser::m_it
private

Definition at line 31 of file BaseParser.hpp.

Referenced by backtrack(), initParser(), and next().

◆ m_it_to_row

std::vector<std::pair<std::string::iterator, std::size_t> > Ark::internal::BaseParser::m_it_to_row
private

A crude map of
position to line number to speed up line number computing.

Definition at line 30 of file BaseParser.hpp.

Referenced by backtrack(), and registerNewLine().

◆ m_next_it

std::string::iterator Ark::internal::BaseParser::m_next_it
private

Definition at line 31 of file BaseParser.hpp.

Referenced by backtrack(), initParser(), and next().

◆ m_str

std::string Ark::internal::BaseParser::m_str
private

Definition at line 29 of file BaseParser.hpp.

Referenced by backtrack(), initParser(), next(), and registerNewLine().

◆ m_sym

utf8_char_t Ark::internal::BaseParser::m_sym
private

The current utf8 character we're on.

Definition at line 32 of file BaseParser.hpp.

Referenced by accept(), backtrack(), error(), expect(), initParser(), and next().


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