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