From: thurston Date: Wed, 4 Apr 2007 02:27:54 +0000 (+0000) Subject: Use the new import feature of Ragel for bringing in defines from the parser X-Git-Tag: 2.0_alpha~333 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a76b1ca9ae9d7a0adebbc762ef3e3b171a77a44b;p=external%2Fragel.git Use the new import feature of Ragel for bringing in defines from the parser header as machine definitions instead of repeating them in scanner. git-svn-id: http://svn.complang.org/ragel/trunk@162 052ea7fc-9027-0410-9066-f65837a77df0 --- diff --git a/ragel/Makefile.in b/ragel/Makefile.in index 30bd0ac..e8e63a3 100644 --- a/ragel/Makefile.in +++ b/ragel/Makefile.in @@ -60,6 +60,10 @@ rlparse.h: rlparse.kh rlparse.cpp: rlparse.kl rlparse.kh kelbt -o $@ $< +# This dependency comes from the import of the parser defines +# into the scanner. +rlscan.cpp: rlparse.h + rlscan.cpp: rlscan.rl ragel $< | rlgen-cd -G2 -o $@ diff --git a/ragel/rlparse.kh b/ragel/rlparse.kh index a5498bb..7855926 100644 --- a/ragel/rlparse.kh +++ b/ragel/rlparse.kh @@ -26,23 +26,24 @@ #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 Parser { %%{ parser Parser; - # 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_Import, KW_Write, TK_Word, TK_Literal; - - token TK_Number, TK_Inline, TK_Reference, TK_ColonEquals, TK_EndSection; - # 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_Reference, TK_ColonEquals, + 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; @@ -77,9 +78,9 @@ 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, - KW_Export; + token KW_Machine, KW_Include, KW_Import, KW_Write, 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, KW_Export; # Specials in code blocks. token KW_Break, KW_Exec, KW_Hold, KW_PChar, KW_Char, KW_Goto, KW_Call, diff --git a/ragel/rlscan.rl b/ragel/rlscan.rl index 70e97fd..264bb3b 100644 --- a/ragel/rlscan.rl +++ b/ragel/rlscan.rl @@ -46,20 +46,13 @@ enum InlineBlockType * The Scanner for Importing */ -#define IMP_Word 128 -#define IMP_Literal 129 -#define IMP_UInt 130 -#define IMP_Define 131 - %%{ machine inline_token_scan; alphtype int; access tok_; - IMP_Word = 128; - IMP_Literal = 129; - IMP_UInt = 130; - IMP_Define = 131; + # Import scanner tokens. + import "rlparse.h"; main := |* # Define of number. @@ -267,14 +260,8 @@ void Scanner::updateCol() %%{ machine section_parse; - # This relies on the the kelbt implementation and the order - # that tokens are declared. - KW_Machine = 128; - KW_Include = 129; - KW_Import = 130; - KW_Write = 131; - TK_Word = 132; - TK_Literal = 133; + # Need the defines representing tokens. + import "rlparse.h"; action clear_words { word = lit = 0; word_len = lit_len = 0; } action store_word { word = tokdata; word_len = toklen; }