3dadb12fa81a23ac82d67b75e6fc97b19aac915c
[external/ragel.git] / rlcodegen / xmlparse.kh
1 /*
2  *  Copyright 2001-2007 Adrian Thurston <thurston@cs.queensu.ca>
3  */
4
5 /*  This file is part of Ragel.
6  *
7  *  Ragel is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2 of the License, or
10  *  (at your option) any later version.
11  * 
12  *  Ragel is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  * 
17  *  You should have received a copy of the GNU General Public License
18  *  along with Ragel; if not, write to the Free Software
19  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
20  */
21 #ifndef _XMLPARSE_H
22 #define _XMLPARSE_H
23
24 #include "vector.h"
25 #include "rlcodegen.h"
26 #include "gendata.h"
27 #include <iostream>
28
29 using std::ostream;
30
31 struct XMLTagHashPair
32 {
33     char *name;
34     int id;
35 };
36
37 struct Token
38 {
39         XMLTag *tag;
40         InputLoc loc;
41 };
42
43 struct InlineItem;
44 struct InlineList;
45
46 struct LmSwitchVect;
47 struct LmSwitchAction;
48
49 extern char *lelNames[];
50
51 struct LangEl;
52
53 struct Parser
54 {
55         %%{
56                 parser Parser;
57
58                 token TAG_unknown, TAG_ragel, TAG_ragel_def, TAG_host, TAG_state_list,
59                         TAG_state, TAG_trans_list, TAG_t, TAG_machine, TAG_start_state,
60                         TAG_action_list, TAG_action_table_list, TAG_action,
61                         TAG_action_table, TAG_alphtype, TAG_element, TAG_getkey,
62                         TAG_state_actions, TAG_entry_points, TAG_sub_action,
63                         TAG_cond_space_list, TAG_cond_space, TAG_cond_list, TAG_c;
64
65                 # Inline block tokens.
66                 token TAG_text, TAG_goto, TAG_call, TAG_next, TAG_goto_expr,
67                         TAG_call_expr, TAG_next_expr, TAG_ret, TAG_pchar, TAG_char,
68                         TAG_hold, TAG_exec, TAG_holdte, TAG_execte, TAG_curs, TAG_targs,
69                         TAG_entry, TAG_data, TAG_lm_switch, TAG_init_act, TAG_set_act,
70                         TAG_set_tokend, TAG_get_tokend, TAG_init_tokstart,
71                         TAG_set_tokstart, TAG_write, TAG_curstate, TAG_access, TAG_break,
72                         TAG_option;
73         }%%
74
75         %%{ write instance_data; }%%
76
77         void init();
78         int parseLangEl( int type, const Token *token );
79
80         Parser( char *fileName )
81                 : fileName(fileName), sourceFileName(0) { }
82
83         int token( int tokenId, Token &token );
84         int token( int tokenId, int col, int line );
85         int token( XMLTag *tag, int col, int line );
86
87         /* Report an error encountered by the parser. */
88         ostream &warning( const InputLoc &loc );
89         ostream &error();
90         ostream &error( const InputLoc &loc );
91         ostream &parser_error( int tokId, Token &token );
92
93         /* The name of the root section, this does not change during an include. */
94         char *fileName;
95
96         /* Collected during parsing. */
97         char *sourceFileName;
98         char *attrKey;
99         char *attrValue;
100         int curAction;
101         int curActionTable;
102         int curTrans;
103         int curState;
104         int curCondSpace;
105         int curStateCond;
106
107         CodeGenMap codeGenMap;
108 };
109
110 %%{ write token_defs; }%%
111
112 #endif /* _XMLPARSE_H */