From b7b7c4d61e8b9c196f4c0cb578cd5799caad72d6 Mon Sep 17 00:00:00 2001 From: Charles Baker Date: Sun, 21 May 2023 19:53:46 +1200 Subject: [PATCH] Move Lexer::set_action_handler() to non-const member section --- src/lalr/Lexer.hpp | 2 +- src/lalr/Lexer.ipp | 74 +++++++++++++++++++++++----------------------- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/lalr/Lexer.hpp b/src/lalr/Lexer.hpp index e8060fa..6847e33 100644 --- a/src/lalr/Lexer.hpp +++ b/src/lalr/Lexer.hpp @@ -48,13 +48,13 @@ class Lexer public: Lexer( const LexerStateMachine* state_machine, const LexerStateMachine* whitespace_state_machine = nullptr, const void* end_symbol = nullptr, ErrorPolicy* error_policy = nullptr ); - void set_action_handler( const char* identifier, LexerActionFunction function ); const std::basic_string& lexeme() const; int line() const; int column() const; const void* symbol() const; const Iterator& position() const; bool full() const; + void set_action_handler( const char* identifier, LexerActionFunction function ); void reset( Iterator start, Iterator finish ); void advance(); diff --git a/src/lalr/Lexer.ipp b/src/lalr/Lexer.ipp index 50973c0..d0702a6 100644 --- a/src/lalr/Lexer.ipp +++ b/src/lalr/Lexer.ipp @@ -88,43 +88,6 @@ Lexer::Lexer( const LexerStateMachine* state_ } } -/** -// Set the action handler for \e identifier to \e function. -// -// @param identifier -// The identifier of the action to set a handler for. -// -// @param function -// The function to set as the handler. -*/ -template -void Lexer::set_action_handler( const char* identifier, LexerActionFunction function ) -{ - LALR_ASSERT( identifier ); - - typename std::vector::iterator action_handler = action_handlers_.begin(); - while ( action_handler != action_handlers_.end() && strcmp(action_handler->action_->identifier, identifier) != 0 ) - { - ++action_handler; - } - - if ( action_handler != action_handlers_.end() ) - { - action_handler->function_ = function; - } - - action_handler = whitespace_action_handlers_.begin(); - while ( action_handler != whitespace_action_handlers_.end() && strcmp(action_handler->action_->identifier, identifier) != 0 ) - { - ++action_handler; - } - - if ( action_handler != whitespace_action_handlers_.end() ) - { - action_handler->function_ = function; - } -} - /** // Get the most recently scanned lexeme. // @@ -197,6 +160,43 @@ bool Lexer::full() const return full_; } +/** +// Set the action handler for \e identifier to \e function. +// +// @param identifier +// The identifier of the action to set a handler for. +// +// @param function +// The function to set as the handler. +*/ +template +void Lexer::set_action_handler( const char* identifier, LexerActionFunction function ) +{ + LALR_ASSERT( identifier ); + + typename std::vector::iterator action_handler = action_handlers_.begin(); + while ( action_handler != action_handlers_.end() && strcmp(action_handler->action_->identifier, identifier) != 0 ) + { + ++action_handler; + } + + if ( action_handler != action_handlers_.end() ) + { + action_handler->function_ = function; + } + + action_handler = whitespace_action_handlers_.begin(); + while ( action_handler != whitespace_action_handlers_.end() && strcmp(action_handler->action_->identifier, identifier) != 0 ) + { + ++action_handler; + } + + if ( action_handler != whitespace_action_handlers_.end() ) + { + action_handler->function_ = function; + } +} + /** // Reset this %Lexer to scan [\e start, \e finish) starting its line count // from \e line.