/*
    Copyright (C) 2012 Bartosz Broda, Jacek Bochenek, Łukasz Biłeńkij, 
    Damian Jaworski, Wojciech Mazur, Dominik Piasecki, Maciej Piasecki, 
    Radosław Ramocki
    
    This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your option)
any later version.

    This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. 

    See the LICENSE and COPYING files for more details.
*/

#ifndef LEXICALUNITS_MEPARSER_H
#define LEXICALUNITS_MEPARSER_H
#include "../lex_headers.h"
#include "Makro.h"
#include "UnitStub.h"

namespace LexicalUnits
{
	namespace MEParser
	{
		class MEParser
		{
		public:
			/**
			 * Parse input stream
			 */ 
			void Parse(std::istream& inStream);
			/**
			 * Parse input file.
			 */ 
			void Parse(const char* inFile);


			std::vector<LexicalUnitPtr> GetUnits();
				
		private:

			std::map<std::string, MakroPtr> m_MakroNameToMakro;
			std::vector<UnitStubPtr> m_vStubs;

			std::vector<LexicalUnitPtr> m_vUnits;

			void InstantiateUnits();

			//helpers for parsing:
			std::string ParseMakros(std::istream &in, std::string &eaten);
			std::string ParseSingleMakro(std::istream &in, std::string &eaten);
			std::string ParseConLinesMakro(std::istream &in, std::string &eaten, std::vector<std::string> &opLines);

			std::string ParseLUList(std::istream &in, std::string &eaten);
			std::string ParseSingleLU(std::istream &in, std::string &eaten);

			static boost::regex m_AnyTagOpenening;
			static boost::regex m_AnyTagClosing;
			
			// regex for makro tags
			static boost::regex m_MakroTagOpen;
			static boost::regex m_MakroTagClose;
			static boost::regex m_MTagOpen;
			static boost::regex m_MTagClose;
			static boost::regex m_NameTag;
			static boost::regex m_VarTag;
			static boost::regex m_ConTagOpen;
			static boost::regex m_ConTagClose;

			// regex for lexical units tag
			static boost::regex m_LUListTagOpen;
			static boost::regex m_LUListTagClose;
			static boost::regex m_LUTagOpen;
			static boost::regex m_LUTagClose;
			static boost::regex m_LuBaseTag;
			static boost::regex m_TTag;
			static boost::regex m_PatTag;
			static boost::regex m_HTag;
			static boost::regex m_FTag;
			/*For future use:
			static boost::regex m_FTagOpen;
			static boost::regex m_FTagClose;
			*/
			
		};//class MEParser
	}//namespace MEParser
}//namespace LexicalUnits
#endif //LEXICALUNITS_MEPARSER_H
