1 // octave.rl based on Mitchell Foral's matlab.rl, modified my Jason Riedy <jason@acm.org>
3 /************************* Required for every parser *************************/
4 #ifndef OHCOUNT_OCTAVE_PARSER_H
5 #define OHCOUNT_OCTAVE_PARSER_H
7 #include "../parser_macros.h"
9 // the name of the language
10 const char *OCTAVE_LANG = LANG_OCTAVE;
12 // the languages entities
13 const char *octave_entities[] = {
14 "space", "comment", "string", "any",
17 // constants associated with the entities
19 OCTAVE_SPACE = 0, OCTAVE_COMMENT, OCTAVE_STRING, OCTAVE_ANY
22 /*****************************************************************************/
27 include common "common.rl";
29 # Line counting machine
31 action octave_ccallback {
40 std_internal_newline(OCTAVE_LANG)
43 std_newline(OCTAVE_LANG)
47 # note: GNU Octave accepts % as well as #, but not '...' at the moment. We
48 # accept it anyways, as that may change. Also, GNU Octave does not currently
49 # support block comments but likely will someday.
50 octave_line_comment = (('%' | '...') [^{] @{ fhold; } | '#') @comment nonnewline*;
51 octave_block_comment =
53 newline %{ entity = INTERNAL_NL; } %octave_ccallback
57 (nonnewline - ws) @code
59 octave_comment = octave_line_comment | octave_block_comment;
61 octave_sq_str = '\'' @code ([^\r\n\f'\\] | '\\' nonnewline)* '\'';
62 octave_dq_str = '"' @code ([^\r\n\f"\\] | '\\' nonnewline)* '"';
63 octave_string = octave_sq_str | octave_dq_str;
66 spaces ${ entity = OCTAVE_SPACE; } => octave_ccallback;
69 newline ${ entity = NEWLINE; } => octave_ccallback;
70 ^space ${ entity = OCTAVE_ANY; } => octave_ccallback;
75 action octave_ecallback {
76 callback(OCTAVE_LANG, octave_entities[entity], cint(ts), cint(te),
80 octave_line_comment_entity = (('%' | '...') [^{] @{ fhold; } | '#') nonnewline*;
81 octave_block_comment_entity = '%{' any* :>> '%}';
82 octave_comment_entity =
83 octave_line_comment_entity | octave_block_comment_entity;
86 space+ ${ entity = OCTAVE_SPACE; } => octave_ecallback;
87 octave_comment_entity ${ entity = OCTAVE_COMMENT; } => octave_ecallback;
93 /************************* Required for every parser *************************/
95 /* Parses a string buffer with OCTAVE code.
97 * @param *buffer The string to parse.
98 * @param length The length of the string to parse.
99 * @param count Integer flag specifying whether or not to count lines. If yes,
100 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
101 * machine optimized for returning entity positions.
102 * @param *callback Callback function. If count is set, callback is called for
103 * every line of code, comment, or blank with 'lcode', 'lcomment', and
104 * 'lblank' respectively. Otherwise callback is called for each entity found.
106 void parse_octave(char *buffer, int length, int count,
107 void (*callback) (const char *lang, const char *entity, int s,
114 cs = (count) ? octave_en_octave_line : octave_en_octave_entity;
117 // if no newline at EOF; callback contents of last line
118 if (count) { process_last_line(OCTAVE_LANG) }
123 /*****************************************************************************/