Loading [MathJax]/extensions/tex2jax.js

Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
TlpLexer.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <iostream>
35#include <string>
36#include <vector>
37
38namespace ogdf {
39
40namespace tlp {
41
42
43struct Token {
44 enum class Type { leftParen, rightParen, identifier, string } type;
45
46 std::string* value; // Optional token value (avaliable in id and string).
47 size_t line, column; // Where given token occured for printing nice info.
48
49 Token(const Type& type, size_t line, size_t column);
50 friend std::ostream& operator<<(std::istream& os, const Token& token);
51
52 bool inline leftParen() const { return type == Type::leftParen; }
53
54 bool inline rightParen() const { return type == Type::rightParen; }
55
56 bool inline identifier() const { return type == Type::identifier; }
57
58 bool inline identifier(const char* str) const {
59 return type == Type::identifier && *value == str;
60 }
61
62 bool inline string() const { return type == Type::string; }
63
64 bool inline string(const char* str) const { return type == Type::string && *value == str; }
65};
66
67std::ostream& operator<<(std::ostream& os, const Token& token);
68
69class Lexer {
70private:
71 std::istream& m_istream;
72 std::string m_buffer;
73 std::string::const_iterator m_begin, m_end;
74 size_t m_line;
75
76 std::vector<Token> m_tokens;
77
80
84
85 size_t line() const { return m_line; }
86
87 size_t column() const { return std::distance(m_buffer.begin(), m_begin) + 1; }
88
89 static bool isIdentifier(char c);
90
91public:
92 explicit Lexer(std::istream& is);
94
95 bool tokenize();
96
97 const std::vector<Token>& tokens() const { return m_tokens; }
98};
99
100}
101}
size_t column() const
Definition TlpLexer.h:87
Lexer(std::istream &is)
static bool isIdentifier(char c)
std::istream & m_istream
Definition TlpLexer.h:71
bool tokenizeIdentifier()
std::string::const_iterator m_begin
Definition TlpLexer.h:73
std::string::const_iterator m_end
Definition TlpLexer.h:73
std::vector< Token > m_tokens
Definition TlpLexer.h:76
const std::vector< Token > & tokens() const
Definition TlpLexer.h:97
size_t line() const
Definition TlpLexer.h:85
std::string m_buffer
Definition TlpLexer.h:72
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
std::ostream & operator<<(std::ostream &os, const Token &token)
The namespace for all OGDF objects.
std::string * value
Definition TlpLexer.h:46
Token(const Type &type, size_t line, size_t column)
bool rightParen() const
Definition TlpLexer.h:54
bool string(const char *str) const
Definition TlpLexer.h:64
bool identifier() const
Definition TlpLexer.h:56
enum ogdf::tlp::Token::Type type
friend std::ostream & operator<<(std::istream &os, const Token &token)
bool identifier(const char *str) const
Definition TlpLexer.h:58
bool string() const
Definition TlpLexer.h:62
bool leftParen() const
Definition TlpLexer.h:52