Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

DotLexer.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <iostream>
35 #include <sstream>
36 #include <vector>
37 
38 
39 namespace ogdf {
40 
41 namespace dot {
42 
43 
45 
55 struct Token {
56 
57  enum class Type {
58  // Operators
60  // Brackets
63  // Keywords
65  strict,
66  // Values
68  };
69 
73  size_t row;
75  size_t column;
77  std::string *value;
78 
79  Token(size_t tokenRow, size_t tokenColumn, std::string *identifierContent = nullptr);
80 
82  static std::string toString(const Type &type);
83 };
84 
85 
87 
96 class Lexer {
97 private:
98  std::istream &m_input;
99 
100  std::string m_buffer; // Current line of given file.
101  size_t m_row, m_col; // Current position in parsed file.
102 
103  std::vector<Token> m_tokens;
104 
105  bool tokenizeLine();
106 
108 
113  bool match(const Token::Type &type, bool word = false);
114 
116 
121  bool match(const std::string &str, bool word = false);
122 
124 
128  bool identifier(Token &token);
129 
131 
135  bool isDotAlnum(signed char c);
136 
137 public:
139  explicit Lexer(std::istream &input);
140  ~Lexer();
141 
143 
146  bool tokenize();
148  const std::vector<Token> &tokens() const;
149 };
150 
151 }
152 }
size_t row
Indicates a token row (line).
Definition: DotLexer.h:73
Type type
The type of an field.
Definition: DotLexer.h:71
static bool match(B &in, const char *str)
Definition: ParseUtils.h:101
Token(size_t tokenRow, size_t tokenColumn, std::string *identifierContent=nullptr)
static std::string toString(const Type &type)
Returns string representation of given token type.
size_t column
Indicated a token column.
Definition: DotLexer.h:75
Just a simple token struct representing a DOT file fragment.
Definition: DotLexer.h:55
std::string * value
Identifier content (nullptr for non-id tokens).
Definition: DotLexer.h:77
std::string m_buffer
Definition: DotLexer.h:100
std::istream & m_input
Definition: DotLexer.h:98
Lexical analysis tool.
Definition: DotLexer.h:96
std::vector< Token > m_tokens
Definition: DotLexer.h:103
The namespace for all OGDF objects.