All machine instantiations are now implicitly referenced and always generated,
[external/ragel.git] / ragel / rlparse.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
22 #ifndef RLPARSE_H
23 #define RLPARSE_H
24
25 #include <iostream>
26 #include "avltree.h"
27 #include "parsedata.h"
28
29 struct Parser
30 {
31 %%{
32         parser Parser;
33
34         # These must be declared first and in this order. Ragel currently cannot
35         # import kelbt keywords for use in machines, so in the scanner
36         # rely on knowing the values that kelbt will assign to these.
37         token KW_Machine, KW_Include, KW_Write, TK_Word, TK_Literal;
38
39         token TK_Number, TK_Inline, TK_Reference, TK_ColonEquals, TK_EndSection;
40
41         # General tokens.
42         token TK_UInt, TK_Hex, TK_Word, TK_Literal, TK_BaseClause,
43                 TK_DotDot, TK_ColonGt, TK_ColonGtGt, TK_LtColon, TK_Arrow,
44                 TK_DoubleArrow, TK_StarStar, TK_ColonEquals, TK_NameSep, TK_BarStar,
45                 TK_DashDash;
46
47         # Conditions.
48         token TK_StartCond, TK_AllCond, TK_LeavingCond;
49
50         token TK_Middle;
51
52         # Global error actions.
53         token TK_StartGblError, TK_AllGblError, TK_FinalGblError,
54                 TK_NotFinalGblError, TK_NotStartGblError, TK_MiddleGblError;
55
56         # Local error actions.
57         token TK_StartLocalError, TK_AllLocalError, TK_FinalLocalError,
58                 TK_NotFinalLocalError, TK_NotStartLocalError, TK_MiddleLocalError;
59
60         # EOF Action embedding.
61         token TK_StartEOF, TK_AllEOF, TK_FinalEOF, TK_NotFinalEOF, TK_NotStartEOF,
62                 TK_MiddleEOF;
63
64         # To State Actions.
65         token TK_StartToState, TK_AllToState, TK_FinalToState, TK_NotFinalToState,
66                 TK_NotStartToState, TK_MiddleToState;
67
68         # In State Actions.
69         token TK_StartFromState, TK_AllFromState, TK_FinalFromState,
70                 TK_NotFinalFromState, TK_NotStartFromState, TK_MiddleFromState;
71
72         # Regular expression tokens. */
73         token RE_Slash, RE_SqOpen, RE_SqOpenNeg, RE_SqClose, RE_Dot, RE_Star,
74                 RE_Dash, RE_Char;
75
76         # Tokens specific to inline code.
77         token IL_WhiteSpace, IL_Comment, IL_Literal, IL_Symbol;
78
79         # Keywords.
80         token KW_Action, KW_AlphType, KW_Range, KW_GetKey, KW_Include, KW_Write,
81                 KW_Machine, KW_When, KW_Eof, KW_Err, KW_Lerr, KW_To, KW_From,
82                 KW_Export;
83
84         # Specials in code blocks.
85         token KW_Break, KW_Exec, KW_Hold, KW_PChar, KW_Char, KW_Goto, KW_Call,
86                 KW_Ret, KW_CurState, KW_TargState, KW_Entry, KW_Next, KW_Exec,
87                 KW_Variable, KW_Access;
88
89         # Special token for terminating semi-terminated code blocks. Needed because
90         # semi is sent as a token in the code block rather than as a generic
91         # symbol.
92         token TK_Semi;
93 }%%
94
95         %% write instance_data;
96
97         void init();
98         int parseLangEl( int type, const Token *token );
99
100         Parser( char *fileName, char *sectionName, InputLoc &sectionLoc )
101                 : sectionName(sectionName)
102         {
103                 pd = new ParseData( fileName, sectionName, sectionLoc );
104                 exportContext.append( false );
105         }
106
107         int token( InputLoc &loc, int tokId, char *tokstart, int toklen );
108         void tryMachineDef( InputLoc &loc, char *name, 
109                 JoinOrLm *joinOrLm, bool isInstance );
110
111         /* Report an error encountered by the parser. */
112         ostream &parse_error( int tokId, Token &token );
113
114         ParseData *pd;
115
116         /* The name of the root section, this does not change during an include. */
117         char *sectionName;
118
119         NameRef nameRef;
120         NameRefList nameRefList;
121
122         Vector<bool> exportContext;
123 };
124
125 %% write token_defs;
126
127 #endif