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 "LexerInfo.h"
24 
25 #include <string>
26 #include <boost/regex.hpp>
27 namespace armarx
28 {
30  {
31  public:
32  struct Rule
33  {
34  Rule(int id, const std::string& name, const boost::regex& regex)
35  : id(id), name(name), regex(regex)
36  {}
37  int id;
38  std::string name;
39  boost::regex regex;
40  };
41 
42  SimpleLexer(std::string src, int tokenFin = -1, int tokenError = -2);
43 
44  void addRule(int id, const std::string& name, const std::string& regex);
45 
46  int nextToken();
47 
48  void reset();
49 
50  std::string tokenIdToName(int id);
51 
52  void positionToLineAndColumn(int pos, int& line, int& column);
54 
55  int pos;
56  int lastPos;
57  std::string src;
58 
60  std::string currentTokenValue;
61 
63  std::vector<Rule> rules;
64  };
65 }
66 
67 
armarx::SimpleLexer::Rule
Definition: SimpleLexer.h:32
armarx::SimpleLexer::rules
std::vector< Rule > rules
Definition: SimpleLexer.h:63
armarx::SimpleLexer::getPositionInfo
LexerInfo getPositionInfo(int pos)
Definition: SimpleLexer.cpp:132
armarx::SimpleLexer::pos
int pos
Definition: SimpleLexer.h:55
armarx::SimpleLexer::currentTokenId
int currentTokenId
Definition: SimpleLexer.h:59
armarx::SimpleLexer::Rule::id
int id
Definition: SimpleLexer.h:37
armarx::SimpleLexer::src
std::string src
Definition: SimpleLexer.h:57
armarx::SimpleLexer::tokenError
int tokenError
Definition: SimpleLexer.h:62
LexerInfo.h
armarx::SimpleLexer::reset
void reset()
Definition: SimpleLexer.cpp:69
armarx::SimpleLexer::positionToLineAndColumn
void positionToLineAndColumn(int pos, int &line, int &column)
Definition: SimpleLexer.cpp:100
armarx::SimpleLexer::currentTokenValue
std::string currentTokenValue
Definition: SimpleLexer.h:60
armarx::SimpleLexer::tokenIdToName
std::string tokenIdToName(int id)
Definition: SimpleLexer.cpp:77
armarx::SimpleLexer::Rule::name
std::string name
Definition: SimpleLexer.h:38
armarx::SimpleLexer::Rule::Rule
Rule(int id, const std::string &name, const boost::regex &regex)
Definition: SimpleLexer.h:34
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:39
armarx::SimpleLexer
Definition: SimpleLexer.h:29
armarx::SimpleLexer::addRule
void addRule(int id, const std::string &name, const std::string &regex)
Definition: SimpleLexer.cpp:34
armarx::LexerInfo
Definition: LexerInfo.h:30
armarx::SimpleLexer::lastPos
int lastPos
Definition: SimpleLexer.h:56
armarx::SimpleLexer::tokenFin
int tokenFin
Definition: SimpleLexer.h:62
armarx::SimpleLexer::Rule::regex
boost::regex regex
Definition: SimpleLexer.h:39
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28