1 // cmake.rl written by James Webber, bunkerprivate@googlemail.com, based on
2 // shell.rl written by Mitchell Foral. mitchell<att>caladbolg<dott>net
4 // From shell, I remove single quote strings and added an @code to the end
5 // of a double quote string in case the terminating double string is on a line
8 /************************* Required for every parser *************************/
9 #ifndef RAGEL_CMAKE_PARSER
10 #define RAGEL_CMAKE_PARSER
12 #include "../parser_macros.h"
14 // the name of the language
15 const char *CMAKE_LANG = "cmake";
17 // the languages entities
18 const char *cmake_entities[] = {
19 "space", "comment", "string", "any"
22 // constants associated with the entities
24 CMAKE_SPACE = 0, CMAKE_COMMENT, CMAKE_STRING, CMAKE_ANY
27 /*****************************************************************************/
32 include common "common.rl";
34 # Line counting machine
36 action cmake_ccallback {
45 std_internal_newline(CMAKE_LANG)
48 std_newline(CMAKE_LANG)
53 printf("endstring\n");
56 cmake_comment = '#' @comment nonnewline*;
60 newline %{ entity = INTERNAL_NL; } %cmake_ccallback
67 )* '"' @code @commit ;
69 cmake_string = cmake_dq_str;
72 spaces ${ entity = CMAKE_SPACE; } => cmake_ccallback;
75 newline ${ entity = NEWLINE; } => cmake_ccallback;
76 ^space ${ entity = CMAKE_ANY; } => cmake_ccallback;
81 action cmake_ecallback {
82 callback(CMAKE_LANG, cmake_entities[entity], cint(ts), cint(te), userdata);
85 cmake_comment_entity = '#' nonnewline*;
88 space+ ${ entity = CMAKE_SPACE; } => cmake_ecallback;
89 cmake_comment_entity ${ entity = CMAKE_COMMENT; } => cmake_ecallback;
90 # TODO: see shell.rl - (what is the todo for?!)
95 /************************* Required for every parser *************************/
97 /* Parses a string buffer with cmake script code.
99 * @param *buffer The string to parse.
100 * @param length The length of the string to parse.
101 * @param count Integer flag specifying whether or not to count lines. If yes,
102 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
103 * machine optimized for returning entity positions.
104 * @param *callback Callback function. If count is set, callback is called for
105 * every line of code, comment, or blank with 'lcode', 'lcomment', and
106 * 'lblank' respectively. Otherwise callback is called for each entity found.
108 void parse_cmake(char *buffer, int length, int count,
109 void (*callback) (const char *lang, const char *entity, int s,
116 cs = (count) ? cmake_en_cmake_line : cmake_en_cmake_entity;
119 // if no newline at EOF; callback contents of last line
120 if (count) { process_last_line(CMAKE_LANG) }
125 /*****************************************************************************/