87 lines
2.4 KiB
C++
87 lines
2.4 KiB
C++
/**
|
|
* @author Edouard DUPIN
|
|
* @copyright 2017, Edouard DUPIN, all right reserved
|
|
* @license MPL-2 (see license file)
|
|
*/
|
|
#pragma once
|
|
|
|
#include <etk/types.hpp>
|
|
#include <estyle/lexer/tocken.hpp>
|
|
#include <etk/math/Vector2D.hpp>
|
|
namespace estyle {
|
|
class LexerElement {
|
|
private:
|
|
enum estyle::lexer::tocken m_tocken; //!< The type of the token that we have
|
|
int32_t m_start; //!< Position in the data begin in the stream
|
|
int32_t m_stop; //!< Position in the data end in the stream
|
|
public:
|
|
LexerElement(enum estyle::lexer::tocken _tocken, int32_t _start, int32_t _stop) :
|
|
m_tocken(_tocken),
|
|
m_start(_start),
|
|
m_stop(_stop) {
|
|
|
|
}
|
|
enum estyle::lexer::tocken getTocken() const {
|
|
return m_tocken;
|
|
}
|
|
void setTocken(enum estyle::lexer::tocken _tocken) {
|
|
m_tocken = _tocken;
|
|
}
|
|
int32_t getStart() const {
|
|
return m_start;
|
|
}
|
|
void setStart(int32_t _pos) {
|
|
m_start = _pos;
|
|
}
|
|
int32_t getStop() const {
|
|
return m_stop;
|
|
}
|
|
void setStop(int32_t _pos) {
|
|
m_stop = _pos;
|
|
}
|
|
private:
|
|
//special case of complex element:
|
|
etk::Vector<estyle::LexerElement> m_list;
|
|
public:
|
|
void pushElement(const estyle::LexerElement& _element) {
|
|
m_list.pushBack(_element);
|
|
}
|
|
const etk::Vector<estyle::LexerElement>& getList() const {
|
|
return m_list;
|
|
}
|
|
};
|
|
class Lexer {
|
|
private:
|
|
etk::String m_stream;
|
|
etk::Vector<estyle::LexerElement> m_list;
|
|
public:
|
|
Lexer();
|
|
void lexify(const etk::String& _input);
|
|
public:
|
|
// squash element name space like "::lklkmlk" and "lmkmlk::lmkmlk::mlklk" in 1 element
|
|
void postAnnalyse_namespace();
|
|
void postAnnalyse_function();
|
|
void postAnnalyse_function_typeExtern();
|
|
void postAnnalyse_function_typeInternal();
|
|
public:
|
|
int64_t size() const {
|
|
return m_list.size();
|
|
}
|
|
enum estyle::lexer::tocken getTocken(int32_t _position) const {
|
|
return m_list[_position].getTocken();
|
|
}
|
|
const etk::Vector<estyle::LexerElement>& getSubList(int32_t _position) const {
|
|
return m_list[_position].getList();
|
|
}
|
|
etk::String getData(int32_t _position) const;
|
|
etk::String getDataSource(int32_t _start, int32_t _stop) const;
|
|
etk::String getValueString(int32_t _position) const;
|
|
ivec2 getFilePosition(int32_t _position) const;
|
|
etk::String getFileLine(int32_t _position) const;
|
|
private:
|
|
void getChar(size_t _iii, char& _currentChar, char& _nextChar);
|
|
void parse();
|
|
|
|
};
|
|
}
|