X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Console%2FParse.ih;h=5129197d9b824b1fae0dfb58bfefaf7805868e89;hb=fa5eaa97c8593e3587c87f25adb14f7f91f31f37;hp=0de5ade57303844225c4b82ed7e99cee97ed63e4;hpb=2d5a1fd2cef2d84e16226a7336948f524fbb71c6;p=senf.git diff --git a/Console/Parse.ih b/Console/Parse.ih index 0de5ade..5129197 100644 --- a/Console/Parse.ih +++ b/Console/Parse.ih @@ -82,10 +82,21 @@ namespace detail { /////////////////////////////////////////////////////////////////////////// // The parse context (variables needed while parsing) + typedef ArgumentToken::TokenType TokenType; + struct Context { std::string str; std::vector path; char ch; + TokenType type; + + // OUCH ... This is sooooo stupid .. push_back_a and assign_a take their + // arguments by const-reference and STORE the REFERENCE ... they do NOT accept + // literal values !!!!!! + static const TokenType BasicString; + static const TokenType HexString; + static const TokenType Word; + static const std::string EmptyString; }; Context & context; @@ -118,6 +129,10 @@ namespace detail { Dispatch_actor dispatch(Callback cb, Arg const & arg) const { return Dispatch_actor(boost::bind(cb, boost::ref(dispatcher), arg)); } + template + Dispatch_actor dispatch(Callback cb, Arg1 const & arg1, Arg2 const & arg2) const + { return Dispatch_actor(boost::bind(cb, boost::ref(dispatcher), arg1, arg2)); } + /////////////////////////////////////////////////////////////////////////// CommandGrammar(ParseDispatcher & d, Context & c) @@ -140,7 +155,8 @@ namespace detail { special_p ("/(){};"), // Characters which are returned as punctuation tokens - punctuation_p (",="), + // (only allowed within '()') + punctuation_p (",=/{};"), // Whitespace characters space_p (" \t\n\r"), @@ -241,6 +257,7 @@ namespace detail { argument = simple_argument [ self.dispatch(&PD::pushArgument, + boost::ref(self.context.type), boost::ref(self.context.str)) ] | complex_argument ; @@ -259,6 +276,8 @@ namespace detail { string // Returns value in context.str = eps_p [ clear_a(self.context.str) ] + >> eps_p [ assign_a(self.context.type, + self.context.BasicString) ] >> lexeme_d [ ch_p('"') @@ -273,6 +292,8 @@ namespace detail { hexstring // Returns value in context.str = eps_p [ clear_a(self.context.str) ] + >> eps_p [ assign_a(self.context.type, + self.context.HexString) ] >> confix_p( "x\"", * hexbyte, '"' ) ; @@ -282,13 +303,15 @@ namespace detail { ; relpath - = ( word [ push_back_a(self.context.path) ] + = ( word [ push_back_a(self.context.path) ] % ch_p('/') ) - >> ( ! ch_p('/') [ push_back_a(self.context.path,"") ] ) + >> ( ! ch_p('/') [ push_back_a(self.context.path, + self.context.EmptyString) ] ) ; abspath - = ch_p('/') [ push_back_a(self.context.path, "") ] + = ch_p('/') [ push_back_a(self.context.path, + self.context.EmptyString) ] >> ( relpath | eps_p [ push_back_a(self.context.path, "") ] ) ; @@ -300,7 +323,8 @@ namespace detail { ; token - = simple_argument [ self.dispatch(&PD::pushWord, + = simple_argument [ self.dispatch(&PD::pushWord, + boost::ref(self.context.type), boost::ref(self.context.str)) ] | punctuation [ self.dispatch(&PD::pushPunctuation, boost::ref(self.context.str)) ] @@ -312,7 +336,12 @@ namespace detail { ; word // Returns value in context.str - = lexeme_d[ + word_p ] [ assign_a(self.context.str) ] + = lexeme_d + [ + eps_p [ assign_a(self.context.type, + self.context.Word) ] + >> (+ word_p) [ assign_a(self.context.str) ] + ] ; hexbyte @@ -353,7 +382,20 @@ namespace detail { }; }; + template + ArgumentToken::TokenType const CommandGrammar::Context::BasicString ( + ArgumentToken::BasicString); + + template + ArgumentToken::TokenType const CommandGrammar::Context::HexString( + ArgumentToken::HexString); + template + ArgumentToken::TokenType const CommandGrammar::Context::Word( + ArgumentToken::Word); + + template + std::string const CommandGrammar::Context::EmptyString; #endif