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"
36 extern char *Parser_lelNames[];
38 /* This is used for tracking the current stack of include file/machine pairs. It is
39 * is used to detect and recursive include structure. */
40 struct IncludeStackItem
42 IncludeStackItem( char *fileName, char *sectionName )
43 : fileName(fileName), sectionName(sectionName) {}
49 typedef Vector<IncludeStackItem> IncludeStack;
53 Scanner( char *fileName, istream &input, ostream &output,
54 Parser *inclToParser, char *inclSectionTarg,
55 int includeDepth, bool importMachines )
57 fileName(fileName), input(input), output(output),
58 inclToParser(inclToParser),
59 inclSectionTarg(inclSectionTarg),
60 includeDepth(includeDepth),
61 importMachines(importMachines),
63 line(1), column(1), lastnl(0),
64 parser(0), ignoreSection(false),
65 parserExistsError(false),
70 bool recursiveInclude( char *inclFileName, char *inclSectionName );
72 /* Make a list of places to look for an included file. */
73 char **makeIncludePathChecks( char *curFileName, char *fileName, int len );
74 std::ifstream *tryOpenInclude( char **pathChecks, long &found );
81 void token( int type, char *start, char *end );
82 void token( int type, char c );
83 void token( int type );
84 void processToken( int type, char *tokdata, int toklen );
85 void directToParser( Parser *toParser, char *tokFileName, int tokLine,
86 int tokColumn, int type, char *tokdata, int toklen );
88 void importToken( int type, char *start, char *end );
89 void pass( int token, char *start, char *end );
96 ostream &scan_error();
101 Parser *inclToParser;
102 char *inclSectionTarg;
106 /* For import parsing. */
108 int *tok_ts, *tok_te;
110 static const int max_tokens = 32;
111 int token_data[max_tokens];
112 char *token_strings[max_tokens];
113 int token_lens[max_tokens];
115 /* For section processing. */
118 int word_len, lit_len;
120 /* For character scanning. */
127 /* Set by machine statements, these persist from section to section
128 * allowing for unnamed sections. */
131 IncludeStack includeStack;
133 /* This is set if ragel has already emitted an error stating that
134 * no section name has been seen and thus no parser exists. */
135 bool parserExistsError;
137 /* This is for inline code. By default it is on. It goes off for
138 * statements and values in inline blocks which are parsed. */
141 /* Keeps a record of the previous token sent to the section parser. */
145 #endif /* _RLSCAN_H */