1 // dylan.rl written by Mitchell Foral. mitchell<att>caladbolg<dott>net
3 /************************* Required for every parser *************************/
4 #ifndef RAGEL_DYLAN_PARSER
5 #define RAGEL_DYLAN_PARSER
7 #include "ragel_parser_macros.h"
9 // the name of the language
10 const char *DYLAN_LANG = "dylan";
12 // the languages entities
13 const char *dylan_entities[] = {
14 "space", "comment", "string", "any"
17 // constants associated with the entities
19 DYLAN_SPACE = 0, DYLAN_COMMENT, DYLAN_STRING, DYLAN_ANY
22 /*****************************************************************************/
27 include common "common.rl";
29 # Line counting machine
31 action dylan_ccallback {
40 std_internal_newline(DYLAN_LANG)
43 std_newline(DYLAN_LANG)
47 dylan_line_comment = '//' @comment nonnewline*;
50 newline %{ entity = INTERNAL_NL; } %dylan_ccallback
54 (nonnewline - ws) @comment
56 dylan_comment = dylan_line_comment | dylan_block_comment;
58 dylan_char = '\'' @code ([^\r\n\f'\\] | '\\' nonnewline) '\'';
59 dylan_dq_str = '"' @code ([^\r\n\f"\\] | '\\' nonnewline)* '"';
60 dylan_string = dylan_char | dylan_dq_str;
63 spaces ${ entity = DYLAN_SPACE; } => dylan_ccallback;
66 newline ${ entity = NEWLINE; } => dylan_ccallback;
67 ^space ${ entity = DYLAN_ANY; } => dylan_ccallback;
72 action dylan_ecallback {
73 callback(DYLAN_LANG, dylan_entities[entity], cint(ts), cint(te));
76 dylan_line_comment_entity = '//' nonnewline*;
77 dylan_block_comment_entity = '/*' any* :>> '*/';
78 dylan_comment_entity = dylan_line_comment_entity | dylan_block_comment_entity;
81 space+ ${ entity = DYLAN_SPACE; } => dylan_ecallback;
82 dylan_comment_entity ${ entity = DYLAN_COMMENT; } => dylan_ecallback;
88 /************************* Required for every parser *************************/
90 /* Parses a string buffer with Dylan 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_dylan(char *buffer, int length, int count,
102 void (*callback) (const char *lang, const char *entity, int start, int end)
107 cs = (count) ? dylan_en_dylan_line : dylan_en_dylan_entity;
110 // if no newline at EOF; callback contents of last line
111 if (count) { process_last_line(DYLAN_LANG) }
116 /*****************************************************************************/