libosmscout  1.1.1
Parser.h
Go to the documentation of this file.
1 /*
2  This source is part of the libosmscout library
3  Copyright (C) 2011 Tim Teulings
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 
20 
21 #if !defined(osmscout_ost_PARSER_H)
22 #define osmscout_ost_PARSER_H
23 
24 #include <osmscout/TypeConfig.h>
25 #include <osmscout/TypeFeatures.h>
26 
27 #include <osmscout/util/String.h>
28 
29 #include <osmscout/ost/Scanner.h>
30 
31 namespace osmscout {
32 namespace ost {
33 
34 
35 class Errors
36 {
37 public:
38  class Err
39  {
40  public:
41  enum Type {
46  };
47 
48  public:
50  int line;
51  int column;
52  std::string text;
53  };
54 
55 public:
56  std::list<Err> errors;
57  bool hasErrors;
58 
59 public:
60  Errors();
61  void SynErr(int line, int col, int n);
62  void Error(int line, int col, const char *s);
63  void Warning(int line, int col, const char *s);
64  void Warning(const char *s);
65  void Exception(const char *s);
66 };
67 
68 class Parser
69 {
70 private:
71  enum {
72  _EOF=0,
73  _ident=1,
74  _number=2,
75  _string=3
76  };
77  int maxT;
78 
79  TokenRef dummyToken;
80  int errDist;
81  int minErrDist;
82 
83  void SynErr(int n);
84  void Get();
85  void Expect(int n);
86  bool StartOf(int s);
87  void ExpectWeak(int n, int follow);
88  bool WeakSeparator(int n, int syFol, int repFol);
89 
90  Scanner *scanner;
91 
92  TokenRef t; // last recognized token
93  TokenRef la; // lookahead token
94 
95  TypeConfig& config;
96 
97 public:
99 
100 std::string Destring(const char* str)
101 {
102  std::string result(str);
103 
104  if (result.length()>=2 &&
105  result[0]=='"' &&
106  result[result.length()-1]=='"') {
107  result=result.substr(1,result.length()-2);
108  }
109 
110  return result;
111 }
112 
113 
114 
115  Parser(Scanner *scanner,
116  TypeConfig& config);
117  ~Parser();
118  void SemErr(const char* msg);
119 
120  void OST();
121  void MAXSPEEDS();
122  void GRADES();
123  void FEATURES();
124  void TYPES();
125  void MAXSPEED();
126  void STRING(std::string& value);
127  void UINT(size_t& value);
128  void GRADE();
129  void FEATURE();
130  void IDENT(std::string& value);
131  void FEATUREDESCS(Feature& feature);
132  void TYPE();
133  void TYPEKINDS(unsigned char& types);
134  void TAGCONDITION(TagConditionRef& condition);
135  void TYPEFEATURE(TypeInfo& typeInfo);
136  void SPECIALTYPE(TypeInfo& typeInfo);
137  void TYPEOPTIONS(TypeInfo& typeInfo);
138  void GROUPS(TypeInfo& typeInfo);
139  void TYPEDESCS(TypeInfo& typeInfo);
140  void TAGANDCOND(TagConditionRef& condition);
141  void TAGBOOLCOND(TagConditionRef& condition);
142  void TAGBINCOND(TagConditionRef& condition);
143  void TAGEXISTSCOND(TagConditionRef& condition);
144  void TAGLESSCOND(const std::string& tagName,TagConditionRef& condition);
145  void TAGLESSEQUALCOND(const std::string& tagName,TagConditionRef& condition);
146  void TAGEQUALSCOND(const std::string& tagName,TagConditionRef& condition);
147  void TAGNOTEQUALSCOND(const std::string& tagName,TagConditionRef& condition);
148  void TAGGREATERCOND(const std::string& tagName,TagConditionRef& condition);
149  void TAGGREATEREQUALCOND(const std::string& tagName,TagConditionRef& condition);
150  void TAGISINCOND(const std::string& tagName,TagConditionRef& condition);
151  void TYPEKIND(unsigned char& types);
152  void TYPEOPTION(TypeInfo& typeInfo);
153  void PATH(TypeInfo& typeInfo);
154  void LANES(TypeInfo& typeInfo);
155  void UINT8(uint8_t& value);
156 
157  void Parse();
158 };
159 
160 } // namespace
161 } // namespace
162 
163 
164 #endif // !defined(COCO_PARSER_H__)
165 
std::shared_ptr< Token > TokenRef
Definition: Scanner.h:43
std::string text
Definition: Parser.h:52
void TYPEKINDS(unsigned char &types)
void TAGBOOLCOND(TagConditionRef &condition)
void IDENT(std::string &value)
Definition: Scanner.h:138
void SynErr(int line, int col, int n)
Definition: Parser.h:42
void TYPEOPTION(TypeInfo &typeInfo)
void TYPEDESCS(TypeInfo &typeInfo)
std::string Destring(const char *str)
Definition: Parser.h:100
Type
Definition: Parser.h:41
Type type
Definition: Parser.h:49
void TAGEXISTSCOND(TagConditionRef &condition)
Parser(Scanner *scanner, TypeConfig &config)
Definition: Parser.h:43
void GROUPS(TypeInfo &typeInfo)
void TAGGREATEREQUALCOND(const std::string &tagName, TagConditionRef &condition)
void TAGBINCOND(TagConditionRef &condition)
Errors * errors
Definition: Parser.h:98
Definition: Area.h:38
Definition: TypeFeature.h:98
void TAGNOTEQUALSCOND(const std::string &tagName, TagConditionRef &condition)
void UINT8(uint8_t &value)
void TAGEQUALSCOND(const std::string &tagName, TagConditionRef &condition)
void TAGLESSCOND(const std::string &tagName, TagConditionRef &condition)
void FEATUREDESCS(Feature &feature)
int column
Definition: Parser.h:51
void Warning(int line, int col, const char *s)
void Error(int line, int col, const char *s)
void TAGANDCOND(TagConditionRef &condition)
void TAGLESSEQUALCOND(const std::string &tagName, TagConditionRef &condition)
std::list< Err > errors
Definition: Parser.h:56
void TYPEKIND(unsigned char &types)
void TYPEFEATURE(TypeInfo &typeInfo)
void SPECIALTYPE(TypeInfo &typeInfo)
void UINT(size_t &value)
int line
Definition: Parser.h:50
Definition: Parser.h:68
void LANES(TypeInfo &typeInfo)
void TYPEOPTIONS(TypeInfo &typeInfo)
Definition: Parser.h:35
void Exception(const char *s)
void SemErr(const char *msg)
std::shared_ptr< TagCondition > TagConditionRef
Definition: Tag.h:68
void PATH(TypeInfo &typeInfo)
void TAGGREATERCOND(const std::string &tagName, TagConditionRef &condition)
void TAGISINCOND(const std::string &tagName, TagConditionRef &condition)
void STRING(std::string &value)
bool hasErrors
Definition: Parser.h:57
Definition: Parser.h:38
void TAGCONDITION(TagConditionRef &condition)