1 // scala.rl written by Mitchell Foral. mitchell<att>caladbolg<dott>net.
3 /************************* Required for every parser *************************/
4 #ifndef OHCOUNT_SCALA_PARSER_H
5 #define OHCOUNT_SCALA_PARSER_H
7 #include "../parser_macros.h"
9 // the name of the language
10 const char *SCALA_LANG = LANG_SCALA;
12 // the languages entities
13 const char *scala_entities[] = {
14 "space", "comment", "string", "any",
17 // constants associated with the entities
19 SCALA_SPACE = 0, SCALA_COMMENT, SCALA_STRING, SCALA_ANY
22 /*****************************************************************************/
27 include common "common.rl";
29 # Line counting machine
31 action scala_ccallback {
40 std_internal_newline(SCALA_LANG)
43 std_newline(SCALA_LANG)
47 scala_line_comment = '//' @comment nonnewline*;
50 newline %{ entity = INTERNAL_NL; } %scala_ccallback
54 (nonnewline - ws) @comment
56 scala_comment = scala_line_comment | scala_block_comment;
58 scala_sq_str = '\'' @code ([^\r\n\f'\\] | '\\' nonnewline)* '\'';
59 scala_dq_str = '"' @code ([^\r\n\f"\\] | '\\' nonnewline)* '"';
60 scala_string = scala_sq_str | scala_dq_str;
63 spaces ${ entity = SCALA_SPACE; } => scala_ccallback;
66 newline ${ entity = NEWLINE; } => scala_ccallback;
67 ^space ${ entity = SCALA_ANY; } => scala_ccallback;
72 action scala_ecallback {
73 callback(SCALA_LANG, scala_entities[entity], cint(ts), cint(te), userdata);
76 scala_line_comment_entity = '//' nonnewline*;
77 scala_block_comment_entity = '/*' any* :>> '*/';
78 scala_comment_entity = scala_line_comment_entity | scala_block_comment_entity;
81 space+ ${ entity = SCALA_SPACE; } => scala_ecallback;
82 scala_comment_entity ${ entity = SCALA_COMMENT; } => scala_ecallback;
88 /************************* Required for every parser *************************/
90 /* Parses a string buffer with Scala 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_scala(char *buffer, int length, int count,
102 void (*callback) (const char *lang, const char *entity, int s,
109 cs = (count) ? scala_en_scala_line : scala_en_scala_entity;
112 // if no newline at EOF; callback contents of last line
113 if (count) { process_last_line(SCALA_LANG) }
118 /*****************************************************************************/