1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
/*
* Copyright 2001-2007 Adrian Thurston <thurston@complang.org>
*/
/* This file is part of Ragel.
*
* Ragel is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Ragel is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Ragel; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _RLPARSE_H
#define _RLPARSE_H
#include <iostream>
#include "avltree.h"
#include "parsedata.h"
/* Import scanner tokens. */
#define IMP_Word 128
#define IMP_Literal 129
#define IMP_UInt 130
#define IMP_Define 131
/* This is used for tracking the include files/machine pairs. */
struct IncludeHistoryItem
{
IncludeHistoryItem( const char *fileName, const char *sectionName )
: fileName(fileName), sectionName(sectionName) {}
const char *fileName;
const char *sectionName;
};
typedef Vector<IncludeHistoryItem> IncludeHistory;
struct Parser
{
%%{
parser Parser;
# General tokens.
token TK_Word, TK_Literal, TK_Number, TK_EndSection, TK_UInt, TK_Hex,
TK_Word, TK_Literal, TK_DotDot, TK_ColonGt, TK_ColonGtGt, TK_LtColon,
TK_Arrow, TK_DoubleArrow, TK_StarStar, TK_ColonEquals, TK_NameSep,
TK_BarStar, TK_DashDash;
# Conditions.
token TK_StartCond, TK_AllCond, TK_LeavingCond;
# State embedding actions.
token TK_Middle;
# Global error actions.
token TK_StartGblError, TK_AllGblError, TK_FinalGblError,
TK_NotFinalGblError, TK_NotStartGblError, TK_MiddleGblError;
# Local error actions.
token TK_StartLocalError, TK_AllLocalError, TK_FinalLocalError,
TK_NotFinalLocalError, TK_NotStartLocalError, TK_MiddleLocalError;
# EOF Action embedding.
token TK_StartEOF, TK_AllEOF, TK_FinalEOF, TK_NotFinalEOF, TK_NotStartEOF,
TK_MiddleEOF;
# To State Actions.
token TK_StartToState, TK_AllToState, TK_FinalToState, TK_NotFinalToState,
TK_NotStartToState, TK_MiddleToState;
# In State Actions.
token TK_StartFromState, TK_AllFromState, TK_FinalFromState,
TK_NotFinalFromState, TK_NotStartFromState, TK_MiddleFromState;
# Regular expression tokens. */
token RE_Slash, RE_SqOpen, RE_SqOpenNeg, RE_SqClose, RE_Dot, RE_Star,
RE_Dash, RE_Char;
# Tokens specific to inline code.
token IL_WhiteSpace, IL_Comment, IL_Literal, IL_Symbol;
# Keywords.
token KW_Machine, KW_Include, KW_Import, KW_Write, KW_Action, KW_AlphType,
KW_Range, KW_GetKey, KW_Include, KW_Write, KW_Machine, KW_InWhen,
KW_When, KW_OutWhen, KW_Eof, KW_Err, KW_Lerr, KW_To, KW_From,
KW_Export, KW_PrePush, KW_PostPop, KW_Length;
# Specials in code blocks.
token KW_Break, KW_Exec, KW_Hold, KW_PChar, KW_Char, KW_Goto, KW_Call,
KW_Ret, KW_CurState, KW_TargState, KW_Entry, KW_Next, KW_Exec,
KW_Variable, KW_Access;
}%%
%% write instance_data;
void init();
int parseLangEl( int type, const Token *token );
Parser( const char *fileName, char *sectionName, InputLoc §ionLoc )
: sectionName(sectionName)
{
pd = new ParseData( fileName, sectionName, sectionLoc );
exportContext.append( false );
includeHistory.append( IncludeHistoryItem(
fileName, sectionName ) );
}
int token( InputLoc &loc, int tokId, char *tokstart, int toklen );
void tryMachineDef( InputLoc &loc, char *name,
MachineDef *machineDef, bool isInstance );
/* Report an error encountered by the parser. */
ostream &parse_error( int tokId, Token &token );
ParseData *pd;
/* The name of the root section, this does not change during an include. */
char *sectionName;
NameRef nameRef;
NameRefList nameRefList;
Vector<bool> exportContext;
IncludeHistory includeHistory;
Parser *prev, *next;
};
%% write token_defs;
#endif
|