File: css_parser.h

package info (click to toggle)
gpick 0.2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,400 kB
  • ctags: 3,306
  • sloc: cpp: 22,216; python: 740; ansic: 476; yacc: 252; lex: 197; makefile: 49; xml: 11; sh: 8
file content (220 lines) | stat: -rw-r--r-- 5,849 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*
 * Copyright (c) 2009-2012, Albertas Vyšniauskas
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
 *
 *     * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
 *     * Neither the name of the software author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef CSS_PARSER_H
#define CSS_PARSER_H

#ifndef _MSC_VER
#include <stdbool.h>
#endif
#include <stdint.h>
#include <stdio.h>

#include <list>

#include "memory_manager.h"

typedef struct parse_parm_s parse_parm;

namespace css_parser {
class css_file;
class css_base;
}

typedef struct parse_parm_s{
	css_parser::css_file *page;
	struct Memory* memory;

	uint32_t first_line;
	uint32_t first_column;
	uint32_t last_line;
	uint32_t last_column;
	uint32_t position;
}parse_parm;

int parse(FILE* f, int *result);

#define YY_EXTRA_TYPE   parse_parm*

#ifndef YYSTYPE
typedef union css_yystype{
	css_parser::css_base *base;
	char* string;
	uint32_t number;
} css_yystype;
# define YYSTYPE css_yystype
# define YYSTYPE_IS_TRIVIAL 1
# define YYSTYPE_IS_DECLARED 1
#endif

/* extern YYSTYPE yylval; */
//YYSTYPE yylval;

/*#define YY_EXTRA_TYPE   parse_parm* */

/* Initialize LOC. */
# define CSS_LOCATION_RESET(Loc)                  	\
	(Loc).first_column = (Loc).first_line = 1;  		\
	(Loc).last_column =  (Loc).last_line = 1;			\
	(Loc).position=0;

/* Advance of NUM lines. */
# define CSS_LOCATION_LINES(Loc, Num)             \
  (Loc).last_column = 1;                      \
  (Loc).last_line += Num;

/* Restart: move the first cursor to the last position. */
# define CSS_LOCATION_STEP(Loc)                   \
  (Loc).first_column = (Loc).last_column;     \
  (Loc).first_line = (Loc).last_line;

/* Output LOC on the stream OUT. */
# define CSS_LOCATION_PRINT(Out, Loc)                               \
  if ((Loc).first_line != (Loc).last_line)                      \
    fprintf (Out, "%d.%d-%d.%d",                                \
             (Loc).first_line, (Loc).first_column,              \
             (Loc).last_line, (Loc).last_column - 1);           \
  else if ((Loc).first_column < (Loc).last_column - 1)          \
    fprintf (Out, "%d.%d-%d", (Loc).first_line,                 \
             (Loc).first_column, (Loc).last_column - 1);        \
  else                                                          \
    fprintf (Out, "%d.%d", (Loc).first_line, (Loc).first_column)


namespace css_parser {

class css_base{
public:
	css_base();

	void* operator new(size_t num_bytes, parse_parm* parm);
	void operator delete(void* base, parse_parm* parm);

	virtual void polymorphic();
};

class css_property: public css_base{
public:
	const char* name_;
	std::list<css_base*> values_;

	css_property(const char* name);

	void addValue(css_base* value);
};

class css_properties: public css_base{
public:
	std::list<css_property*> properties_;

	css_properties();

	void addProperty(css_property* property);
};

class css_simple_selector: public css_base{
public:
	const char* name_;

	css_simple_selector(const char* name);
};

class css_selector: public css_base{
public:
	std::list<css_simple_selector*> simple_selectors_;

	css_selector();

	void addSimpleSelector(css_simple_selector* simple_selector);
	void addSelector(css_selector* selector);
	void prependSimpleSelector(css_simple_selector* simple_selector);
};

class css_selectors: public css_base{
public:
	std::list<css_selector*> selectors_;

	css_selectors();

	void addSelector(css_selector* selector);
};

class css_ruleset: public css_base{
public:
	std::list<css_selector*> selectors_;
	std::list<css_property*> properties_;

	css_ruleset();

	void addSelector(css_selector* selector);
	void setSelectors(std::list<css_selector*> &selectors);
	void addProperty(css_property* property);
	void addProperties(css_properties* properties);
};

class css_file: public css_base{
public:
	std::list<css_ruleset*> rulesets_;

	css_file();

	void addRuleset(css_ruleset* ruleset);
};

class css_function: public css_base{
public:
	const char* name_;
	std::list<css_base*> arguments_;

	css_function(const char* name);

	void addArgument(css_base* argument);
};

class css_hex: public css_base{
public:
	uint32_t value_;
	css_hex(uint32_t value);
	css_hex(const char *value);
};

class css_number: public css_base{
public:
	double value_;
	css_number(double value);
};

class css_percentage: public css_base{
public:
	double value_;
	css_percentage(double value);
};

class css_string: public css_base{
public:
	const char* value_;
	css_string(const char* value);
};

}

int parse_file(const char *filename);


#endif