123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- /*
- * 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
|