Now supplying the XmlParser to writeMachines.
[external/ragel.git] / ragel / rlparse.kh
index fe983fa..e840f8a 100644 (file)
 #include "avltree.h"
 #include "parsedata.h"
 
-extern char *lelNames[];
 
-struct LangEl;
+/* Import scanner tokens. */
+#define IMP_Word 128
+#define IMP_Literal 129
+#define IMP_UInt 130
+#define IMP_Define 131
 
-struct Parser
+/* This is used for tracking the include files/machine pairs. */
+struct IncludeHistoryItem
 {
-       %%{
-       parser Parser;
+       IncludeHistoryItem( const char *fileName, const char *sectionName )
+               : fileName(fileName), sectionName(sectionName) {}
 
-       # These must be declared first and in this order. Ragel currently cannot
-       # import kelbt keywords for use in machines, so in the scanner
-       # rely on knowing the values that kelbt will assign to these.
-       token KW_Machine, KW_Include, KW_Write, TK_Word, TK_Literal;
+       const char *fileName;
+       const char *sectionName;
+};
 
-       token TK_Number, TK_Inline, TK_Reference, TK_ColonEquals, TK_EndSection;
+typedef Vector<IncludeHistoryItem> IncludeHistory;
+
+struct Parser
+{
+%%{
+       parser Parser;
 
        # General tokens.
-       token TK_UInt, TK_Hex, TK_Word, TK_Literal, TK_BaseClause,
-               TK_DotDot, TK_ColonGt, TK_ColonGtGt, TK_LtColon, TK_Arrow,
-               TK_DoubleArrow, TK_StarStar, TK_ColonEquals, TK_NameSep, TK_BarStar,
-               TK_DashDash;
+       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.
@@ -81,26 +90,29 @@ struct Parser
        token IL_WhiteSpace, IL_Comment, IL_Literal, IL_Symbol;
 
        # Keywords.
-       token KW_Action, KW_AlphType, KW_Range, KW_GetKey, KW_Include, KW_Write,
-               KW_Machine, KW_When, KW_Eof, KW_Err, KW_Lerr, KW_To, KW_From;
+       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;
 
        # 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;
+}%%
 
-       # Special token for terminating semi-terminated code blocks. Needed because
-       # semi is sent as a token in the code block rather than as a generic
-       # symbol.
-       token TK_Semi;
+       %% write instance_data;
 
-       interface;
-       }%%
+       void init();
+       int parseLangEl( int type, const Token *token );
 
-       Parser( char *fileName, char *sectionName, InputLoc &sectionLoc )
+       Parser( const char *fileName, char *sectionName, InputLoc &sectionLoc )
                : 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 );
@@ -108,7 +120,7 @@ struct Parser
                JoinOrLm *joinOrLm, bool isInstance );
 
        /* Report an error encountered by the parser. */
-       ostream &parser_error( int tokId, Token &token );
+       ostream &parse_error( int tokId, Token &token );
 
        ParseData *pd;
 
@@ -117,6 +129,11 @@ struct Parser
 
        NameRef nameRef;
        NameRefList nameRefList;
+
+       Vector<bool> exportContext;
+       IncludeHistory includeHistory;
 };
 
+%% write token_defs;
+
 #endif