1 // scilab.rl written by Sylvestre Ledru based on matlab Mitchell Foral. mitchell<att>caladbolg<dott>net.
3 /************************* Required for every parser *************************/
4 #ifndef RAGEL_SCILAB_PARSER
5 #define RAGEL_SCILAB_PARSER
7 #include "../parser_macros.h"
9 // the name of the language
10 const char *SCILAB_LANG = "scilab";
12 // the languages entities
13 const char *scilab_entities[] = {
14 "space", "comment", "string", "any",
17 // constants associated with the entities
19 SCILAB_SPACE = 0, SCILAB_COMMENT, SCILAB_STRING, SCILAB_ANY
22 /*****************************************************************************/
27 include common "common.rl";
29 # Line counting machine
31 action scilab_ccallback {
40 std_internal_newline(SCILAB_LANG)
43 std_newline(SCILAB_LANG)
47 scilab_comment = ('//') @comment nonnewline*;
49 # The detector is not smart enough to detect GNU Octave's double
50 # quotes around strings, so accept it here.
51 scilab_sq_str = '\'' @code ([^\r\n\f'\\] | '\\' nonnewline)* '\'';
52 scilab_dq_str = '"' @code ([^\r\n\f"\\] | '\\' nonnewline)* '"';
53 scilab_string = scilab_sq_str | scilab_dq_str;
56 spaces ${ entity = SCILAB_SPACE; } => scilab_ccallback;
59 newline ${ entity = NEWLINE; } => scilab_ccallback;
60 ^space ${ entity = SCILAB_ANY; } => scilab_ccallback;
65 action scilab_ecallback {
66 callback(SCILAB_LANG, scilab_entities[entity], cint(ts), cint(te),
70 scilab_comment_entity = ('//') @comment nonnewline*;
73 space+ ${ entity = SCILAB_SPACE; } => scilab_ecallback;
74 scilab_comment_entity ${ entity = SCILAB_COMMENT; } => scilab_ecallback;
80 /************************* Required for every parser *************************/
82 /* Parses a string buffer with SCILAB code.
84 * @param *buffer The string to parse.
85 * @param length The length of the string to parse.
86 * @param count Integer flag specifying whether or not to count lines. If yes,
87 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
88 * machine optimized for returning entity positions.
89 * @param *callback Callback function. If count is set, callback is called for
90 * every line of code, comment, or blank with 'lcode', 'lcomment', and
91 * 'lblank' respectively. Otherwise callback is called for each entity found.
93 void parse_scilab(char *buffer, int length, int count,
94 void (*callback) (const char *lang, const char *entity, int s,
101 cs = (count) ? scilab_en_scilab_line : scilab_en_scilab_entity;
104 // if no newline at EOF; callback contents of last line
105 if (count) { process_last_line(SCILAB_LANG) }
110 /*****************************************************************************/