Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
DotLexer.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <iostream>
35#include <sstream>
36#include <vector>
37
38namespace ogdf {
39
40namespace dot {
41
42
44
54struct Token {
55 enum class Type {
56 // Operators
58 colon,
60 comma,
63 // Brackets
68 // Keywords
69 graph,
70 digraph,
72 node,
73 edge,
74 strict,
75 // Values
77 };
78
82 size_t row;
84 size_t column;
86 std::string* value;
87
88 Token(size_t tokenRow, size_t tokenColumn, std::string* identifierContent = nullptr);
89
91 static std::string toString(const Type& type);
92};
93
95
104class Lexer {
105private:
106 std::istream& m_input;
107
108 std::string m_buffer; // Current line of given file.
109 size_t m_row, m_col; // Current position in parsed file.
110
111 std::vector<Token> m_tokens;
112
114
116
121 bool match(const Token::Type& type, bool word = false);
122
124
129 bool match(const std::string& str, bool word = false);
130
132
137
139
143 bool isDotAlnum(signed char c);
144
145public:
147 explicit Lexer(std::istream& input);
149
151
154 bool tokenize();
156 const std::vector<Token>& tokens() const;
157};
158
159}
160}
Lexical analysis tool.
Definition DotLexer.h:104
const std::vector< Token > & tokens() const
Returns list of tokens (first use Lexer::tokenize())
std::string m_buffer
Definition DotLexer.h:108
bool isDotAlnum(signed char c)
Checks if character is allowed in an identifier by DOT standard.
std::istream & m_input
Definition DotLexer.h:106
bool match(const std::string &str, bool word=false)
Checks if head matches given string. Advances head on success.
std::vector< Token > m_tokens
Definition DotLexer.h:111
Lexer(std::istream &input)
Initializes lexer with given input (but does nothing to it).
bool tokenize()
Scans input and turns it into token list.
bool identifier(Token &token)
Checks whether head is an identifier.
bool match(const Token::Type &type, bool word=false)
Checks if head matches given token. Advances head on success.
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.
Just a simple token struct representing a DOT file fragment.
Definition DotLexer.h:54
static std::string toString(const Type &type)
Returns string representation of given token type.
Type type
The type of an field.
Definition DotLexer.h:80
size_t column
Indicated a token column.
Definition DotLexer.h:84
size_t row
Indicates a token row (line).
Definition DotLexer.h:82
std::string * value
Identifier content (nullptr for non-id tokens).
Definition DotLexer.h:86
Token(size_t tokenRow, size_t tokenColumn, std::string *identifierContent=nullptr)