1 // nsis.rl written by Chris Morgan.
3 /************************* Required for every parser *************************/
4 #ifndef OHCOUNT_NSIS_PARSER_H
5 #define OHCOUNT_NSIS_PARSER_H
7 #include "../parser_macros.h"
9 // the name of the language
10 const char *NSIS_LANG = LANG_NSIS;
12 // the languages entities
13 const char *nsis_entities[] = {
14 "space", "comment", "string", "any"
17 // constants associated with the entities
19 NSIS_SPACE = 0, NSIS_COMMENT, NSIS_STRING, NSIS_ANY
22 /*****************************************************************************/
27 include common "common.rl";
29 # Line counting machine
31 action nsis_ccallback {
40 std_internal_newline(NSIS_LANG)
43 std_newline(NSIS_LANG)
47 nsis_line_comment = ('#' | ';') @comment nonnewline*;
50 newline %{ entity = INTERNAL_NL; } %nsis_ccallback
54 (nonnewline - ws) @comment
56 nsis_comment = nsis_line_comment | nsis_block_comment;
58 nsis_bt_str = '`' @code ([^\r\n\f`\\] | '\\' nonnewline)* '`';
59 nsis_sq_str = '\'' @code ([^\r\n\f'\\] | '\\' nonnewline)* '\'';
60 nsis_dq_str = '"' @code ([^\r\n\f"\\] | '\\' nonnewline)* '"';
61 nsis_string = nsis_bt_str | nsis_sq_str | nsis_dq_str;
64 spaces ${ entity = NSIS_SPACE; } => nsis_ccallback;
67 newline ${ entity = NEWLINE; } => nsis_ccallback;
68 ^space ${ entity = NSIS_ANY; } => nsis_ccallback;
73 action nsis_ecallback {
74 callback(NSIS_LANG, nsis_entities[entity], cint(ts), cint(te), userdata);
77 nsis_line_comment_entity = ('#' | '//') nonnewline*;
78 nsis_block_comment_entity = '/*' any* :>> '*/';
79 nsis_comment_entity = nsis_line_comment_entity | nsis_block_comment_entity;
82 space+ ${ entity = NSIS_SPACE; } => nsis_ecallback;
83 nsis_comment_entity ${ entity = NSIS_COMMENT; } => nsis_ecallback;
89 /************************* Required for every parser *************************/
91 /* Parses a string buffer with NSIS code.
93 * @param *buffer The string to parse.
94 * @param length The length of the string to parse.
95 * @param count Integer flag specifying whether or not to count lines. If yes,
96 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
97 * machine optimized for returning entity positions.
98 * @param *callback Callback function. If count is set, callback is called for
99 * every line of code, comment, or blank with 'lcode', 'lcomment', and
100 * 'lblank' respectively. Otherwise callback is called for each entity found.
102 void parse_nsis(char *buffer, int length, int count,
103 void (*callback) (const char *lang, const char *entity, int s,
110 cs = (count) ? nsis_en_nsis_line : nsis_en_nsis_entity;
113 // if no newline at EOF; callback contents of last line
114 if (count) { process_last_line(NSIS_LANG) }
119 /*****************************************************************************/