Debian Codegraph @

src/tools/dlgedit/loadlg.l

raw
1 %{
2 /*
3 Copyright (C) 2000/2002/2003 Kai Sterker <[email protected]>
4 Part of the Adonthell Project <http://adonthell.nongnu.org>
5
6 Dlgedit is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 Dlgedit is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Dlgedit. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include <math.h>
21 #include <string>
22 #include "dlg_types.h"
23
24 #define YY_DECL int parse_dlgfile (std::string &mytext, int &mynum)
25
26 // definitions for using 'includes'
27 #define MAX_INCLUDE_DEPTH 10
28 YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
29 int include_stack_ptr = 0;
30
31 // switch to another file for input
32 void parser_switch_input ()
33 {
34 include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
35 yy_switch_to_buffer (yy_create_buffer (yyin, YY_BUF_SIZE));
36 }
37
38 // return to previous file
39 void parser_restore_input ()
40 {
41 yy_delete_buffer (YY_CURRENT_BUFFER);
42 yy_switch_to_buffer (include_stack[include_stack_ptr]);
43 }
44 %}
45
46 digit [0-9]
47 num -?{digit}+
48
49 %x text module
50 %option noyywrap nounput never-interactive prefix="loadlg"
51
52 %%
53
54 "#".*[\n]? ; /* Eat up comments */
55
56 Circle return LOAD_CIRCLE;
57 Arrow return LOAD_ARROW;
58 End return LOAD_END;
59 Type return LOAD_TYPE;
60 Prev return LOAD_PREV;
61 Next return LOAD_NEXT;
62 Link return LOAD_LINK;
63 Pos return LOAD_POS;
64 Note return LOAD_NOTE;
65 Text return LOAD_TEXT;
66 Cond return LOAD_COND;
67 Vars return LOAD_VARS;
68 Func return LOAD_FUNC;
69 NPC return LOAD_NPC;
70 Name return LOAD_NAME;
71 Race return LOAD_RACE;
72 Gender return LOAD_GENDER;
73 Loop return LOAD_LOOP;
74 Proj return LOAD_PROJECT;
75 Inc return LOAD_IMPORTS;
76 Dtor return LOAD_DTOR;
77 Ctor return LOAD_CTOR;
78 Id return LOAD_ID;
79
80 Module mytext = ""; BEGIN(module); return LOAD_MODULE;
81
82 <module>[ \t] /* Eat whitespace */
83 <module>[^ \t\n]+ {
84 mytext += yytext;
85 BEGIN(INITIAL);
86
87 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
88 {
89 fprintf (stderr, "Modules nested too deeply\n");
90 return LOAD_UNKNOWN;
91 }
92
93 return LOAD_STR;
94 }
95
96 <<EOF>> {
97 if (--include_stack_ptr < 0)
98 {
99 include_stack_ptr = 0;
100 yyterminate ();
101 }
102 else
103 {
104 parser_restore_input ();
105 return 0;
106 }
107 }
108
109 \xa7 mytext = ""; BEGIN(text);
110 <text>\xa7 BEGIN(INITIAL); return LOAD_STR;
111 <text>[^\xa7]+ mytext += yytext;
112
113 {num} mynum = atoi (yytext); return LOAD_NUM;
114
115 [ \t\n]+ ;
116 . return LOAD_UNKNOWN;