Wolframe, 0.0.3

parseUtils.hpp
Go to the documentation of this file.
1 /************************************************************************
2 
3  Copyright (C) 2011 - 2014 Project Wolframe.
4  All rights reserved.
5 
6  This file is part of Project Wolframe.
7 
8  Commercial Usage
9  Licensees holding valid Project Wolframe Commercial licenses may
10  use this file in accordance with the Project Wolframe
11  Commercial License Agreement provided with the Software or,
12  alternatively, in accordance with the terms contained
13  in a written agreement between the licensee and Project Wolframe.
14 
15  GNU General Public License Usage
16  Alternatively, you can redistribute this file and/or modify it
17  under the terms of the GNU General Public License as published by
18  the Free Software Foundation, either version 3 of the License, or
19  (at your option) any later version.
20 
21  Wolframe is distributed in the hope that it will be useful,
22  but WITHOUT ANY WARRANTY; without even the implied warranty of
23  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  GNU General Public License for more details.
25 
26  You should have received a copy of the GNU General Public License
27  along with Wolframe. If not, see <http://www.gnu.org/licenses/>.
28 
29  If you have questions regarding the use of this file, please contact
30  Project Wolframe.
31 
32 ************************************************************************/
35 
36 #ifndef _WOLFRAME_PARSE_UTILS_HPP_INCLUDED
37 #define _WOLFRAME_PARSE_UTILS_HPP_INCLUDED
38 #include "utils/sourceLineInfo.hpp"
39 #include <string>
40 #include <vector>
41 #include <map>
42 
43 namespace _Wolframe {
44 namespace utils {
45 
49 class CharTable
50 {
51 public:
52  CharTable( const char* op="", bool isInverse=false);
53  bool operator[]( char ch) const {return m_ar[ (unsigned char)ch];}
54 private:
55  bool m_ar[256];
56 };
57 
61 const CharTable& emptyCharTable();
63 const CharTable& anyCharTable();
64 
68 {
69 public:
73  IdentifierTable( bool casesensitive_, const char** arg);
74 
76  int operator[]( const std::string&) const;
78  std::string tostring() const;
80  const char* idstring( int id) const;
81 
82 private:
83  bool m_casesensitive; //< true, if the keywords inserted are case sensitive
84  std::map<std::string,int> m_tab; //< table implementation
85  const char** m_arg; //< original set of keywors for inverse lookups
86 };
87 
88 
101 char parseNextToken( std::string& tok, std::string::const_iterator& itr, std::string::const_iterator end, const CharTable& operatorTable, const CharTable& alphaTable);
102 
104 char parseNextToken( std::string& tok, std::string::const_iterator& itr, std::string::const_iterator end, const CharTable& operatorTable);
105 
107 char parseNextToken( std::string& tok, std::string::const_iterator& itr, std::string::const_iterator end);
108 
110 char gotoNextToken( std::string::const_iterator& itr, std::string::const_iterator end);
111 
116 std::string parseLine( std::string::const_iterator& si, const std::string::const_iterator& se);
117 
124 int parseNextIdentifier( std::string::const_iterator& si, const std::string::const_iterator& se, const IdentifierTable& idtab);
125 
131 std::pair<std::string,std::string> parseTokenAssignement( std::string::const_iterator& itr, std::string::const_iterator end, const CharTable& alphaTable);
132 
137 std::pair<std::string,std::string> parseTokenAssignement( std::string::const_iterator& itr, std::string::const_iterator end);
138 
143 std::string parseNextLine( std::string::const_iterator& itr, std::string::const_iterator end);
144 
145 }} //namespace _Wolframe::utils
146 
147 #endif // _MISC_UTILS_HPP_INCLUDED
Defines a data structure to hold positional info in a source string for error messsages etc...
std::string parseLine(std::string::const_iterator &si, const std::string::const_iterator &se)
Parse the rest of the line starting.
std::pair< std::string, std::string > parseTokenAssignement(std::string::const_iterator &itr, std::string::const_iterator end, const CharTable &alphaTable)
Parse a token assignement 'identifier = token'.
const CharTable & emptyCharTable()
Get an empty character set as table.
Character table structure for parseNextToken( std::string&,std::string::const_iterator&, std::string::const_iterator, ...);.
Definition: parseUtils.hpp:49
char gotoNextToken(std::string::const_iterator &itr, std::string::const_iterator end)
Skip to next token (skip white spaces)
Identifier table structure for parseNextIdentifier( std::string::const_iterator&, std::string::const_...
Definition: parseUtils.hpp:67
bool operator[](char ch) const
Definition: parseUtils.hpp:53
std::string tostring() const
Get the list of keywords defined as string for log messages.
const CharTable & anyCharTable()
Get the character set containing all characters as table.
std::map< std::string, int > m_tab
Definition: parseUtils.hpp:84
std::string parseNextLine(std::string::const_iterator &itr, std::string::const_iterator end)
CharTable(const char *op="", bool isInverse=false)
const CharTable & identifierCharTable()
Get the default identifier character table.
int parseNextIdentifier(std::string::const_iterator &si, const std::string::const_iterator &se, const IdentifierTable &idtab)
Parse the next identifier if it is in 'idtab' or goto the next token if not.
const char ** m_arg
Definition: parseUtils.hpp:85
bool m_casesensitive
Definition: parseUtils.hpp:83
bool m_ar[256]
Definition: parseUtils.hpp:55
const char * idstring(int id) const
Get the keyword with index 'id' (starting from 1)
char parseNextToken(std::string &tok, std::string::const_iterator &itr, std::string::const_iterator end, const CharTable &operatorTable, const CharTable &alphaTable)
Parsing the next token in a UTF-8 or Isolatin-1 string that is either.
int operator[](const std::string &) const
Lookup in table.
IdentifierTable(bool casesensitive_, const char **arg)
Constructor.