1 /************************* Required for every parser *************************/
2 #ifndef OHCOUNT_XAML_PARSER_H
3 #define OHCOUNT_XAML_PARSER_H
5 #include "../parser_macros.h"
7 // the name of the language
8 const char *XAML_LANG = LANG_XAML;
10 // the languages entities
11 const char *xaml_entities[] = {
12 "space", "comment", "doctype",
13 "tag", "entity", "any"
16 // constants associated with the entities
18 XAML_SPACE = 0, XAML_COMMENT, XAML_DOCTYPE,
19 XAML_TAG, XAML_ENTITY, XAML_ANY
22 /*****************************************************************************/
27 include common "common.rl";
29 # Line counting machine
31 action xaml_ccallback {
40 std_internal_newline(XAML_LANG)
43 std_newline(XAML_LANG)
45 case CHECK_BLANK_ENTRY:
46 check_blank_entry(XAML_LANG)
52 newline %{ entity = INTERNAL_NL; } %xaml_ccallback
56 (nonnewline - ws) @comment
59 xaml_sq_str = '\'' [^\r\n\f']* '\'' @code;
60 xaml_dq_str = '"' [^\r\n\f"]* '"' @code;
63 newline %{ entity = INTERNAL_NL; } %xaml_ccallback
67 (nonnewline - ws) @code
69 xaml_string = xaml_sq_str | xaml_dq_str | xaml_cdata_str;
72 spaces ${ entity = XAML_SPACE; } => xaml_ccallback;
75 newline ${ entity = NEWLINE; } => xaml_ccallback;
76 ^space ${ entity = XAML_ANY; } => xaml_ccallback;
81 action xaml_ecallback {
82 callback(XAML_LANG, xaml_entities[entity], cint(ts), cint(te), userdata);
85 xaml_comment_entity = '<!--' any* :>> '-->';
88 space+ ${ entity = XAML_SPACE; } => xaml_ecallback;
89 xaml_comment_entity ${ entity = XAML_COMMENT; } => xaml_ecallback;
95 /************************* Required for every parser *************************/
97 /* Parses a string buffer with XAML markup.
99 * @param *buffer The string to parse.
100 * @param length The length of the string to parse.
101 * @param count Integer flag specifying whether or not to count lines. If yes,
102 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
103 * machine optimized for returning entity positions.
104 * @param *callback Callback function. If count is set, callback is called for
105 * every line of code, comment, or blank with 'lcode', 'lcomment', and
106 * 'lblank' respectively. Otherwise callback is called for each entity found.
108 void parse_xaml(char *buffer, int length, int count,
109 void (*callback) (const char *lang, const char *entity, int s,
116 cs = (count) ? xaml_en_xaml_line : xaml_en_xaml_entity;
119 // if no newline at EOF; callback contents of last line
120 if (count) { process_last_line(XAML_LANG) }
125 /*****************************************************************************/