grafthistory: support curl
[elinks/elinks-j605.git] / src / document / css / scanner.h
blob4820a0a636f3ad73abf75d9af47275d7240a9ccf
2 #ifndef EL__DOCUMENT_CSS_SCANNER_H
3 #define EL__DOCUMENT_CSS_SCANNER_H
5 #include "util/scanner.h"
7 /* The various token types and what they contain. Patterns taken from
8 * the flex scanner declarations in the CSS 2 Specification. */
9 enum css_token_type {
10 /* Char tokens: */
12 /* Char tokens range from 1 to 255 and have their char value as type */
13 /* meaning non char tokens have values from 256 and up. */
15 /* Low level string tokens: */
17 /* {...} means char group, <...> means token */
18 /* {identstart} [a-z_]|{nonascii} */
19 /* {ident} [a-z0-9_-]|{nonascii} */
20 /* <ident> {identstart}{ident}* */
21 /* <name> {ident}+ */
22 /* <number> [0-9]+|[0-9]*"."[0-9]+ */
24 /* Percentage is put because although it looks like being composed of
25 * <number> and '%' floating point numbers are really not allowed but
26 * strtol() will round it down for us ;) */
27 CSS_TOKEN_IDENT = 256, /* <ident> */
28 CSS_TOKEN_NUMBER, /* <number> */
29 CSS_TOKEN_PERCENTAGE, /* <number>% */
30 CSS_TOKEN_STRING, /* Char sequence delimted by matching ' or " */
32 /* High level string tokens: */
34 /* The various number values; dimension being the most generic */
35 CSS_TOKEN_ANGLE, /* <number>rad, <number>grad or <number>deg */
36 CSS_TOKEN_DIMENSION, /* <number><ident> */
37 CSS_TOKEN_EM, /* <number>em */
38 CSS_TOKEN_EX, /* <number>ex */
39 CSS_TOKEN_FREQUENCY, /* <number>Hz or <number>kHz */
40 CSS_TOKEN_LENGTH, /* <number>{px,cm,mm,in,pt,pc} */
41 CSS_TOKEN_TIME, /* <number>ms or <number>s */
43 /* XXX: CSS_TOKEN_HASH conflicts with CSS_TOKEN_HEX_COLOR. Generating
44 * hex color tokens has precedence and the hash token user have to
45 * treat CSS_TOKEN_HASH and CSS_TOKEN_HEX_COLOR alike. */
46 CSS_TOKEN_HASH, /* #<name> */
47 CSS_TOKEN_HEX_COLOR, /* #[0-9a-f]\{3,6} */
49 /* For all unknown functions we generate on token contain both function name
50 * and args so scanning/parsing is easier. Besides we already check for
51 * ending ')'. */
52 /* For known functions where we need several args [like rgb()] we want
53 * to generate tokens for every arg and arg delimiter ( ',' or ')' ).
54 * Because url() is a bit triggy: it can contain both <string> and some
55 * chars that would other wise make the scanner probably choke we also
56 * include the arg in that token. Besides it will make things like
57 * 'background' property parsing easier. */
58 CSS_TOKEN_FUNCTION, /* <ident>(<args>) */
59 CSS_TOKEN_RGB, /* rgb( */
60 CSS_TOKEN_URL, /* url(<arg>) */
62 /* @-rule symbols */
63 CSS_TOKEN_AT_KEYWORD, /* @<ident> */
64 CSS_TOKEN_AT_CHARSET, /* @charset */
65 CSS_TOKEN_AT_FONT_FACE, /* @font-face */
66 CSS_TOKEN_AT_IMPORT, /* @import */
67 CSS_TOKEN_AT_MEDIA, /* @media */
68 CSS_TOKEN_AT_PAGE, /* @page */
70 CSS_TOKEN_IMPORTANT, /* !<whitespace>important */
72 /* TODO: Selector stuff: */
73 CSS_TOKEN_SELECT_SPACE_LIST, /* ~= */
74 CSS_TOKEN_SELECT_HYPHEN_LIST, /* |= */
75 CSS_TOKEN_SELECT_BEGIN, /* ^= */
76 CSS_TOKEN_SELECT_END, /* $= */
77 CSS_TOKEN_SELECT_CONTAINS, /* *= */
79 /* Special tokens: */
81 /* A special token for unrecognized strings */
82 CSS_TOKEN_GARBAGE,
84 /* Token type used internally when scanning to signal that the token
85 * should not be recorded in the scanners token table. */
86 CSS_TOKEN_SKIP,
88 /* Another internal token type used both to mark unused tokens in the
89 * scanner table as invalid or when scanning to signal that the
90 * scanning should end. */
91 CSS_TOKEN_NONE = 0,
94 extern struct scanner_info css_scanner_info;
96 #define skip_css_tokens(scanner, type) \
97 skip_scanner_tokens(scanner, type, get_css_precedence(type))
99 #define get_css_precedence(token_type) \
100 ((token_type) == '}' ? (1 << 10) : \
101 (token_type) == '{' ? (1 << 9) : \
102 (token_type) == ';' ? (1 << 8) : \
103 (token_type) == ')' ? (1 << 7) : 0)
105 /* Check whether it is safe to skip the @token when looking for @skipto. */
106 static inline int
107 check_css_precedence(int type, int skipto)
109 return get_css_precedence(type) < get_css_precedence(skipto);
112 #endif