summaryrefslogtreecommitdiff
path: root/ragel/rlparse.kh
blob: e077d6a24d7b5d816ddad7ec09cdec731faf9886 (plain)
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
142
143
144
145
146
147
148
/*
 *  Copyright 2001-2007 Adrian Thurston <thurston@colm.net>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#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

struct ParamList;

struct TokHead
{
	TokHead *next;
};

struct Parser6
{
%%{
	parser Parser6;

	# General tokens.
	token TK_Word, TK_Literal, 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_BarEquals,
		TK_NameSep, TK_BarStar, TK_DashDash, TK_DotDotIndep;

	# 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;
		
	token TK_ColonNfaOpen, TK_CloseColon, TK_ColonCondOpen,
		TK_ColonCondStarOpen, TK_ColonCondPlusOpen, TK_ColonNoMaxOpen;

	# 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, KW_NfaPrePush, KW_NfaPostPop;

	# 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, KW_Ncall, KW_Nret, KW_Nbreak;
	
	token TK_SubstRef;
}%%

	%% write instance_data;

	void init();
	int parseLangEl( int type, const Token *token );
	void clear();

	Parser6( InputData *id, const char *fileName, char *sectionName,
			const InputLoc &sectionLoc, const HostLang *hostLang,
			MinimizeLevel minimizeLevel,
			MinimizeOpt minimizeOpt );

	int token( InputLoc &loc, int tokId, char *tokstart, int toklen );
	void tryMachineDef( const 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;
	const HostLang *hostLang;

	NameRef nameRef;
	NameRefList nameRefList;

	Vector<bool> exportContext;

	TokHead *tokHead;
	ActionParamList *paramList;

	Parser6 *prev, *next;

	void terminateParser();

	bool parseSubstitutions;
};

%% write token_defs;

void clearTokdata( Parser6 *parser );

#endif