Initial import of files for generating Doxygen documentation.
[ohcount] / src / parsers / xaml.rl
1 /************************* Required for every parser *************************/
2 #ifndef OHCOUNT_XAML_PARSER_H
3 #define OHCOUNT_XAML_PARSER_H
4
5 #include "../parser_macros.h"
6
7 // the name of the language
8 const char *XAML_LANG = LANG_XAML;
9
10 // the languages entities
11 const char *xaml_entities[] = {
12   "space", "comment", "doctype",
13   "tag", "entity", "any"
14 };
15
16 // constants associated with the entities
17 enum {
18   XAML_SPACE = 0, XAML_COMMENT, XAML_DOCTYPE,
19   XAML_TAG, XAML_ENTITY, XAML_ANY
20 };
21
22 /*****************************************************************************/
23
24 %%{
25   machine xaml;
26   write data;
27   include common "common.rl";
28
29   # Line counting machine
30
31   action xaml_ccallback {
32     switch(entity) {
33     case XAML_SPACE:
34       ls
35       break;
36     case XAML_ANY:
37       code
38       break;
39     case INTERNAL_NL:
40       std_internal_newline(XAML_LANG)
41       break;
42     case NEWLINE:
43       std_newline(XAML_LANG)
44       break;
45     case CHECK_BLANK_ENTRY:
46       check_blank_entry(XAML_LANG)
47     }
48   }
49
50   xaml_comment =
51     '<!--' @comment (
52       newline %{ entity = INTERNAL_NL; } %xaml_ccallback
53       |
54       ws
55       |
56       (nonnewline - ws) @comment
57     )* :>> '-->';
58
59   xaml_sq_str = '\'' [^\r\n\f']* '\'' @code;
60   xaml_dq_str = '"' [^\r\n\f"]* '"' @code;
61   xaml_cdata_str =
62     '<![CDATA[' @code (
63       newline %{ entity = INTERNAL_NL; } %xaml_ccallback
64       |
65       ws
66       |
67       (nonnewline - ws) @code
68     )* :>> ']]>';
69   xaml_string = xaml_sq_str | xaml_dq_str | xaml_cdata_str;
70
71   xaml_line := |*
72     spaces       ${ entity = XAML_SPACE; } => xaml_ccallback;
73     xaml_comment;
74     xaml_string;
75     newline      ${ entity = NEWLINE;   } => xaml_ccallback;
76     ^space       ${ entity = XAML_ANY;   } => xaml_ccallback;
77   *|;
78
79   # Entity machine
80
81   action xaml_ecallback {
82     callback(XAML_LANG, xaml_entities[entity], cint(ts), cint(te), userdata);
83   }
84
85   xaml_comment_entity = '<!--' any* :>> '-->';
86
87   xaml_entity := |*
88     space+             ${ entity = XAML_SPACE;   } => xaml_ecallback;
89     xaml_comment_entity ${ entity = XAML_COMMENT; } => xaml_ecallback;
90     # TODO:
91     ^space;
92   *|;
93 }%%
94
95 /************************* Required for every parser *************************/
96
97 /* Parses a string buffer with XAML markup.
98  *
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.
107  */
108 void parse_xaml(char *buffer, int length, int count,
109                 void (*callback) (const char *lang, const char *entity, int s,
110                                   int e, void *udata),
111                 void *userdata
112   ) {
113   init
114
115   %% write init;
116   cs = (count) ? xaml_en_xaml_line : xaml_en_xaml_entity;
117   %% write exec;
118
119   // if no newline at EOF; callback contents of last line
120   if (count) { process_last_line(XAML_LANG) }
121 }
122
123 #endif
124
125 /*****************************************************************************/