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_ost_PARSER_H)
22#define osmscout_ost_PARSER_H
23
24#include <osmscout/TypeConfig.h>
25
27
28#include <osmscout/io/File.h>
30
32
33namespace osmscout {
34namespace ost {
35
36
37class Errors
38{
39public:
40 class Err
41 {
42 public:
49
50 public:
52 int line;
53 int column;
54 std::string text;
55 };
56
57public:
58 std::list<Err> errors;
60
61public:
63 void SynErr(int line, int col, int n);
64 void Error(int line, int col, const char *s);
65 void Warning(int line, int col, const char *s);
66 void Warning(const char *s);
67 void Exception(const char *s);
68};
69
70class Parser
71{
72private:
73 enum {
74 _EOF=0,
75 _ident=1,
76 _number=2,
77 _string=3
78 };
79 int maxT;
80
81 TokenRef dummyToken;
82 int errDist;
83 int minErrDist;
84
85 void SynErr(int n);
86 void Get();
87 void Expect(int n);
88 bool StartOf(int s);
89 void ExpectWeak(int n, int follow);
90 bool WeakSeparator(int n, int syFol, int repFol);
91
92 Scanner *scanner;
93
94 TokenRef t; // last recognized token
95 TokenRef la; // lookahead token
96
97 std::string filename;
98 TypeConfig& config;
99
100public:
102
103std::string Destring(const char* str)
104{
105 std::string result(str);
106
107 if (result.length()>=2 &&
108 result[0]=='"' &&
109 result[result.length()-1]=='"') {
110 result=result.substr(1,result.length()-2);
111 }
112
113 return result;
114}
115
116
117
118 Parser(Scanner *scanner,
119 const std::string& filename,
120 TypeConfig& config);
122 void SemErr(const char* msg);
123
124 void OST();
125 void IMPORTS();
126 void MAXSPEEDS();
127 void GRADES();
128 void FEATURES();
129 void TYPES();
130 void IMPORT();
131 void STRING(std::string& value);
132 void MAXSPEED();
133 void UINT(size_t& value);
134 void GRADE();
135 void FEATURE();
136 void IDENT(std::string& value);
137 void FEATUREDESCS(Feature& feature);
138 void TYPE();
139 void TYPEKINDS(unsigned char& types);
141 void TYPEFEATURE(TypeInfo& typeInfo);
142 void SPECIALTYPE(TypeInfo& typeInfo);
143 void TYPEOPTIONS(TypeInfo& typeInfo);
144 void GROUPS(TypeInfo& typeInfo);
145 void TYPEDESCS(TypeInfo& typeInfo);
146 void TAGANDCOND(TagConditionRef& condition);
147 void TAGBOOLCOND(TagConditionRef& condition);
148 void TAGBINCOND(TagConditionRef& condition);
150 void TAGLESSCOND(const std::string& tagName,TagConditionRef& condition);
151 void TAGLESSEQUALCOND(const std::string& tagName,TagConditionRef& condition);
152 void TAGEQUALSCOND(const std::string& tagName,TagConditionRef& condition);
153 void TAGNOTEQUALSCOND(const std::string& tagName,TagConditionRef& condition);
154 void TAGGREATERCOND(const std::string& tagName,TagConditionRef& condition);
155 void TAGGREATEREQUALCOND(const std::string& tagName,TagConditionRef& condition);
156 void TAGISINCOND(const std::string& tagName,TagConditionRef& condition);
157 void TYPEKIND(unsigned char& types);
158 void TYPEOPTION(TypeInfo& typeInfo);
159 void PATH(TypeInfo& typeInfo);
160 void LANES(TypeInfo& typeInfo);
161 void UINT8(uint8_t& value);
162
163 void Parse();
164};
165
166} // namespace
167} // namespace
168
169
170#endif // !defined(COCO_PARSER_H__)
Definition TypeFeature.h:99
Definition Parser.h:41
Type
Definition Parser.h:43
@ Symbol
Definition Parser.h:44
@ Error
Definition Parser.h:45
@ Warning
Definition Parser.h:46
@ Exception
Definition Parser.h:47
Type type
Definition Parser.h:51
int column
Definition Parser.h:53
int line
Definition Parser.h:52
std::string text
Definition Parser.h:54
Definition Parser.h:38
void Warning(int line, int col, const char *s)
bool hasErrors
Definition Parser.h:59
std::list< Err > errors
Definition Parser.h:58
void SynErr(int line, int col, int n)
void Exception(const char *s)
void Warning(const char *s)
void Error(int line, int col, const char *s)
void SemErr(const char *msg)
void TAGBOOLCOND(TagConditionRef &condition)
Errors * errors
Definition Parser.h:101
void TAGLESSEQUALCOND(const std::string &tagName, TagConditionRef &condition)
void TAGISINCOND(const std::string &tagName, TagConditionRef &condition)
void TAGLESSCOND(const std::string &tagName, TagConditionRef &condition)
void FEATUREDESCS(Feature &feature)
void UINT(size_t &value)
void SPECIALTYPE(TypeInfo &typeInfo)
void STRING(std::string &value)
void TYPEDESCS(TypeInfo &typeInfo)
void TAGBINCOND(TagConditionRef &condition)
std::string Destring(const char *str)
Definition Parser.h:103
void TYPEOPTIONS(TypeInfo &typeInfo)
void TAGEXISTSCOND(TagConditionRef &condition)
Parser(Scanner *scanner, const std::string &filename, TypeConfig &config)
void GROUPS(TypeInfo &typeInfo)
void TYPEFEATURE(TypeInfo &typeInfo)
void PATH(TypeInfo &typeInfo)
void TAGANDCOND(TagConditionRef &condition)
void TAGNOTEQUALSCOND(const std::string &tagName, TagConditionRef &condition)
void TYPEKIND(unsigned char &types)
void TAGGREATEREQUALCOND(const std::string &tagName, TagConditionRef &condition)
void UINT8(uint8_t &value)
void TYPEOPTION(TypeInfo &typeInfo)
void TAGEQUALSCOND(const std::string &tagName, TagConditionRef &condition)
void TYPEKINDS(unsigned char &types)
void LANES(TypeInfo &typeInfo)
void TAGGREATERCOND(const std::string &tagName, TagConditionRef &condition)
void TAGCONDITION(TagConditionRef &condition)
void IDENT(std::string &value)
Definition Scanner.h:139
std::shared_ptr< TagCondition > TagConditionRef
Definition Tag.h:68
Definition Parser.h:34
std::shared_ptr< Token > TokenRef
Definition Scanner.h:43
Definition Area.h:39