2 * Copyright 2007 Adrian Thurston <thurston@cs.queensu.ca>
5 /* This file is part of Ragel.
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.
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.
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
29 #include "parsedata.h"
38 ImportScanner( char *fileName, istream &input, ostream &output, Parser *parser )
40 fileName(fileName), input(input), output(output),
46 void token( int type, char *start, char *end );
51 ostream &scan_error();
58 /* For scanning the tokens. */
60 int *tok_tokstart, *tok_tokend;
62 static const int max_tokens = 8;
63 int token_data[max_tokens];
65 /* For scanning the characters. */
67 char *chr_tokstart, *chr_tokend;
72 extern char *Parser_lelNames[];
74 /* This is used for tracking the current stack of include file/machine pairs. It is
75 * is used to detect and recursive include structure. */
76 struct IncludeStackItem
78 IncludeStackItem( char *fileName, char *sectionName )
79 : fileName(fileName), sectionName(sectionName) {}
85 typedef Vector<IncludeStackItem> IncludeStack;
89 Scanner( char *fileName, istream &input, ostream &output,
90 Parser *inclToParser, char *inclSectionTarg,
93 fileName(fileName), input(input), output(output),
94 inclToParser(inclToParser),
95 inclSectionTarg(inclSectionTarg),
96 includeDepth(includeDepth),
97 line(1), column(1), lastnl(0),
98 parser(0), ignoreSection(false),
99 parserExistsError(false),
104 bool recursiveInclude( char *inclFileName, char *inclSectionName );
106 char *prepareFileName( char *fileName, int len )
108 bool caseInsensitive;
109 Token tokenFnStr, tokenRes;
110 tokenFnStr.data = fileName;
111 tokenFnStr.length = len;
112 tokenFnStr.prepareLitString( tokenRes, caseInsensitive );
113 return tokenRes.data;
117 void token( int type, char *start, char *end );
118 void token( int type, char c );
119 void token( int type );
125 ostream &scan_error();
130 Parser *inclToParser;
131 char *inclSectionTarg;
134 /* For section processing. */
137 int word_len, lit_len;
139 /* For character scanning. */
142 char *tokstart, *tokend;
146 /* Set by machine statements, these persist from section to section
147 * allowing for unnamed sections. */
150 IncludeStack includeStack;
152 /* This is set if ragel has already emitted an error stating that
153 * no section name has been seen and thus no parser exists. */
154 bool parserExistsError;
156 /* This is for inline code. By default it is on. It goes off for
157 * statements and values in inline blocks which are parsed. */
160 /* Keeps a record of the previous token sent to the section parser. */
164 #endif /* _RLSCAN_H */