1 // tex.rl written by Mitchell Foral. mitchell<att>caladbolg<dott>net.
3 /************************* Required for every parser *************************/
4 #ifndef RAGEL_TEX_PARSER
5 #define RAGEL_TEX_PARSER
7 #include "ragel_parser_macros.h"
9 // the name of the language
10 const char *TEX_LANG = "tex";
12 // the languages entities
13 const char *tex_entities[] = {
14 "space", "comment", "string", "any"
17 // constants associated with the entities
19 TEX_SPACE = 0, TEX_COMMENT, TEX_STRING, TEX_ANY
22 /*****************************************************************************/
27 include common "common.rl";
29 # Line counting machine
31 action tex_ccallback {
40 std_internal_newline(TEX_LANG)
47 tex_comment = '%' @comment nonnewline*;
50 spaces ${ entity = TEX_SPACE; } => tex_ccallback;
52 newline ${ entity = NEWLINE; } => tex_ccallback;
53 ^space ${ entity = TEX_ANY; } => tex_ccallback;
58 action tex_ecallback {
59 callback(TEX_LANG, entity, cint(ts), cint(te));
62 tex_entity := 'TODO:';
65 /************************* Required for every parser *************************/
67 /* Parses a string buffer with Tex markup.
69 * @param *buffer The string to parse.
70 * @param length The length of the string to parse.
71 * @param count Integer flag specifying whether or not to count lines. If yes,
72 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
73 * machine optimized for returning entity positions.
74 * @param *callback Callback function. If count is set, callback is called for
75 * every line of code, comment, or blank with 'lcode', 'lcomment', and
76 * 'lblank' respectively. Otherwise callback is called for each entity found.
78 void parse_tex(char *buffer, int length, int count,
79 void (*callback) (const char *lang, const char *entity, int start, int end)
84 cs = (count) ? tex_en_tex_line : tex_en_tex_entity;
87 // if no newline at EOF; callback contents of last line
88 if (count) { process_last_line(TEX_LANG) }
93 /*****************************************************************************/