1 // css.rl written by Mitchell Foral. mitchell<att>caladbolg<dott>net.
3 /************************* Required for every parser *************************/
4 #ifndef OHCOUNT_CSS_PARSER_H
5 #define OHCOUNT_CSS_PARSER_H
7 #include "../parser_macros.h"
9 // the name of the language
10 const char *CSS_LANG = LANG_CSS;
12 // the languages entities
13 const char *css_entities[] = {
14 "space", "comment", "string", "at_rule", "selector",
15 "value", "unit", "color", "url", "any"
18 // constants associated with the entities
20 CSS_SPACE = 0, CSS_COMMENT, CSS_STRING, CSS_AT_RULE, CSS_SELECTOR,
21 CSS_VALUE, CSS_UNIT, CSS_COLOR, CSS_URL, CSS_ANY
24 /*****************************************************************************/
29 include common "common.rl";
31 # Line counting machine
33 action css_ccallback {
42 std_internal_newline(CSS_LANG)
51 newline %{ entity = INTERNAL_NL; } %css_ccallback
55 (nonnewline - ws) @comment
60 newline %{ entity = INTERNAL_NL; } %css_ccallback
70 newline %{ entity = INTERNAL_NL; } %css_ccallback
78 css_string = css_sq_str | css_dq_str;
81 spaces ${ entity = CSS_SPACE; } => css_ccallback;
84 newline ${ entity = NEWLINE; } => css_ccallback;
85 ^space ${ entity = CSS_ANY; } => css_ccallback;
90 action css_ecallback {
91 callback(CSS_LANG, css_entities[entity], cint(ts), cint(te), userdata);
94 css_comment_entity = '/*' any* :>> '*/';
97 space+ ${ entity = CSS_SPACE; } => css_ecallback;
98 css_comment_entity ${ entity = CSS_COMMENT; } => css_ecallback;
104 /************************* Required for every parser *************************/
106 /* Parses a string buffer with CSS code.
108 * @param *buffer The string to parse.
109 * @param length The length of the string to parse.
110 * @param count Integer flag specifying whether or not to count lines. If yes,
111 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
112 * machine optimized for returning entity positions.
113 * @param *callback Callback function. If count is set, callback is called for
114 * every line of code, comment, or blank with 'lcode', 'lcomment', and
115 * 'lblank' respectively. Otherwise callback is called for each entity found.
117 void parse_css(char *buffer, int length, int count,
118 void (*callback) (const char *lang, const char *entity, int s,
125 cs = (count) ? css_en_css_line : css_en_css_entity;
128 // if no newline at EOF; callback contents of last line
129 if (count) { process_last_line(CSS_LANG) }
134 /*****************************************************************************/