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
 
CodeErrorContext generateErrorContext (const std::string &expr)
 
void error (const std::string &error, std::string exp, const std::optional< CodeErrorContext > &additional_context=std::nullopt)
 
void errorWithNextToken (const std::string &message, const std::optional< CodeErrorContext > &additional_context=std::nullopt)
 Fetch the next token (space and paren delimited) to generate an error.
 
void expectSuffixOrError (char suffix, const std::string &context, const std::optional< CodeErrorContext > &additional_context=std::nullopt)
 Check for a closing char or generate an error.
 
long getCount ()
 
std::size_t getSize () const
 
bool isEOF () const
 
void backtrack (long n)
 Backtrack to a given position (this is NOT an offset!)
 
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
 
std::string peek () const
 
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 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 24 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 338 of file BaseParser.cpp.

References accept().

Referenced by errorWithNextToken().

◆ backtrack()

◆ comment()

◆ error()

void Ark::internal::BaseParser::error ( const std::string & error,
std::string exp,
const std::optional< CodeErrorContext > & additional_context = std::nullopt )
protected
Parameters
erroran error message
expthe expression causing the error
additional_contextoptional context created when a node is being parsed

Definition at line 130 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().

◆ errorWithNextToken()

void Ark::internal::BaseParser::errorWithNextToken ( const std::string & message,
const std::optional< CodeErrorContext > & additional_context = std::nullopt )
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 172 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::functionArgs().

◆ expectSuffixOrError()

void Ark::internal::BaseParser::expectSuffixOrError ( char suffix,
const std::string & context,
const std::optional< CodeErrorContext > & additional_context = std::nullopt )
protected

Check for a closing char or generate an error.

Parameters
suffixa suffix char, eg " or ) @param context can be "string", "node" ; represents a structure
additional_contextoptional context created when a node is being parsed

Definition at line 150 of file BaseParser.cpp.

References accept(), and errorWithNextToken().

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

◆ generateErrorContext()

CodeErrorContext Ark::internal::BaseParser::generateErrorContext ( const std::string & expr)
nodiscardprotected

◆ getCount()

◆ getCursor()

◆ getSize()

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

Definition at line 93 of file BaseParser.hpp.

◆ hexNumber()

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

Definition at line 295 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 203 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 264 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 349 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 327 of file BaseParser.cpp.

References accept().

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

◆ peek()

std::string Ark::internal::BaseParser::peek ( ) const
nodiscardprotected

Definition at line 184 of file BaseParser.cpp.

References Ark::internal::utf8_char_t::c_str(), and m_sym.

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

◆ prefix()

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

Definition at line 257 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, and m_str.

Referenced by next().

◆ sequence()

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

Definition at line 320 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 277 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 189 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 229 of file BaseParser.cpp.

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

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

Member Data Documentation

◆ m_filename

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

◆ m_filepos

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

The position of the cursor in the file.

Definition at line 34 of file BaseParser.hpp.

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

◆ m_it

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

Definition at line 32 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 31 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 32 of file BaseParser.hpp.

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

◆ m_str

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

Definition at line 30 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 33 of file BaseParser.hpp.

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


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