diff --git a/src/lalr/Parser.hpp b/src/lalr/Parser.hpp index b46ccae..425ab6d 100644 --- a/src/lalr/Parser.hpp +++ b/src/lalr/Parser.hpp @@ -68,18 +68,16 @@ public: bool full() const; const UserData& user_data() const; const Lexer& lexer() const; + void fire_error(int line, int column, int error, const char* format, ... ) const; + void fire_printf( const char* format, ... ) const; + bool is_debug_enabled() const; AddParserActionHandler parser_action_handlers(); AddLexerActionHandler lexer_action_handlers(); void set_default_action_handler( ParserActionFunction function ); void set_action_handler( const char* identifier, ParserActionFunction function ); - void set_lexer_action_handler( const char* identifier, LexerActionFunction function ); - - void fire_error(int line, int column, int error, const char* format, ... ) const; - void fire_printf( const char* format, ... ) const; - + void set_lexer_action_handler( const char* identifier, LexerActionFunction function ); void set_debug_enabled( bool debug_enabled ); - bool is_debug_enabled() const; private: const ParserTransition* find_transition( const ParserSymbol* symbol, const ParserState* state ) const; diff --git a/src/lalr/Parser.ipp b/src/lalr/Parser.ipp index 4848108..2fa1995 100644 --- a/src/lalr/Parser.ipp +++ b/src/lalr/Parser.ipp @@ -254,6 +254,69 @@ const Lexer& Parser +void Parser::fire_error( int line, int column, int error, const char* format, ... ) const +{ + if ( error_policy_ ) + { + va_list args; + va_start( args, format ); + error_policy_->lalr_error( line, column, error, format, args ); + va_end( args ); + } +} + +/** +// Fire a printf event. +// +// @param format +// A printf style format string that describes the message to print. +// +// @param ... +// Parameters to fill in the message as specified by \e format. +*/ +template +void Parser::fire_printf( const char* format, ... ) const +{ + if ( error_policy_ ) + { + LALR_ASSERT( format ); + va_list args; + va_start( args, format ); + error_policy_->lalr_vprintf( format, args ); + va_end( args ); + } + else + { + va_list args; + va_start( args, format ); + vfprintf( stdout, format, args ); + va_end( args ); + } +} + +/** +// Are shift and reduce operations printed? +// +// @return +// True if shift and reduce operations are printed otherwise false. +*/ +template +bool Parser::is_debug_enabled() const +{ + return debug_enabled_; +} + /** // Add action handlers to this %Parser. // @@ -337,57 +400,6 @@ void Parser::set_lexer_action_handl lexer_.set_action_handler( identifier, function ); } -/** -// Fire an %error event. -// -// @param line -// The line number to associate with the %error (or 0 if there is no line -// to associate with the %error). -// -// @param error -// The %Error that describes the %error that has occured. -*/ -template -void Parser::fire_error( int line, int column, int error, const char* format, ... ) const -{ - if ( error_policy_ ) - { - va_list args; - va_start( args, format ); - error_policy_->lalr_error( line, column, error, format, args ); - va_end( args ); - } -} - -/** -// Fire a printf event. -// -// @param format -// A printf style format string that describes the message to print. -// -// @param ... -// Parameters to fill in the message as specified by \e format. -*/ -template -void Parser::fire_printf( const char* format, ... ) const -{ - if ( error_policy_ ) - { - LALR_ASSERT( format ); - va_list args; - va_start( args, format ); - error_policy_->lalr_vprintf( format, args ); - va_end( args ); - } - else - { - va_list args; - va_start( args, format ); - vfprintf( stdout, format, args ); - va_end( args ); - } -} - /** // Set whether or not shift operations are printed. // @@ -401,18 +413,6 @@ void Parser::set_debug_enabled( boo debug_enabled_ = debug_enabled; } -/** -// Are shift and reduce operations printed? -// -// @return -// True if shift and reduce operations are printed otherwise false. -*/ -template -bool Parser::is_debug_enabled() const -{ - return debug_enabled_; -} - /** // Find the Transition for \e symbol in \e state. //