Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
ogdf::dot::Lexer Class Reference

Lexical analysis tool. More...

#include <ogdf/fileformats/DotLexer.h>

Public Member Functions

 Lexer (std::istream &input)
 Initializes lexer with given input (but does nothing to it).
 
 ~Lexer ()
 
bool tokenize ()
 Scans input and turns it into token list.
 
const std::vector< Token > & tokens () const
 Returns list of tokens (first use Lexer::tokenize())
 

Private Member Functions

bool identifier (Token &token)
 Checks whether head is an identifier.
 
bool isDotAlnum (signed char c)
 Checks if character is allowed in an identifier by DOT standard.
 
bool match (const std::string &str, bool word=false)
 Checks if head matches given string. Advances head on success.
 
bool match (const Token::Type &type, bool word=false)
 Checks if head matches given token. Advances head on success.
 
bool tokenizeLine ()
 

Private Attributes

std::string m_buffer
 
size_t m_col
 
std::istream & m_input
 
size_t m_row
 
std::vector< Tokenm_tokens
 

Detailed Description

Lexical analysis tool.

This class reads the given input and generates a token list. Token list representation of DOT file is much easier for further processing (like parsing) as it automatically gets rid of comments and deals with various identifier representations in DOT format (C-like identifier, double-quoted strings, number literals).

See also
dot::Parser

Definition at line 104 of file DotLexer.h.

Constructor & Destructor Documentation

◆ Lexer()

ogdf::dot::Lexer::Lexer ( std::istream &  input)
explicit

Initializes lexer with given input (but does nothing to it).

◆ ~Lexer()

ogdf::dot::Lexer::~Lexer ( )

Member Function Documentation

◆ identifier()

bool ogdf::dot::Lexer::identifier ( Token token)
private

Checks whether head is an identifier.

Parameters
tokenFunction fills it with identifier value and col/row info.
Returns
True if matches, false otherwise.

◆ isDotAlnum()

bool ogdf::dot::Lexer::isDotAlnum ( signed char  c)
private

Checks if character is allowed in an identifier by DOT standard.

Parameters
cA character
Returns
True if c is one of alphabetic ([a-zA-Z\200-\377]) characters, underscores ('_') or digits ([0-9])

◆ match() [1/2]

bool ogdf::dot::Lexer::match ( const std::string &  str,
bool  word = false 
)
private

Checks if head matches given string. Advances head on success.

Parameters
strA string being matched.
wordTrue if token is part of a word, false otherwise.
Returns
True if matches, false otherwise.

◆ match() [2/2]

bool ogdf::dot::Lexer::match ( const Token::Type type,
bool  word = false 
)
private

Checks if head matches given token. Advances head on success.

Parameters
typeA type of token being matched.
wordTrue if token is part of a word, false otherwise.
Returns
True if matches, false otherwise.

◆ tokenize()

bool ogdf::dot::Lexer::tokenize ( )

Scans input and turns it into token list.

Returns
True if success, false otherwise.

◆ tokenizeLine()

bool ogdf::dot::Lexer::tokenizeLine ( )
private

◆ tokens()

const std::vector< Token > & ogdf::dot::Lexer::tokens ( ) const

Returns list of tokens (first use Lexer::tokenize())

Member Data Documentation

◆ m_buffer

std::string ogdf::dot::Lexer::m_buffer
private

Definition at line 108 of file DotLexer.h.

◆ m_col

size_t ogdf::dot::Lexer::m_col
private

Definition at line 109 of file DotLexer.h.

◆ m_input

std::istream& ogdf::dot::Lexer::m_input
private

Definition at line 106 of file DotLexer.h.

◆ m_row

size_t ogdf::dot::Lexer::m_row
private

Definition at line 109 of file DotLexer.h.

◆ m_tokens

std::vector<Token> ogdf::dot::Lexer::m_tokens
private

Definition at line 111 of file DotLexer.h.


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