SimpleLexer.h
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @author Simon Ottenhaus (simon dot ottenhaus at kit dot edu)
17 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
18 * GNU General Public License
19 */
20 
21 #pragma once
22 
23 #include <string>
24 
25 #include <boost/regex.hpp>
26 
27 #include "LexerInfo.h"
28 
29 namespace armarx
30 {
32  {
33  public:
34  struct Rule
35  {
36  Rule(int id, const std::string& name, const boost::regex& regex) :
37  id(id), name(name), regex(regex)
38  {
39  }
40 
41  int id;
42  std::string name;
43  boost::regex regex;
44  };
45 
46  SimpleLexer(std::string src, int tokenFin = -1, int tokenError = -2);
47 
48  void addRule(int id, const std::string& name, const std::string& regex);
49 
50  int nextToken();
51 
52  void reset();
53 
54  std::string tokenIdToName(int id);
55 
56  void positionToLineAndColumn(int pos, int& line, int& column);
58 
59  int pos;
60  int lastPos;
61  std::string src;
62 
64  std::string currentTokenValue;
65 
67  std::vector<Rule> rules;
68  };
69 } // namespace armarx
armarx::SimpleLexer::Rule
Definition: SimpleLexer.h:34
armarx::SimpleLexer::rules
std::vector< Rule > rules
Definition: SimpleLexer.h:67
armarx::SimpleLexer::getPositionInfo
LexerInfo getPositionInfo(int pos)
Definition: SimpleLexer.cpp:138
armarx::SimpleLexer::pos
int pos
Definition: SimpleLexer.h:59
armarx::SimpleLexer::currentTokenId
int currentTokenId
Definition: SimpleLexer.h:63
armarx::SimpleLexer::Rule::id
int id
Definition: SimpleLexer.h:41
armarx::SimpleLexer::src
std::string src
Definition: SimpleLexer.h:61
armarx::SimpleLexer::tokenError
int tokenError
Definition: SimpleLexer.h:66
LexerInfo.h
armarx::SimpleLexer::reset
void reset()
Definition: SimpleLexer.cpp:73
armarx::SimpleLexer::positionToLineAndColumn
void positionToLineAndColumn(int pos, int &line, int &column)
Definition: SimpleLexer.cpp:106
armarx::SimpleLexer::currentTokenValue
std::string currentTokenValue
Definition: SimpleLexer.h:64
armarx::SimpleLexer::tokenIdToName
std::string tokenIdToName(int id)
Definition: SimpleLexer.cpp:82
armarx::SimpleLexer::Rule::name
std::string name
Definition: SimpleLexer.h:42
armarx::SimpleLexer::Rule::Rule
Rule(int id, const std::string &name, const boost::regex &regex)
Definition: SimpleLexer.h:36
armarx::SimpleLexer::SimpleLexer
SimpleLexer(std::string src, int tokenFin=-1, int tokenError=-2)
Definition: SimpleLexer.cpp:25
armarx::SimpleLexer::nextToken
int nextToken()
Definition: SimpleLexer.cpp:41
armarx::SimpleLexer
Definition: SimpleLexer.h:31
armarx::SimpleLexer::addRule
void addRule(int id, const std::string &name, const std::string &regex)
Definition: SimpleLexer.cpp:35
armarx::LexerInfo
Definition: LexerInfo.h:30
armarx::SimpleLexer::lastPos
int lastPos
Definition: SimpleLexer.h:60
armarx::SimpleLexer::tokenFin
int tokenFin
Definition: SimpleLexer.h:66
armarx::SimpleLexer::Rule::regex
boost::regex regex
Definition: SimpleLexer.h:43
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27