1 // objective_c.rl written by Mitchell Foral. mitchell<att>caladbolg<dott>net.
3 /************************* Required for every parser *************************/
4 #ifndef OHCOUNT_OBJECTIVE_C_PARSER_H
5 #define OHCOUNT_OBJECTIVE_C_PARSER_H
7 #include "../parser_macros.h"
9 // the name of the language
10 const char *OBJC_LANG = LANG_OBJECTIVE_C;
12 // the languages entities
13 const char *objc_entities[] = {
14 "space", "comment", "string", "any"
17 // constants associated with the entities
19 OBJC_SPACE = 0, OBJC_COMMENT, OBJC_STRING, OBJC_ANY,
22 /*****************************************************************************/
27 include common "common.rl";
29 # Line counting machine
31 action objc_ccallback {
40 std_internal_newline(OBJC_LANG)
43 std_newline(OBJC_LANG)
49 escaped_newline %{ entity = INTERNAL_NL; } %objc_ccallback
53 (nonnewline - ws) @comment
57 newline %{ entity = INTERNAL_NL; } %objc_ccallback
61 (nonnewline - ws) @comment
63 objc_comment = objc_line_comment | objc_block_comment;
65 objc_sq_str = '\'' @code ([^\r\n\f'\\] | '\\' nonnewline)* '\'';
66 objc_dq_str = '"' @code ([^\r\n\f"\\] | '\\' nonnewline)* '"';
67 objc_string = objc_sq_str | objc_dq_str;
70 spaces ${ entity = OBJC_SPACE; } => objc_ccallback;
73 newline ${ entity = NEWLINE; } => objc_ccallback;
74 ^space ${ entity = OBJC_ANY; } => objc_ccallback;
79 action objc_ecallback {
80 callback(OBJC_LANG, objc_entities[entity], cint(ts), cint(te), userdata);
83 objc_line_comment_entity = '//' (escaped_newline | nonnewline)*;
84 objc_block_comment_entity = '/*' any* :>> '*/';
85 objc_comment_entity = objc_line_comment_entity | objc_block_comment_entity;
88 space+ ${ entity = OBJC_SPACE; } => objc_ecallback;
89 objc_comment_entity ${ entity = OBJC_COMMENT; } => objc_ecallback;
95 /************************* Required for every parser *************************/
97 /* Parses a string buffer with Objective C code.
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_objective_c(char *buffer, int length, int count,
109 void (*callback) (const char *lang, const char *entity,
110 int s, int e, void *udata),
116 cs = (count) ? objective_c_en_objc_line : objective_c_en_objc_entity;
119 // if no newline at EOF; callback contents of last line
120 if (count) { process_last_line(OBJC_LANG) }
125 /*****************************************************************************/