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 <cstddef>
35#include <iostream>
36#include <string>
37#include <vector>
38
39namespace ogdf {
40
41namespace dot {
42
43
45
55struct Token {
56 enum class Type {
57 // Operators
59 colon,
61 comma,
64 // Brackets
69 // Keywords
70 graph,
71 digraph,
73 node,
74 edge,
75 strict,
76 // Values
78 };
79
83 size_t row;
85 size_t column;
87 std::string* value;
88
89 Token(size_t tokenRow, size_t tokenColumn, std::string* identifierContent = nullptr);
90
92 static std::string toString(const Type& type);
93};
94
96
105class Lexer {
106private:
107 std::istream& m_input;
108
109 std::string m_buffer; // Current line of given file.
110 size_t m_row, m_col; // Current position in parsed file.
111
112 std::vector<Token> m_tokens;
113
115
117
122 bool match(const Token::Type& type, bool word = false);
123
125
130 bool match(const std::string& str, bool word = false);
131
133
137 bool identifier(Token& token);
138
140
144 bool isDotAlnum(signed char c);
145
146public:
148 explicit Lexer(std::istream& input);
150
152
155 bool tokenize();
157 const std::vector<Token>& tokens() const;
158};
159
160}
161}
Lexical analysis tool.
Definition DotLexer.h:105
const std::vector< Token > & tokens() const
Returns list of tokens (first use Lexer::tokenize())
std::string m_buffer
Definition DotLexer.h:109
bool isDotAlnum(signed char c)
Checks if character is allowed in an identifier by DOT standard.
std::istream & m_input
Definition DotLexer.h:107
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:112
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.
The namespace for all OGDF objects.
Just a simple token struct representing a DOT file fragment.
Definition DotLexer.h:55
static std::string toString(const Type &type)
Returns string representation of given token type.
Type type
The type of an field.
Definition DotLexer.h:81
size_t column
Indicated a token column.
Definition DotLexer.h:85
size_t row
Indicates a token row (line).
Definition DotLexer.h:83
std::string * value
Identifier content (nullptr for non-id tokens).
Definition DotLexer.h:87
Token(size_t tokenRow, size_t tokenColumn, std::string *identifierContent=nullptr)