1 // vim.rl written by Mitchell Foral. mitchell<att>caladbolg<dott>net.
3 /************************* Required for every parser *************************/
4 #ifndef RAGEL_VIM_PARSER
5 #define RAGEL_VIM_PARSER
7 #include "ragel_parser_macros.h"
9 // the name of the language
10 const char *VIM_LANG = "vim";
12 // the languages entities
13 const char *vim_entities[] = {
14 "space", "comment", "string", "any"
17 // constants associated with the entities
19 VIM_SPACE = 0, VIM_COMMENT, VIM_STRING, VIM_ANY
22 /*****************************************************************************/
27 include common "common.rl";
29 # Line counting machine
31 action vim_ccallback {
40 std_internal_newline(VIM_LANG)
47 vim_comment = '"' when no_code @comment nonnewline*;
49 vim_sq_str = '\'' @code ([^\r\n\f'\\] | '\\' any)* '\'';
50 vim_dq_str = '"' when !no_code @code ([^\r\n\f"\\] | '\\' any)* '"';
51 vim_string = vim_sq_str | vim_dq_str;
54 spaces ${ entity = VIM_SPACE; } => vim_ccallback;
57 newline ${ entity = NEWLINE; } => vim_ccallback;
59 ^(space | '"') ${ entity = VIM_ANY; } => vim_ccallback;
65 action vim_ecallback {
66 callback(VIM_LANG, vim_entities[entity], cint(ts), cint(te));
69 vim_entity := 'TODO:';
72 /************************* Required for every parser *************************/
74 /* Parses a string buffer with Vim code.
76 * @param *buffer The string to parse.
77 * @param length The length of the string to parse.
78 * @param count Integer flag specifying whether or not to count lines. If yes,
79 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
80 * machine optimized for returning entity positions.
81 * @param *callback Callback function. If count is set, callback is called for
82 * every line of code, comment, or blank with 'lcode', 'lcomment', and
83 * 'lblank' respectively. Otherwise callback is called for each entity found.
85 void parse_vim(char *buffer, int length, int count,
86 void (*callback) (const char *lang, const char *entity, int start, int end)
91 cs = (count) ? vim_en_vim_line : vim_en_vim_entity;
94 // if no newline at EOF; callback contents of last line
95 if (count) { process_last_line(VIM_LANG) }
100 /*****************************************************************************/