1 // smalltalk.rl written by Mitchell Foral. mitchell<att>caladbolg<dott>net
3 /************************* Required for every parser *************************/
4 #ifndef OHCOUNT_SMALLTALK_PARSER_H
5 #define OHCOUNT_SMALLTALK_PARSER_H
7 #include "../parser_macros.h"
9 // the name of the language
10 const char *SMALLTALK_LANG = LANG_SMALLTALK;
12 // the languages entities
13 const char *smalltalk_entities[] = {
14 "space", "comment", "string", "any"
17 // constants associated with the entities
19 SMALLTALK_SPACE = 0, SMALLTALK_COMMENT, SMALLTALK_STRING, SMALLTALK_ANY
22 /*****************************************************************************/
27 include common "common.rl";
29 # Line counting machine
31 action smalltalk_ccallback {
40 std_internal_newline(SMALLTALK_LANG)
43 std_newline(SMALLTALK_LANG)
49 newline %{ entity = INTERNAL_NL; } %smalltalk_ccallback
53 [^\r\n\f\t "] @comment
56 smalltalk_string = '\'' @code [^\r\n\f']* '\'';
59 spaces ${ entity = SMALLTALK_SPACE; } => smalltalk_ccallback;
62 newline ${ entity = NEWLINE; } => smalltalk_ccallback;
63 ^space ${ entity = SMALLTALK_ANY; } => smalltalk_ccallback;
68 action smalltalk_ecallback {
69 callback(SMALLTALK_LANG, smalltalk_entities[entity], cint(ts), cint(te),
73 smalltalk_comment_entity = '"' any* :>> '"';
75 smalltalk_entity := |*
76 space+ ${ entity = SMALLTALK_SPACE; } => smalltalk_ecallback;
77 smalltalk_comment_entity ${ entity = SMALLTALK_COMMENT; } => smalltalk_ecallback;
83 /************************* Required for every parser *************************/
85 /* Parses a string buffer with Smalltalk code.
87 * @param *buffer The string to parse.
88 * @param length The length of the string to parse.
89 * @param count Integer flag specifying whether or not to count lines. If yes,
90 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
91 * machine optimized for returning entity positions.
92 * @param *callback Callback function. If count is set, callback is called for
93 * every line of code, comment, or blank with 'lcode', 'lcomment', and
94 * 'lblank' respectively. Otherwise callback is called for each entity found.
96 void parse_smalltalk(char *buffer, int length, int count,
97 void (*callback) (const char *lang, const char *entity,
98 int s, int e, void *udata),
104 cs = (count) ? smalltalk_en_smalltalk_line : smalltalk_en_smalltalk_entity;
107 // if no newline at EOF; callback contents of last line
108 if (count) { process_last_line(SMALLTALK_LANG) }
113 /*****************************************************************************/