Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

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 
112  bool match(const Token::Type &type);
113 
115 
120  bool match(const std::string &str);
121 
123 
127  bool identifier(Token &token);
128 
129 public:
131  explicit Lexer(std::istream &input);
132  ~Lexer();
133 
135 
138  bool tokenize();
140  const std::vector<Token> &tokens() const;
141 };
142 
143 
144 } // end namespace dot
145 
146 } // end namespace ogdf
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.