1 // clearsilver.rl written by Mitchell Foral. mitchell<att>caladbolg<dott>net.
3 /************************* Required for every parser *************************/
4 #ifndef OHCOUNT_CS_PARSER_H
5 #define OHCOUNT_CS_PARSER_H
7 #include "../parser_macros.h"
9 // the name of the language
10 const char *CS_LANG = LANG_CLEARSILVER;
12 // the languages entities
13 const char *cs_entities[] = {
14 "space", "comment", "string", "any"
17 // constants associated with the entities
19 CS_SPACE = 0, CS_COMMENT, CS_STRING, CS_ANY
22 /*****************************************************************************/
27 include common "common.rl";
29 # Line counting machine
40 std_internal_newline(CS_LANG)
47 cs_comment = '#' @comment nonnewline*;
49 cs_string = '"' @code ([^\r\n\f"\\] | '\\' nonnewline)* '"';
52 spaces ${ entity = CS_SPACE; } => cs_ccallback;
55 newline ${ entity = NEWLINE; } => cs_ccallback;
56 ^space ${ entity = CS_ANY; } => cs_ccallback;
62 callback(CS_LANG, cs_entities[entity], cint(ts), cint(te), userdata);
65 cs_comment_entity = '#' nonnewline*;
68 space+ ${ entity = CS_SPACE; } => cs_ecallback;
69 cs_comment_entity ${ entity = CS_COMMENT; } => cs_ecallback;
75 /************************* Required for every parser *************************/
77 /* Parses a string buffer with Clearsilver code (not in HTML).
79 * @param *buffer The string to parse.
80 * @param length The length of the string to parse.
81 * @param count Integer flag specifying whether or not to count lines. If yes,
82 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
83 * machine optimized for returning entity positions.
84 * @param *callback Callback function. If count is set, callback is called for
85 * every line of code, comment, or blank with 'lcode', 'lcomment', and
86 * 'lblank' respectively. Otherwise callback is called for each entity found.
88 void parse_clearsilver(char *buffer, int length, int count,
89 void (*callback) (const char *lang, const char *entity,
90 int s, int e, void *udata),
96 cs = (count) ? clearsilver_en_cs_line : clearsilver_en_cs_entity;
99 // if no newline at EOF; callback contents of last line
100 if (count) { process_last_line(CS_LANG) }
105 /*****************************************************************************/