Hermes
Loading...
Searching...
No Matches
hermes::StringParser Class Reference

General token parser for strings. More...

#include <parsers.h>

Public Member Functions

void setBlankCharacters (const std::string &blank_characters)
 
void pushBlankCharacter (char blank_character)
 
void pushBlankDelimiters (const std::string &open_pattern, const std::string &close_pattern)
 
void pushBlockDelimiters (const std::string &open_pattern, const std::string &close_pattern)
 
void pushTokenPattern (const std::string &name, const std::string &regex_pattern)
 Appends a token - pattern pair to the parser.
 
Result< ParseTreeparse (const std::string &text, bool copy_string=true)
 Parses a given string into a parsing tree.
 

Static Public Member Functions

static StringParser cLanguage ()
 A simple and rough parser for c-like languages (far from complete).
 
static size_t matchPrefixWithAny (const std::string &characters, const std::string &s, size_t start=0)
 Matches the prefix (from start) of the string with any any sequence in the given set of characters.
 
static size_t matchPrefixWithAny (const std::vector< std::pair< std::string, std::string > > &block_delimiters, const std::string &s, size_t &block_content_start, size_t &block_content_size, size_t start=0)
 Matches the prefix (from start) of the string with any block.
 
static size_t matchPrefixWithAny (const std::vector< std::string > &block_openings, const std::string &s, int &match_id, size_t start=0)
 Matches the prefix (from start) of the string with any block.
 
static size_t startsWith (const std::vector< std::pair< std::string, std::string > > &block_delimiters, const std::string &s, size_t i=0)
 Checks if string starts with a block delimiter (first element in pairs)
 

Detailed Description

General token parser for strings.

Member Function Documentation

◆ cLanguage()

StringParser hermes::StringParser::cLanguage ( )
static

A simple and rough parser for c-like languages (far from complete).

Returns
StringParser object with configured rules.

◆ matchPrefixWithAny() [1/3]

size_t hermes::StringParser::matchPrefixWithAny ( const std::string &  characters,
const std::string &  s,
size_t  start = 0 
)
static

Matches the prefix (from start) of the string with any any sequence in the given set of characters.

Parameters
characters
sraw string
startstarting index in the string s
Returns
the size of the matched sequence

◆ matchPrefixWithAny() [2/3]

size_t hermes::StringParser::matchPrefixWithAny ( const std::vector< std::pair< std::string, std::string > > &  block_delimiters,
const std::string &  s,
size_t block_content_start,
size_t block_content_size,
size_t  start = 0 
)
static

Matches the prefix (from start) of the string with any block.

Note
This function stops at the first match (blocks with equal opening prefix will give undefined behavior)
Parameters
block_delimiters
sraw string
block_content_startindex of the string of the first character in the content
block_content_sizecontent's size
startstarting index in the string for the prefix
Returns
size of the matched block (opening + content + closing)

◆ matchPrefixWithAny() [3/3]

size_t hermes::StringParser::matchPrefixWithAny ( const std::vector< std::string > &  block_openings,
const std::string &  s,
int match_id,
size_t  start = 0 
)
static

Matches the prefix (from start) of the string with any block.

Note
This function matches with the block with the largest delimiter.
Parameters
block_openings
s
match_idreceives the input vector index of the matched block, -1 otherwise
startstarting index at s
Returns
size of the opening patter for the matched block

◆ parse()

Result< ParseTree > hermes::StringParser::parse ( const std::string &  text,
bool  copy_string = true 
)

Parses a given string into a parsing tree.

Parameters
text
copy_string
Returns

◆ pushTokenPattern()

void hermes::StringParser::pushTokenPattern ( const std::string &  name,
const std::string &  regex_pattern 
)

Appends a token - pattern pair to the parser.

Parameters
name
regex_pattern

◆ startsWith()

size_t hermes::StringParser::startsWith ( const std::vector< std::pair< std::string, std::string > > &  block_delimiters,
const std::string &  s,
size_t  i = 0 
)
static

Checks if string starts with a block delimiter (first element in pairs)

Parameters
block_delimiters
sraw string
istarting index
Returns
the index of the block with matching start

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