/**
 * @file src/parser/lexer.h
 * @brief Declaration of class Lexer.
 * @copyright (c) 2017 Avast Software, licensed under the MIT license
 */

#pragma once

#ifndef yyFlexLexerOnce
#include <FlexLexer.h>
#endif

#include "yaramod/yy/yy_parser.hpp"

namespace yaramod {

class ParserDriver;

namespace yy {

/**
 * Class representing lexer engine.
 */
class Lexer : public yyFlexLexer
{
public:
	/// @name Constructors
	/// @{
	/**
	 * Constructor.
	 *
	 * @param driver Parser driver.
	 * @param input Input stream.
	 */
	Lexer(ParserDriver& driver, std::istream* input = nullptr) : yyFlexLexer(input), _driver(driver)
	{
		// Uncomment for debugging flex
		//yy_flex_debug = 1;
	}
	/// @}

	/// @name Methods generated by flex
	/// @{
	Parser::symbol_type getNextToken();
	/// @}

	/// @name Methods defined yy/lexer.l
	/// @{
	void includeFile(std::istream* input);
	bool includeEnd();
	void switchToYaraLexer();
	void switchToHexLexer();
	void switchToRegexpLexer();
	/// @}

protected:
	ParserDriver& _driver; ///< Parser driver.

	std::string _strLiteral; ///< Currently processed string literal.
	std::string _regexpClass; ///< Currently processed regular expression class.
};

}
}
