1 // vhdl.rl written by Mitchell Foral. mitchell<att>caladbolg<dott>net.
3 /************************* Required for every parser *************************/
4 #ifndef OHCOUNT_VHDL_PARSER_H
5 #define OHCOUNT_VHDL_PARSER_H
7 #include "../parser_macros.h"
9 // the name of the language
10 const char *VHDL_LANG = LANG_VHDL;
12 // the languages entities
13 const char *vhdl_entities[] = {
14 "space", "comment", "string", "any"
17 // constants associated with the entities
19 VHDL_SPACE = 0, VHDL_COMMENT, VHDL_STRING, VHDL_ANY
22 /*****************************************************************************/
27 include common "common.rl";
29 # Line counting machine
31 action vhdl_ccallback {
40 std_internal_newline(VHDL_LANG)
43 std_newline(VHDL_LANG)
47 vhdl_comment = '--' @comment nonnewline*;
49 vhdl_char = '\'' @code [^\r\n\f'] '\'';
50 vhdl_dq_str = '"' @code [^\r\n\f"]* '"';
51 vhdl_string = vhdl_char | vhdl_dq_str;
54 spaces ${ entity = VHDL_SPACE; } => vhdl_ccallback;
57 newline ${ entity = NEWLINE; } => vhdl_ccallback;
58 ^space ${ entity = VHDL_ANY; } => vhdl_ccallback;
63 action vhdl_ecallback {
64 callback(VHDL_LANG, vhdl_entities[entity], cint(ts), cint(te), userdata);
67 vhdl_comment_entity = '--' nonnewline*;
70 space+ ${ entity = VHDL_SPACE; } => vhdl_ecallback;
71 vhdl_comment_entity ${ entity = VHDL_COMMENT; } => vhdl_ecallback;
77 /************************* Required for every parser *************************/
79 /* Parses a string buffer with VHDL code.
81 * @param *buffer The string to parse.
82 * @param length The length of the string to parse.
83 * @param count Integer flag specifying whether or not to count lines. If yes,
84 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
85 * machine optimized for returning entity positions.
86 * @param *callback Callback function. If count is set, callback is called for
87 * every line of code, comment, or blank with 'lcode', 'lcomment', and
88 * 'lblank' respectively. Otherwise callback is called for each entity found.
90 void parse_vhdl(char *buffer, int length, int count,
91 void (*callback) (const char *lang, const char *entity, int s,
98 cs = (count) ? vhdl_en_vhdl_line : vhdl_en_vhdl_entity;
101 // if no newline at EOF; callback contents of last line
102 if (count) { process_last_line(VHDL_LANG) }
107 /*****************************************************************************/