1 // pike.rl written by Mitchell Foral. mitchell<att>caladbolg<dott>net.
3 /************************* Required for every parser *************************/
4 #ifndef OHCOUNT_PIKE_PARSER_H
5 #define OHCOUNT_PIKE_PARSER_H
7 #include "../parser_macros.h"
9 // the name of the language
10 const char *PIKE_LANG = LANG_PIKE;
12 // the languages entities
13 const char *pike_entities[] = {
14 "space", "comment", "string", "any"
17 // constants associated with the entities
19 PIKE_SPACE = 0, PIKE_COMMENT, PIKE_STRING, PIKE_ANY
22 /*****************************************************************************/
27 include common "common.rl";
29 # Line counting machine
31 action pike_ccallback {
40 std_internal_newline(PIKE_LANG)
43 std_newline(PIKE_LANG)
47 pike_line_comment = '//' @comment nonnewline*;
50 newline %{ entity = INTERNAL_NL; } %pike_ccallback
54 (nonnewline - ws) @comment
56 pike_comment = pike_line_comment | pike_block_comment;
58 pike_sq_str = '\'' @code ([^\r\n\f'\\] | '\\' nonnewline)* '\'';
59 pike_dq_str = '"' @code ([^\r\n\f"\\] | '\\' nonnewline)* '"';
60 pike_string = pike_sq_str | pike_dq_str;
63 spaces ${ entity = PIKE_SPACE; } => pike_ccallback;
66 newline ${ entity = NEWLINE; } => pike_ccallback;
67 ^space ${ entity = PIKE_ANY; } => pike_ccallback;
72 action pike_ecallback {
73 callback(PIKE_LANG, pike_entities[entity], cint(ts), cint(te), userdata);
76 pike_line_comment_entity = '//' nonnewline*;
77 pike_block_comment_entity = '/*' any* :>> '*/';
78 pike_comment_entity = pike_line_comment_entity | pike_block_comment_entity;
81 space+ ${ entity = PIKE_SPACE; } => pike_ecallback;
82 pike_comment_entity ${ entity = PIKE_COMMENT; } => pike_ecallback;
88 /************************* Required for every parser *************************/
90 /* Parses a string buffer with Pike code.
92 * @param *buffer The string to parse.
93 * @param length The length of the string to parse.
94 * @param count Integer flag specifying whether or not to count lines. If yes,
95 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
96 * machine optimized for returning entity positions.
97 * @param *callback Callback function. If count is set, callback is called for
98 * every line of code, comment, or blank with 'lcode', 'lcomment', and
99 * 'lblank' respectively. Otherwise callback is called for each entity found.
101 void parse_pike(char *buffer, int length, int count,
102 void (*callback) (const char *lang, const char *entity, int s,
109 cs = (count) ? pike_en_pike_line : pike_en_pike_entity;
112 // if no newline at EOF; callback contents of last line
113 if (count) { process_last_line(PIKE_LANG) }
118 /*****************************************************************************/