Initialize Tizen 2.3
[external/ragel.git] / ragel / rlscan.h
1 /*
2  *  Copyright 2007 Adrian Thurston <thurston@complang.org>
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
22 #ifndef _RLSCAN_H
23 #define _RLSCAN_H
24
25 #include <iostream>
26 #include "rlscan.h"
27 #include "vector.h"
28 #include "rlparse.h"
29 #include "parsedata.h"
30 #include "avltree.h"
31 #include "vector.h"
32
33 using std::istream;
34 using std::ostream;
35
36 extern char *Parser_lelNames[];
37
38 struct Scanner
39 {
40         Scanner( InputData &id, const char *fileName, istream &input,
41                         Parser *inclToParser, char *inclSectionTarg,
42                         int includeDepth, bool importMachines )
43         : 
44                 id(id), fileName(fileName), 
45                 input(input),
46                 inclToParser(inclToParser),
47                 inclSectionTarg(inclSectionTarg),
48                 includeDepth(includeDepth),
49                 importMachines(importMachines),
50                 cur_token(0),
51                 line(1), column(1), lastnl(0), 
52                 parser(0), ignoreSection(false), 
53                 parserExistsError(false),
54                 whitespaceOn(true),
55                 lastToken(0)
56                 {}
57
58         bool duplicateInclude( char *inclFileName, char *inclSectionName );
59
60         /* Make a list of places to look for an included file. */
61         char **makeIncludePathChecks( const char *curFileName, const char *fileName, int len );
62         std::ifstream *tryOpenInclude( char **pathChecks, long &found );
63
64         void handleMachine();
65         void handleInclude();
66         void handleImport();
67
68         void init();
69         void token( int type, char *start, char *end );
70         void token( int type, char c );
71         void token( int type );
72         void processToken( int type, char *tokdata, int toklen );
73         void directToParser( Parser *toParser, const char *tokFileName, int tokLine, 
74                 int tokColumn, int type, char *tokdata, int toklen );
75         void flushImport( );
76         void importToken( int type, char *start, char *end );
77         void pass( int token, char *start, char *end );
78         void pass();
79         void updateCol();
80         void startSection();
81         void endSection();
82         void do_scan();
83         bool active();
84         ostream &scan_error();
85
86         InputData &id;
87         const char *fileName;
88         istream &input;
89         Parser *inclToParser;
90         char *inclSectionTarg;
91         int includeDepth;
92         bool importMachines;
93
94         /* For import parsing. */
95         int tok_cs, tok_act;
96         int *tok_ts, *tok_te;
97         int cur_token;
98         static const int max_tokens = 32;
99         int token_data[max_tokens];
100         char *token_strings[max_tokens];
101         int token_lens[max_tokens];
102
103         /* For section processing. */
104         int cs;
105         char *word, *lit;
106         int word_len, lit_len;
107
108         /* For character scanning. */
109         int line;
110         InputLoc sectionLoc;
111         char *ts, *te;
112         int column;
113         char *lastnl;
114
115         /* Set by machine statements, these persist from section to section
116          * allowing for unnamed sections. */
117         Parser *parser;
118         bool ignoreSection;
119
120         /* This is set if ragel has already emitted an error stating that
121          * no section name has been seen and thus no parser exists. */
122         bool parserExistsError;
123
124         /* This is for inline code. By default it is on. It goes off for
125          * statements and values in inline blocks which are parsed. */
126         bool whitespaceOn;
127
128         /* Keeps a record of the previous token sent to the section parser. */
129         int lastToken;
130 };
131
132 #endif