1 // objective_j.rl written by Francisco tolmasky. francisco<att>280north<dott>com.
2 // Modified from file by Mitchell Foral. mitchell<att>caladbolg<dott>net.
4 /************************* Required for every parser *************************/
5 #ifndef OHCOUNT_OBJECTIVE_J_PARSER_H
6 #define OHCOUNT_OBJECTIVE_J_PARSER_H
8 #include "../parser_macros.h"
10 // the name of the language
11 const char *OBJJ_LANG = LANG_OBJECTIVE_J;
13 // the languages entities
14 const char *objj_entities[] = {
15 "space", "comment", "string", "any"
18 // constants associated with the entities
20 OBJJ_SPACE = 0, OBJJ_COMMENT, OBJJ_STRING, OBJJ_ANY,
23 /*****************************************************************************/
28 include common "common.rl";
30 # Line counting machine
32 action objj_ccallback {
41 std_internal_newline(OBJJ_LANG)
44 std_newline(OBJJ_LANG)
50 escaped_newline %{ entity = INTERNAL_NL; } %objj_ccallback
54 (nonnewline - ws) @comment
58 newline %{ entity = INTERNAL_NL; } %objj_ccallback
62 (nonnewline - ws) @comment
64 objj_comment = objj_line_comment | objj_block_comment;
66 objj_sq_str = '\'' @code ([^\r\n\f'\\] | '\\' nonnewline)* '\'';
67 objj_dq_str = '"' @code ([^\r\n\f"\\] | '\\' nonnewline)* '"';
68 objj_string = objj_sq_str | objj_dq_str;
71 spaces ${ entity = OBJJ_SPACE; } => objj_ccallback;
74 newline ${ entity = NEWLINE; } => objj_ccallback;
75 ^space ${ entity = OBJJ_ANY; } => objj_ccallback;
80 action objj_ecallback {
81 callback(OBJJ_LANG, objj_entities[entity], cint(ts), cint(te), userdata);
84 objj_line_comment_entity = '//' (escaped_newline | nonnewline)*;
85 objj_block_comment_entity = '/*' any* :>> '*/';
86 objj_comment_entity = objj_line_comment_entity | objj_block_comment_entity;
89 space+ ${ entity = OBJJ_SPACE; } => objj_ecallback;
90 objj_comment_entity ${ entity = OBJJ_COMMENT; } => objj_ecallback;
96 /************************* Required for every parser *************************/
98 /* Parses a string buffer with Objective C code.
100 * @param *buffer The string to parse.
101 * @param length The length of the string to parse.
102 * @param count Integer flag specifying whether or not to count lines. If yes,
103 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
104 * machine optimized for returning entity positions.
105 * @param *callback Callback function. If count is set, callback is called for
106 * every line of code, comment, or blank with 'lcode', 'lcomment', and
107 * 'lblank' respectively. Otherwise callback is called for each entity found.
109 void parse_objective_j(char *buffer, int length, int count,
110 void (*callback) (const char *lang, const char *entity,
111 int s, int e, void *udata),
117 cs = (count) ? objective_j_en_objj_line : objective_j_en_objj_entity;
120 // if no newline at EOF; callback contents of last line
121 if (count) { process_last_line(OBJJ_LANG) }
126 /*****************************************************************************/