libosmscout 1.1.1
Loading...
Searching...
No Matches
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_oss_PARSER_H)
22#define osmscout_oss_PARSER_H
23
24#include <limits>
25#include <list>
26#include <sstream>
27
28#include <osmscout/Pixel.h>
29
30#include <osmscout/TypeConfig.h>
31
32#include <osmscout/io/File.h>
33
36#include <osmscout/log/Logger.h>
37
38
40
42
43#ifdef CONST
44 #undef CONST
45#endif
46
47namespace osmscout {
48namespace oss {
49
50
51class Errors
52{
53public:
54 class Err
55 {
56 public:
63
64 public:
66 int line;
67 int column;
68 std::string text;
69 };
70
71public:
72 std::list<Err> errors;
73 bool hasErrors=false;
75
76public:
77 explicit Errors(const Log &log);
78 void SynErr(int line, int col, int n);
79 void Error(int line, int col, const char *s);
80 void Warning(int line, int col, const char *s);
81 void Warning(const char *s);
82 void Exception(const char *s);
83
84};
85
86class Parser
87{
88private:
89 enum {
90 _EOF=0,
91 _ident=1,
92 _number=2,
93 _double=3,
94 _color=4,
95 _variable=5,
96 _string=6
97 };
98 int maxT;
99
100 TokenRef dummyToken;
101 int errDist;
102 int minErrDist;
103 Scanner *scanner;
104 TokenRef t; // last recognized token
105 TokenRef la; // lookahead token
106
107 osmscout::ColorPostprocessor colorPostprocessor;
108
109 void SynErr(int n);
110
111 void Get();
112 void Expect(int n);
113 bool StartOf(int s);
114 void ExpectWeak(int n, int follow);
115 bool WeakSeparator(int n, int syFol, int repFol);
116
117 osmscout::Color PostprocessColor(const osmscout::Color& color) const;
118
119public:
121
122std::string filename;
125bool state;
126
136
137std::string Destring(const char* str)
138{
139 std::string result(str);
140
141 if (result.length()>=2 &&
142 result[0]=='"' &&
143 result[result.length()-1]=='"') {
144 result=result.substr(1,result.length()-2);
145 }
146
147 return result;
148}
149
150bool StringToDouble(const char* string, double& value)
151{
152 std::istringstream buffer(string);
153
154 buffer.imbue(std::locale::classic());
155
156 buffer >> value;
157
158 return !buffer.fail() && !buffer.bad() && buffer.eof();
159}
160
161size_t GetHexDigitValue(char c)
162{
163 if (c>='0' && c<='9') {
164 return c-'0';
165 }
166 else if (c>='a' && c<='f') {
167 return 10+(c-'a');
168 }
169
170 assert(false);
171 return 0;
172}
173
174void AddFeatureToFilter(StyleFilter& filter,
175 const std::string& featureName,
176 const std::string& flagName,
177 TypeInfoSet& resultTypes)
178{
179 FeatureRef feature=config.GetTypeConfig()->GetFeature(featureName);
180
181 if (!feature) {
182 std::string e="Unknown feature '"+featureName+"'";
183
184 SemErr(e.c_str());
185 return;
186 }
187
188 size_t flagIndex=std::numeric_limits<size_t>::max();
189
190 if (!flagName.empty() &&
191 !feature->GetFlagIndex(flagName,
192 flagIndex)) {
193 std::string e="Unknown feature flag '"+featureName+"."+flagName+"'";
194
195 SemErr(e.c_str());
196 return;
197 }
198
199 for (const auto& type : config.GetTypeConfig()->GetTypes()) {
200 if (type->HasFeature(featureName)) {
201 if (!filter.FiltersByType() ||
202 filter.HasType(type)) {
203 // Add type only if the filter either has no types or
204 // if the type is already filtered
205 resultTypes.Set(type);
206 }
207 }
208 }
209
210 if (!resultTypes.Empty()) {
211 size_t featureFilterIndex=config.GetFeatureFilterIndex(*feature);
212
213 filter.AddFeature(featureFilterIndex,
214 flagIndex);
215 }
216}
217
218
219
220 Parser(Scanner *scanner,
221 const std::string& filename,
223 osmscout::ColorPostprocessor colorPostprocessor=nullptr,
224 const Log &log=osmscout::log);
226
227 void SemErr(const char* msg);
228 void SemWarning(const char* msg);
229
230 void OSS();
231 void IMPORTS();
233 void WAYORDER();
237 void IMPORT();
238 void STRING(std::string& value);
239 void FLAGBLOCK(bool state);
240 void FLAGDEF();
242 void IFCOND(bool& state);
243 void IDENT(std::string& value);
244 void BOOL(bool& value);
245 void WAYGROUP(size_t priority);
246 void POLYGON(Symbol& symbol);
247 void RECTANGLE(Symbol& symbol);
248 void CIRCLE(Symbol& symbol);
254 void COORD(Vertex2D& coord);
255 void UDOUBLE(double& value);
256 void DOUBLE(double& value);
257 void CONSTBLOCK(bool state);
259 void CONSTDEF();
264 void COLOR(Color& color);
265 void MAG(Magnification& magnification);
266 void UINT(size_t& value);
267 void STYLEBLOCK(StyleFilter filter, bool state);
268 void STYLE(StyleFilter filter, bool state);
269 void STYLECONDBLOCK(StyleFilter filter, bool state);
270 void STYLEFILTER(StyleFilter& filter);
271 void STYLEDEF(StyleFilter filter, bool state);
272 void STYLEFILTER_GROUP(StyleFilter& filter);
273 void STYLEFILTER_FEATURE(StyleFilter& filter);
274 void STYLEFILTER_PATH(StyleFilter& filter);
275 void STYLEFILTER_TYPE(StyleFilter& filter);
276 void STYLEFILTER_MAG(StyleFilter& filter);
277 void STYLEFILTER_ONEWAY(StyleFilter& filter);
278 void STYLEFILTER_SIZE(StyleFilter& filter);
279 void STYLEFILTER_FEATURE_ENTRY(StyleFilter& filter, TypeInfoSet& types);
281 void UMAP(double& width);
282 void NODESTYLEDEF(StyleFilter filter, bool state);
283 void WAYSTYLEDEF(StyleFilter filter, bool state);
284 void AREASTYLEDEF(StyleFilter filter, bool state);
285 void ROUTESTYLEDEF(StyleFilter filter, bool state);
286 void NODETEXTSTYLE(StyleFilter filter, bool state);
287 void NODEICONSTYLE(StyleFilter filter, bool state);
290 void WAYSTYLE(StyleFilter filter, bool state);
291 void WAYPATHTEXTSTYLE(StyleFilter filter, bool state);
292 void WAYPATHSYMBOLSTYLE(StyleFilter filter, bool state);
293 void WAYSHIELDSTYLE(StyleFilter filter, bool state);
295 void ROUTEPATHTEXTSTYLE(StyleFilter filter, bool state);
299 void AREASTYLE(StyleFilter filter, bool state);
300 void AREATEXTSTYLE(StyleFilter filter, bool state);
301 void AREAICONSTYLE(StyleFilter filter, bool state);
302 void AREABORDERSTYLE(StyleFilter filter, bool state);
303 void AREABORDERTEXTSTYLE(StyleFilter filter, bool state);
304 void AREABORDERSYMBOLSTYLE(StyleFilter filter, bool state);
305 void ROUTESTYLE(StyleFilter filter, bool state);
306 void ATTRIBUTE(PartialStyleBase& style, const StyleDescriptor& descriptor);
308 void COLOR_VALUE(Color& color);
309 void CONSTANT(StyleConstantRef& constant);
310
311 void Parse();
312
313};
314
315} // namespace
316} // namespace
317
318
319#endif // !defined(COCO_PARSER_H__)
320
Definition Logger.h:352
Definition Magnification.h:250
Definition StyleDescription.h:105
Index selectors by type and level.
Definition StyleConfig.h:552
Definition StyleDescription.h:478
Definition Parser.h:55
Type type
Definition Parser.h:65
std::string text
Definition Parser.h:68
Type
Definition Parser.h:57
@ Symbol
Definition Parser.h:58
@ Warning
Definition Parser.h:60
@ Exception
Definition Parser.h:61
@ Error
Definition Parser.h:59
int line
Definition Parser.h:66
int column
Definition Parser.h:67
Definition Parser.h:52
void Exception(const char *s)
void SynErr(int line, int col, int n)
bool hasErrors
Definition Parser.h:73
void Error(int line, int col, const char *s)
std::list< Err > errors
Definition Parser.h:72
Log log
Definition Parser.h:74
void Warning(const char *s)
Errors(const Log &log)
void Warning(int line, int col, const char *s)
void IDENT(std::string &value)
bool StringToDouble(const char *string, double &value)
Definition Parser.h:150
Parser(Scanner *scanner, const std::string &filename, StyleConfig &config, osmscout::ColorPostprocessor colorPostprocessor=nullptr, const Log &log=osmscout::log)
void DOUBLE(double &value)
void STYLEBLOCK(StyleFilter filter, bool state)
void ROUTESTYLEDEF(StyleFilter filter, bool state)
void NODESTYLEDEF(StyleFilter filter, bool state)
void FLAGCONDBLOCK(bool state)
void AREASYMBOLSTYLE(FillPartialStyle &fillStyle, BorderPartialStyle &borderStyle)
void STRING(std::string &value)
std::string Destring(const char *str)
Definition Parser.h:137
void WAYPATHSYMBOLSTYLE(StyleFilter filter, bool state)
void IFCOND(bool &state)
void STYLEFILTER(StyleFilter &filter)
void ATTRIBUTE(PartialStyleBase &style, const StyleDescriptor &descriptor)
std::string filename
Definition Parser.h:122
void ICONSTYLEATTR(IconPartialStyle &style)
void WAYSHIELDSTYLE(StyleFilter filter, bool state)
void NODETEXTSTYLE(StyleFilter filter, bool state)
void CONSTBLOCK(bool state)
void WAYSTYLEDEF(StyleFilter filter, bool state)
void NODEICONSTYLE(StyleFilter filter, bool state)
void CIRCLE(Symbol &symbol)
void AREAFILLSYMSTYLE(FillPartialStyle &fillStyle)
void WAYPATHTEXTSTYLE(StyleFilter filter, bool state)
void STYLEFILTER_GROUP(StyleFilter &filter)
void ATTRIBUTEVALUE(PartialStyleBase &style, const StyleAttributeDescriptor &descriptor)
void COLOR_VALUE(Color &color)
void FILLSTYLEATTR(FillPartialStyle &style)
void STYLEFILTER_ONEWAY(StyleFilter &filter)
void UDOUBLE(double &value)
void CONSTANT(StyleConstantRef &constant)
void SemErr(const char *msg)
void AREABORDERSYMSTYLE(BorderPartialStyle &borderStyle)
void AREASTYLEDEF(StyleFilter filter, bool state)
void TEXTSTYLEATTR(TextPartialStyle &style)
void AREASTYLE(StyleFilter filter, bool state)
void AREATEXTSTYLE(StyleFilter filter, bool state)
void FLAGBLOCK(bool state)
void PATHSHIELDSTYLEATTR(PathShieldPartialStyle &style)
void PATHSYMBOLSTYLEATTR(PathSymbolPartialStyle &style)
void STYLEFILTER_PATH(StyleFilter &filter)
MagnificationConverter magnificationConverter
Definition Parser.h:124
void BORDERSTYLEATTR(BorderPartialStyle &style)
void POLYGON(Symbol &symbol)
void AREABORDERSTYLE(StyleFilter filter, bool state)
void STYLEFILTER_FEATURE(StyleFilter &filter)
void AREABORDERTEXTSTYLE(StyleFilter filter, bool state)
void STYLE(StyleFilter filter, bool state)
size_t GetHexDigitValue(char c)
Definition Parser.h:161
void AREAICONSTYLE(StyleFilter filter, bool state)
void BOOL(bool &value)
void WAYSTYLE(StyleFilter filter, bool state)
void STYLECONDBLOCK(StyleFilter filter, bool state)
void ROUTEPATHTEXTSTYLE(StyleFilter filter, bool state)
void LINESTYLEATTR(LinePartialStyle &style)
void SemWarning(const char *msg)
void STYLEDEF(StyleFilter filter, bool state)
void CONSTCONDBLOCK(bool state)
void COORD(Vertex2D &coord)
void RECTANGLE(Symbol &symbol)
bool state
Definition Parser.h:125
void COLOR(Color &color)
void AREABORDERSYMBOLSTYLE(StyleFilter filter, bool state)
void ROUTESTYLE(StyleFilter filter, bool state)
void WAYGROUP(size_t priority)
ValueType
Definition Parser.h:128
@ NUMBER
Definition Parser.h:133
@ NO_VALUE
Definition Parser.h:129
Errors * errors
Definition Parser.h:120
void SIZECONDITION(SizeConditionRef &condition)
void UMAP(double &width)
void STYLEFILTER_TYPE(StyleFilter &filter)
void STYLEFILTER_MAG(StyleFilter &filter)
void STYLEFILTER_FEATURE_ENTRY(StyleFilter &filter, TypeInfoSet &types)
void UINT(size_t &value)
void MAG(Magnification &magnification)
void STYLEFILTER_SIZE(StyleFilter &filter)
void PATHTEXTSTYLEATTR(PathTextPartialStyle &style)
void AddFeatureToFilter(StyleFilter &filter, const std::string &featureName, const std::string &flagName, TypeInfoSet &resultTypes)
Definition Parser.h:174
StyleConfig & config
Definition Parser.h:123
Definition Scanner.h:154
OSMSCOUT_API Log log
Definition LoggerImpl.h:95
Definition Parser.h:48
std::shared_ptr< Token > TokenRef
Definition Scanner.h:43
Definition Area.h:39
PartialStyle< PathShieldStyle, PathShieldStyle::Attribute > PathShieldPartialStyle
Index selectors by type and level.
Definition StyleConfig.h:517
PartialStyle< PathTextStyle, PathTextStyle::Attribute > PathTextPartialStyle
Index selectors by type and level.
Definition StyleConfig.h:523
PartialStyle< TextStyle, TextStyle::Attribute > TextPartialStyle
Index selectors by type and level.
Definition StyleConfig.h:505
osmscout::Color(*)(const osmscout::Color &) ColorPostprocessor
Definition StyleConfig.h:54
PartialStyle< LineStyle, LineStyle::Attribute > LinePartialStyle
Definition StyleConfig.h:487
PartialStyle< BorderStyle, BorderStyle::Attribute > BorderPartialStyle
Index selectors by type and level.
Definition StyleConfig.h:499
PartialStyle< PathSymbolStyle, PathSymbolStyle::Attribute > PathSymbolPartialStyle
Index selectors by type and level.
Definition StyleConfig.h:535
std::shared_ptr< StyleConstant > StyleConstantRef
Definition StyleConfig.h:104
PartialStyle< IconStyle, IconStyle::Attribute > IconPartialStyle
Index selectors by type and level.
Definition StyleConfig.h:529
std::shared_ptr< Feature > FeatureRef
Definition TypeFeature.h:219
std::shared_ptr< SizeCondition > SizeConditionRef
Definition StyleConfig.h:220
PartialStyle< FillStyle, FillStyle::Attribute > FillPartialStyle
Index selectors by type and level.
Definition StyleConfig.h:493
Definition StyleConfig.h:353