aboutsummaryrefslogtreecommitdiff
path: root/src/cssparser.hh
blob: 8be8c8a5b3cd543d5828af73f1ac70305843caf4 (plain)
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
#ifndef __CSSPARSER_HH__
#define __CSSPARSER_HH__

#include "css.hh"

typedef struct {
   const char *symbol;
   const CssValueType type[3];
   const char *const *enum_symbols;
} CssPropertyInfo;

extern const CssPropertyInfo Css_property_info[CSS_PROPERTY_LAST];

typedef enum {
   CSS_TK_DECINT, CSS_TK_FLOAT, CSS_TK_COLOR, CSS_TK_SYMBOL, CSS_TK_STRING,
   CSS_TK_CHAR, CSS_TK_END
} CssTokenType;

class CssParser {
   private:
      static const int maxStrLen = 256;
      CssContext *context;
      CssOrigin origin;

      const char *buf;
      int buflen, bufptr;

      CssTokenType ttype;
      char tval[maxStrLen];
      bool within_block;
      bool space_separated; /* used when parsing CSS selectors */

      CssParser(CssContext *context, CssOrigin origin,
                const char *buf, int buflen);
      int getc();
      void ungetc();
      void nextToken();
      bool tokenMatchesProperty(CssPropertyName prop, CssValueType * type);
      bool parseValue(CssPropertyName prop, CssValueType type,
                      CssPropertyValue * val);
      bool parseWeight();
      void parseDeclaration(CssPropertyList * props,
                            CssPropertyList * importantProps);
      bool parseSimpleSelector(CssSimpleSelector *selector);
      CssSelector *parseSelector();
      void parseRuleset();

   public:
      static CssPropertyList *parseDeclarationBlock(const char *buf, int buflen);
      static void parse(CssContext *context, const char *buf, int buflen,
                        CssOrigin origin);
};

#endif