Fixes recursion bug in disambiguate_in().
[ohcount] / src / parsers / idl_pvwave.rl
1 // idl_pvwave.rl written by Sylwester Arabas. slayoo<att>igf<dott>fuw<dott>edu<dott>pl.
2 // (it's the tex.rl file with the comment symbol changed from "%" into ";")
3
4 /************************* Required for every parser *************************/
5 #ifndef RAGEL_IDL_PVWAVE_PARSER
6 #define RAGEL_IDL_PVWAVE_PARSER
7
8 #include "../parser_macros.h"
9
10 // the name of the language
11 const char *IDL_PVWAVE_LANG = "idl_pvwave";
12
13 // the languages entities
14 const char *idl_pvwave_entities[] = {
15   "space", "comment", "string", "any"
16 };
17
18 // constants associated with the entities
19 enum {
20   IDL_PVWAVE_SPACE = 0, IDL_PVWAVE_COMMENT, IDL_PVWAVE_STRING, IDL_PVWAVE_ANY
21 };
22
23 /*****************************************************************************/
24
25 %%{
26   machine idl_pvwave;
27   write data;
28   include common "common.rl";
29
30   # Line counting machine
31
32   action idl_pvwave_ccallback {
33     switch(entity) {
34     case IDL_PVWAVE_SPACE:
35       ls
36       break;
37     case IDL_PVWAVE_ANY:
38       code
39       break;
40     case INTERNAL_NL:
41       std_internal_newline(IDL_PVWAVE_LANG)
42       break;
43     case NEWLINE:
44       std_newline(IDL_PVWAVE_LANG)
45     }
46   }
47
48   idl_pvwave_comment = ';' @comment nonnewline*;
49
50   idl_pvwave_line := |*
51     spaces       ${ entity = IDL_PVWAVE_SPACE; } => idl_pvwave_ccallback;
52     idl_pvwave_comment;
53     newline      ${ entity = NEWLINE;   } => idl_pvwave_ccallback;
54     ^space       ${ entity = IDL_PVWAVE_ANY;   } => idl_pvwave_ccallback;
55   *|;
56
57   # Entity machine
58
59   action idl_pvwave_ecallback {
60     callback(IDL_PVWAVE_LANG, idl_pvwave_entities[entity], cint(ts), cint(te), userdata);
61   }
62
63   idl_pvwave_comment_entity = ';' nonnewline*;
64
65   idl_pvwave_entity := |*
66     space+             ${ entity = IDL_PVWAVE_SPACE;   } => idl_pvwave_ecallback;
67     idl_pvwave_comment_entity ${ entity = IDL_PVWAVE_COMMENT; } => idl_pvwave_ecallback;
68     # TODO:
69     ^space;
70   *|;
71 }%%
72
73 /************************* Required for every parser *************************/
74
75 /* Parses a string buffer with IDL_PVWAVE markup.
76  *
77  * @param *buffer The string to parse.
78  * @param length The length of the string to parse.
79  * @param count Integer flag specifying whether or not to count lines. If yes,
80  *   uses the Ragel machine optimized for counting. Otherwise uses the Ragel
81  *   machine optimized for returning entity positions.
82  * @param *callback Callback function. If count is set, callback is called for
83  *   every line of code, comment, or blank with 'lcode', 'lcomment', and
84  *   'lblank' respectively. Otherwise callback is called for each entity found.
85  */
86 void parse_idl_pvwave(char *buffer, int length, int count,
87   void (*callback) (const char *lang, const char *entity, int start, int end, void *udata),
88   void *userdata
89   ) {
90   init
91
92   %% write init;
93   cs = (count) ? idl_pvwave_en_idl_pvwave_line : idl_pvwave_en_idl_pvwave_entity;
94   %% write exec;
95
96   // if no newline at EOF; callback contents of last line
97   if (count) { process_last_line(IDL_PVWAVE_LANG) }
98 }
99
100 #endif
101
102 /*****************************************************************************/