[DEV] continue build
This commit is contained in:
parent
2e7feacb3d
commit
7d3c72a405
@ -85,33 +85,33 @@ etk::String estyle::Generator::getDoxygenNLine(const etk::String& _data) {
|
||||
|
||||
|
||||
|
||||
void estyle::Generator::addSpace(etk::String& _data) {
|
||||
if (_data.size() == 0) {
|
||||
void estyle::Generator::addSpace() {
|
||||
if (m_output.size() == 0) {
|
||||
return;
|
||||
}
|
||||
if (_data.back() == '\0') {
|
||||
ESTYLE_TODO("TODO : Do indentation... : '" << _data << "'");
|
||||
if (m_output.back() == '\0') {
|
||||
ESTYLE_TODO("TODO : Do indentation... : '" << m_output << "'");
|
||||
}
|
||||
if (_data.back() == '\n') {
|
||||
if (m_output.back() == '\n') {
|
||||
if (propertyIndentWithTabulation.get() == true) {
|
||||
for (int32_t iii=0; iii<m_indentation; ++iii) {
|
||||
_data += "\t";
|
||||
m_output += "\t";
|
||||
}
|
||||
} else {
|
||||
for (int32_t iii=0; iii<m_indentation; ++iii) {
|
||||
for (int32_t jjj=0; jjj<propertyIndentSize.get(); ++jjj) {
|
||||
_data += " ";
|
||||
m_output += " ";
|
||||
}
|
||||
}
|
||||
}
|
||||
ESTYLE_TODO("TODO : Do indentation...");
|
||||
return;
|
||||
}
|
||||
if ( _data.back() == ' '
|
||||
|| _data.back() == '\t') {
|
||||
if ( m_output.back() == ' '
|
||||
|| m_output.back() == '\t') {
|
||||
return;
|
||||
}
|
||||
_data += " ";
|
||||
m_output += " ";
|
||||
}
|
||||
|
||||
enum class stack {
|
||||
@ -130,161 +130,167 @@ enum class stack {
|
||||
etk::Vector<enum stack> m_urrentStack;
|
||||
|
||||
etk::String estyle::Generator::process(const etk::String& _code) {
|
||||
estyle::Lexer lexer(_code);
|
||||
etk::String out;
|
||||
for (size_t iii = 0; iii < lexer.size(); ++iii) {
|
||||
enum estyle::lexer::tocken elem = lexer.getTocken(iii);
|
||||
m_lexer.lexify(_code);
|
||||
process(0, estyle::lexer::END_OF_FILE) {
|
||||
return m_output;
|
||||
};
|
||||
int32_t estyle::Generator::process(int32_t _startId, enum estyle::lexer::tocken _endTocken) {
|
||||
for (size_t iii = _startId; iii < m_lexer.size(); ++iii) {
|
||||
enum estyle::lexer::tocken elem = m_lexer.getTocken(iii);
|
||||
if (elem == _endTocken) {
|
||||
return iii;
|
||||
}
|
||||
if (elem == estyle::lexer::RESERVED_COMMENT_1_LINE) {
|
||||
out += "//";
|
||||
out += lexer.getData(iii);
|
||||
out += getEndOfLine();
|
||||
m_output += "//";
|
||||
m_output += m_lexer.getData(iii);
|
||||
m_output += getEndOfLine();
|
||||
continue;
|
||||
}
|
||||
if (elem == estyle::lexer::RESERVED_DOCUMENTATION_1_LINE) {
|
||||
out += getDoxygenOneLine();
|
||||
out += lexer.getData(iii);
|
||||
out += getEndOfLine();
|
||||
m_output += getDoxygenOneLine();
|
||||
m_output += m_lexer.getData(iii);
|
||||
m_output += getEndOfLine();
|
||||
continue;
|
||||
}
|
||||
if (elem == estyle::lexer::RESERVED_COMMENT_N_LINE) {
|
||||
addSpace(out);
|
||||
out += "/*";
|
||||
out += lexer.getData(iii);
|
||||
out += "*/";
|
||||
if (iii+1 < lexer.size()) {
|
||||
if (lexer.getTocken(iii+1) == estyle::lexer::RESERVED_NEW_LINE) {
|
||||
out += getEndOfLine();
|
||||
addSpace();
|
||||
m_output += "/*";
|
||||
m_output += m_lexer.getData(iii);
|
||||
m_output += "*/";
|
||||
if (iii+1 < m_lexer.size()) {
|
||||
if (m_lexer.getTocken(iii+1) == estyle::lexer::RESERVED_NEW_LINE) {
|
||||
m_output += getEndOfLine();
|
||||
++iii;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (elem == estyle::lexer::RESERVED_DOCUMENTATION_1_LINE) {
|
||||
addSpace(out);
|
||||
out += getDoxygenNLine(lexer.getData(iii));
|
||||
out += getEndOfLine();
|
||||
addSpace();
|
||||
m_output += getDoxygenNLine(m_lexer.getData(iii));
|
||||
m_output += getEndOfLine();
|
||||
// TODO : Some mode can create error like /** */ becaming /// ...
|
||||
if (iii+1 < lexer.size()) {
|
||||
if (lexer.getTocken(iii+1) == estyle::lexer::RESERVED_NEW_LINE) {
|
||||
out += getEndOfLine();
|
||||
if (iii+1 < m_lexer.size()) {
|
||||
if (m_lexer.getTocken(iii+1) == estyle::lexer::RESERVED_NEW_LINE) {
|
||||
m_output += getEndOfLine();
|
||||
++iii;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (elem == estyle::lexer::BASIC_TYPE_INTEGER_SIZE_T) {
|
||||
addSpace(out);
|
||||
out += "size_t";
|
||||
addSpace();
|
||||
m_output += "size_t";
|
||||
continue;
|
||||
}
|
||||
if (elem == estyle::lexer::BASIC_TYPE_INTEGER_008) {
|
||||
addSpace(out);
|
||||
out += "int8_t";
|
||||
addSpace();
|
||||
m_output += "int8_t";
|
||||
continue;
|
||||
}
|
||||
if (elem == estyle::lexer::BASIC_TYPE_INTEGER_008_UNSIGNED) {
|
||||
addSpace(out);
|
||||
out += "uint8_t";
|
||||
addSpace();
|
||||
m_output += "uint8_t";
|
||||
continue;
|
||||
}
|
||||
if (elem == estyle::lexer::BASIC_TYPE_INTEGER_016) {
|
||||
addSpace(out);
|
||||
out += "int16_t";
|
||||
addSpace();
|
||||
m_output += "int16_t";
|
||||
continue;
|
||||
}
|
||||
if (elem == estyle::lexer::BASIC_TYPE_INTEGER_016_UNSIGNED) {
|
||||
addSpace(out);
|
||||
out += "uint16_t";
|
||||
addSpace();
|
||||
m_output += "uint16_t";
|
||||
continue;
|
||||
}
|
||||
if (elem == estyle::lexer::BASIC_TYPE_INTEGER_032) {
|
||||
addSpace(out);
|
||||
out += "int32_t";
|
||||
addSpace();
|
||||
m_output += "int32_t";
|
||||
continue;
|
||||
}
|
||||
if (elem == estyle::lexer::BASIC_TYPE_INTEGER_032_UNSIGNED) {
|
||||
addSpace(out);
|
||||
out += "uint32_t";
|
||||
addSpace();
|
||||
m_output += "uint32_t";
|
||||
continue;
|
||||
}
|
||||
if (elem == estyle::lexer::BASIC_TYPE_INTEGER_064) {
|
||||
addSpace(out);
|
||||
out += "int64_t";
|
||||
addSpace();
|
||||
m_output += "int64_t";
|
||||
continue;
|
||||
}
|
||||
if (elem == estyle::lexer::BASIC_TYPE_INTEGER_064_UNSIGNED) {
|
||||
addSpace(out);
|
||||
out += "uint64_t";
|
||||
addSpace();
|
||||
m_output += "uint64_t";
|
||||
continue;
|
||||
}
|
||||
if (elem == estyle::lexer::BASIC_TYPE_INTEGER_128) {
|
||||
addSpace(out);
|
||||
out += "int128_t";
|
||||
addSpace();
|
||||
m_output += "int128_t";
|
||||
continue;
|
||||
}
|
||||
if (elem == estyle::lexer::BASIC_TYPE_INTEGER_128_UNSIGNED) {
|
||||
addSpace(out);
|
||||
out += "uint128_t";
|
||||
addSpace();
|
||||
m_output += "uint128_t";
|
||||
continue;
|
||||
}
|
||||
if (elem == estyle::lexer::BASIC_TYPE_FLOAT_32) {
|
||||
addSpace(out);
|
||||
out += "float";
|
||||
addSpace();
|
||||
m_output += "float";
|
||||
continue;
|
||||
}
|
||||
if (elem == estyle::lexer::BASIC_TYPE_FLOAT_64) {
|
||||
addSpace(out);
|
||||
out += "double";
|
||||
addSpace();
|
||||
m_output += "double";
|
||||
continue;
|
||||
}
|
||||
if (elem == estyle::lexer::BASIC_TYPE_FLOAT_96) {
|
||||
addSpace(out);
|
||||
out += "triple";
|
||||
addSpace();
|
||||
m_output += "triple";
|
||||
continue;
|
||||
}
|
||||
if (elem == estyle::lexer::BASIC_TYPE_BOOLEAN) {
|
||||
addSpace(out);
|
||||
out += "bool";
|
||||
addSpace();
|
||||
m_output += "bool";
|
||||
continue;
|
||||
}
|
||||
if (elem == estyle::lexer::BASIC_TYPE_VOID) {
|
||||
addSpace(out);
|
||||
out += "void";
|
||||
addSpace();
|
||||
m_output += "void";
|
||||
continue;
|
||||
}
|
||||
if (elem == estyle::lexer::SEMICOLON) {
|
||||
out += ";";
|
||||
out += getEndOfLine();
|
||||
m_output += ";";
|
||||
m_output += getEndOfLine();
|
||||
continue;
|
||||
}
|
||||
if (elem == estyle::lexer::ID) {
|
||||
addSpace(out);
|
||||
out += lexer.getData(iii);
|
||||
addSpace();
|
||||
m_output += m_lexer.getData(iii);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (elem == estyle::lexer::EQUAL) {
|
||||
out += "=";
|
||||
m_output += "=";
|
||||
continue;
|
||||
}
|
||||
if (elem == estyle::lexer::STRING) {
|
||||
out += "\"";
|
||||
out += lexer.getData(iii);
|
||||
out += "\"";
|
||||
m_output += "\"";
|
||||
m_output += m_lexer.getData(iii);
|
||||
m_output += "\"";
|
||||
continue;
|
||||
}
|
||||
if (elem == estyle::lexer::SIMPLE_QUOTE_STRING) {
|
||||
out += "'";
|
||||
out += lexer.getData(iii);
|
||||
out += "'";
|
||||
m_output += "'";
|
||||
m_output += m_lexer.getData(iii);
|
||||
m_output += "'";
|
||||
continue;
|
||||
}
|
||||
if (elem == estyle::lexer::BRACE_IN) {
|
||||
m_urrentStack.pushBack(stack::BLOCK);
|
||||
out += getEndOfLine();
|
||||
//addSpace(out);
|
||||
out += "{";
|
||||
out += getEndOfLine();
|
||||
m_output += getEndOfLine();
|
||||
//addSpace();
|
||||
m_output += "{";
|
||||
m_output += getEndOfLine();
|
||||
m_indentation++;
|
||||
continue;
|
||||
}
|
||||
@ -298,23 +304,23 @@ etk::String estyle::Generator::process(const etk::String& _code) {
|
||||
} else {
|
||||
m_urrentStack.popBack();
|
||||
}
|
||||
out += getEndOfLine();
|
||||
addSpace(out);
|
||||
out += "}";
|
||||
out += getEndOfLine();
|
||||
m_output += getEndOfLine();
|
||||
addSpace();
|
||||
m_output += "}";
|
||||
m_output += getEndOfLine();
|
||||
continue;
|
||||
}
|
||||
if (elem == estyle::lexer::RESERVED_IF) {
|
||||
addSpace(out);
|
||||
addSpace();
|
||||
int32_t spaceOffset = 4;
|
||||
out += "if ";
|
||||
for (size_t jjj=iii+1; jjj<lexer.size(); ++jjj) {
|
||||
enum estyle::lexer::tocken elem = lexer.getTocken(jjj);
|
||||
m_output += "if ";
|
||||
for (size_t jjj=iii+1; jjj<m_lexer.size(); ++jjj) {
|
||||
enum estyle::lexer::tocken elem = m_lexer.getTocken(jjj);
|
||||
if (elem == estyle::lexer::RESERVED_NEW_LINE) {
|
||||
// OK ==> normal case ...
|
||||
} else if (elem == estyle::lexer::PARENTHESE_IN) {
|
||||
// find condition section ...
|
||||
iii = generateCondition(lexer, jjj, out, spaceOffset);
|
||||
iii = generateCondition(jjj, m_output, spaceOffset);
|
||||
break;
|
||||
} else {
|
||||
ESTYLE_ERROR("Get 'if' without '(' element");
|
||||
@ -323,28 +329,27 @@ etk::String estyle::Generator::process(const etk::String& _code) {
|
||||
continue;
|
||||
}
|
||||
// default other case:
|
||||
addSpace(out);
|
||||
out += lexer.getData(iii);
|
||||
addSpace();
|
||||
m_output += m_lexer.getData(iii);
|
||||
}
|
||||
|
||||
return out;
|
||||
};
|
||||
return m_lexer.size();
|
||||
}
|
||||
|
||||
size_t estyle::Generator::generateCondition(estyle::Lexer& _lexer, size_t _pos, etk::String& _data, int32_t _offset) {
|
||||
size_t estyle::Generator::generateCondition(size_t _pos, etk::String& _data, int32_t _offset) {
|
||||
|
||||
int32_t sectionEnd = endOfSection(_lexer, _pos);
|
||||
int32_t nbCondition = countCurrentLevelCondition(_lexer, _pos);
|
||||
int32_t sectionEnd = endOfSection(_pos);
|
||||
int32_t nbCondition = countCurrentLevelCondition(_pos);
|
||||
if (nbCondition == 0) {
|
||||
for (size_t iii=_pos; iii<=sectionEnd; ++iii) {
|
||||
addSpace(_data);
|
||||
_data += _lexer.getData(iii);
|
||||
_data += m_lexer.getData(iii);
|
||||
}
|
||||
} else {
|
||||
_data += "( ";
|
||||
for (size_t iii=_pos+1; iii<=sectionEnd; ++iii) {
|
||||
enum estyle::lexer::tocken elem = _lexer.getTocken(iii);
|
||||
enum estyle::lexer::tocken elem = m_lexer.getTocken(iii);
|
||||
if (elem == estyle::lexer::PARENTHESE_IN) {
|
||||
iii = generateCondition(_lexer, iii, _data, _offset + 5);
|
||||
iii = generateCondition(m_lexer, iii, _data, _offset + 5);
|
||||
} else if ( elem == estyle::lexer::AND_AND
|
||||
|| elem == estyle::lexer::OR_OR) {
|
||||
_data += getEndOfLine();
|
||||
@ -352,10 +357,10 @@ size_t estyle::Generator::generateCondition(estyle::Lexer& _lexer, size_t _pos,
|
||||
for (int32_t ooo=0; ooo<_offset; ++ooo) {
|
||||
_data += " ";
|
||||
}
|
||||
_data += " " + _lexer.getData(iii) + " ";
|
||||
_data += " " + m_lexer.getData(iii) + " ";
|
||||
} else {
|
||||
addSpace(_data);
|
||||
_data += _lexer.getData(iii);
|
||||
_data += m_lexer.getData(iii);
|
||||
}
|
||||
}
|
||||
|
||||
@ -363,10 +368,10 @@ size_t estyle::Generator::generateCondition(estyle::Lexer& _lexer, size_t _pos,
|
||||
return sectionEnd;
|
||||
}
|
||||
|
||||
size_t estyle::Generator::endOfSection(estyle::Lexer& _lexer, size_t _pos) {
|
||||
ESTYLE_INFO(" " << _lexer.getTocken(_pos) << " " << _pos << " [BEGIN]");
|
||||
size_t estyle::Generator::endOfSection(size_t _pos) {
|
||||
ESTYLE_INFO(" " << m_lexer.getTocken(_pos) << " " << _pos << " [BEGIN]");
|
||||
enum estyle::lexer::tocken endTocken = estyle::lexer::END_OF_FILE;
|
||||
enum estyle::lexer::tocken elem = _lexer.getTocken(_pos);
|
||||
enum estyle::lexer::tocken elem = m_lexer.getTocken(_pos);
|
||||
if (elem == estyle::lexer::PARENTHESE_IN) {
|
||||
endTocken = estyle::lexer::PARENTHESE_OUT;
|
||||
} else if (elem == estyle::lexer::BRACKET_IN) {
|
||||
@ -374,28 +379,28 @@ size_t estyle::Generator::endOfSection(estyle::Lexer& _lexer, size_t _pos) {
|
||||
} else if (elem == estyle::lexer::BRACE_IN) {
|
||||
endTocken = estyle::lexer::BRACE_OUT;
|
||||
} else {
|
||||
ESTYLE_ERROR("can not get end position of " << _lexer.getTocken(_pos));
|
||||
ESTYLE_ERROR("can not get end position of " << m_lexer.getTocken(_pos));
|
||||
return _pos;
|
||||
}
|
||||
for (size_t iii=_pos+1; iii < _lexer.size(); ++iii) {
|
||||
elem = _lexer.getTocken(iii);
|
||||
for (size_t iii=_pos+1; iii < m_lexer.size(); ++iii) {
|
||||
elem = m_lexer.getTocken(iii);
|
||||
if (elem == endTocken) {
|
||||
return iii;
|
||||
}
|
||||
if ( elem == estyle::lexer::PARENTHESE_IN
|
||||
|| elem == estyle::lexer::BRACKET_IN
|
||||
|| elem == estyle::lexer::BRACE_IN) {
|
||||
iii = endOfSection(_lexer, iii);
|
||||
iii = endOfSection(m_lexer, iii);
|
||||
}
|
||||
}
|
||||
return _lexer.size();
|
||||
return m_lexer.size();
|
||||
}
|
||||
|
||||
|
||||
int32_t estyle::Generator::countCurrentLevelCondition(estyle::Lexer& _lexer, size_t _pos) {
|
||||
int32_t estyle::Generator::countCurrentLevelCondition(size_t _pos) {
|
||||
int32_t out;
|
||||
enum estyle::lexer::tocken endTocken = estyle::lexer::END_OF_FILE;
|
||||
enum estyle::lexer::tocken elem = _lexer.getTocken(_pos);
|
||||
enum estyle::lexer::tocken elem = m_lexer.getTocken(_pos);
|
||||
if (elem == estyle::lexer::PARENTHESE_IN) {
|
||||
endTocken = estyle::lexer::PARENTHESE_OUT;
|
||||
} else if (elem == estyle::lexer::BRACKET_IN) {
|
||||
@ -403,18 +408,18 @@ int32_t estyle::Generator::countCurrentLevelCondition(estyle::Lexer& _lexer, siz
|
||||
} else if (elem == estyle::lexer::BRACE_IN) {
|
||||
endTocken = estyle::lexer::BRACE_OUT;
|
||||
} else {
|
||||
ESTYLE_ERROR("can not get end position of " << _lexer.getTocken(_pos));
|
||||
ESTYLE_ERROR("can not get end position of " << m_lexer.getTocken(_pos));
|
||||
return _pos;
|
||||
}
|
||||
for (size_t iii=_pos+1; iii < _lexer.size(); ++iii) {
|
||||
elem = _lexer.getTocken(iii);
|
||||
for (size_t iii=_pos+1; iii < m_lexer.size(); ++iii) {
|
||||
elem = m_lexer.getTocken(iii);
|
||||
if (elem == endTocken) {
|
||||
return out;
|
||||
}
|
||||
if ( elem == estyle::lexer::PARENTHESE_IN
|
||||
|| elem == estyle::lexer::BRACKET_IN
|
||||
|| elem == estyle::lexer::BRACE_IN) {
|
||||
iii = endOfSection(_lexer, iii);
|
||||
iii = endOfSection(iii);
|
||||
}
|
||||
if ( elem == estyle::lexer::AND_AND
|
||||
|| elem == estyle::lexer::OR_OR) {
|
||||
@ -424,3 +429,35 @@ int32_t estyle::Generator::countCurrentLevelCondition(estyle::Lexer& _lexer, siz
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
int32_t estyle::Generator::countCurrentLevelComa(size_t _pos) {
|
||||
int32_t out;
|
||||
enum estyle::lexer::tocken endTocken = estyle::lexer::END_OF_FILE;
|
||||
enum estyle::lexer::tocken elem = m_lexer.getTocken(_pos);
|
||||
if (elem == estyle::lexer::PARENTHESE_IN) {
|
||||
endTocken = estyle::lexer::PARENTHESE_OUT;
|
||||
} else if (elem == estyle::lexer::BRACKET_IN) {
|
||||
endTocken = estyle::lexer::BRACKET_OUT;
|
||||
} else if (elem == estyle::lexer::BRACE_IN) {
|
||||
endTocken = estyle::lexer::BRACE_OUT;
|
||||
} else {
|
||||
ESTYLE_ERROR("can not get end position of " << m_lexer.getTocken(_pos));
|
||||
return _pos;
|
||||
}
|
||||
for (size_t iii=_pos+1; iii < m_lexer.size(); ++iii) {
|
||||
elem = m_lexer.getTocken(iii);
|
||||
if (elem == endTocken) {
|
||||
return out;
|
||||
}
|
||||
if ( elem == estyle::lexer::PARENTHESE_IN
|
||||
|| elem == estyle::lexer::BRACKET_IN
|
||||
|| elem == estyle::lexer::BRACE_IN) {
|
||||
iii = endOfSection(iii);
|
||||
}
|
||||
if (elem == estyle::lexer::COMA) {
|
||||
out++;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
|
@ -17,23 +17,26 @@ namespace estyle {
|
||||
public:
|
||||
Generator();
|
||||
~Generator();
|
||||
protected:
|
||||
public:
|
||||
eproperty::Value<bool> propertyEndOfLine;
|
||||
eproperty::Value<bool> propertyIndentWithTabulation;
|
||||
eproperty::Value<int8_t> propertyIndentSize;
|
||||
eproperty::Value<bool> propertyDoxygenOneLine;
|
||||
eproperty::List<int32_t> propertyDoxygenMultipleLine;
|
||||
private:
|
||||
estyle::Lexer m_lexer;
|
||||
int32_t m_indentation = 0;
|
||||
etk::String m_output;
|
||||
public:
|
||||
etk::String process(const etk::String& _code);
|
||||
private:
|
||||
void addSpace(etk::String& _data);
|
||||
void addSpace();
|
||||
etk::String getEndOfLine();
|
||||
etk::String getDoxygenOneLine();
|
||||
etk::String getDoxygenNLine(const etk::String& _data);
|
||||
int32_t m_indentation = 0;
|
||||
size_t endOfSection(estyle::Lexer& _lexer, size_t _pos);
|
||||
int32_t countCurrentLevelCondition(estyle::Lexer& _lexer, size_t _pos);
|
||||
size_t generateCondition(estyle::Lexer& _lexer, size_t _pos, etk::String& _data, int32_t _offset);
|
||||
size_t endOfSection(size_t _pos);
|
||||
int32_t countCurrentLevelCondition(size_t _pos);
|
||||
size_t generateCondition(size_t _pos, etk::String& _data, int32_t _offset);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -242,6 +242,24 @@ void estyle::Lexer::parse() {
|
||||
tockenElement = estyle::lexer::BOOLEAN;
|
||||
} else if (idData == "false") {
|
||||
tockenElement = estyle::lexer::BOOLEAN;
|
||||
} else if (idData == "throw") {
|
||||
tockenElement = estyle::lexer::RESERVED_THROW;
|
||||
} else if (idData == "try") {
|
||||
tockenElement = estyle::lexer::RESERVED_TRY;
|
||||
} else if (idData == "catch") {
|
||||
tockenElement = estyle::lexer::RESERVED_CATCH;
|
||||
} else if (idData == "#if") {
|
||||
tockenElement = estyle::lexer::RESERVED_SHARP_IF;
|
||||
} else if (idData == "#elif") {
|
||||
tockenElement = estyle::lexer::RESERVED_SHARP_ELSE_IF;
|
||||
} else if (idData == "#ifdef") {
|
||||
tockenElement = estyle::lexer::RESERVED_SHARP_IF_DEFINE;
|
||||
} else if (idData == "#ifndef") {
|
||||
tockenElement = estyle::lexer::RESERVED_SHARP_IF_NOT_DEFINE;
|
||||
} else if (idData == "#endif") {
|
||||
tockenElement = estyle::lexer::RESERVED_SHARP_END_IF;
|
||||
} else if (idData == "#else") {
|
||||
tockenElement = estyle::lexer::RESERVED_SHARP_ELSE;
|
||||
}
|
||||
m_list.pushBack(estyle::LexerElement(tockenElement, tokenStart, iii));
|
||||
iii--;
|
||||
@ -478,7 +496,12 @@ void estyle::Lexer::parse() {
|
||||
continue;
|
||||
}
|
||||
if (currentChar == ':') {
|
||||
m_list.pushBack(estyle::LexerElement(estyle::lexer::COLON, iii, iii+1));
|
||||
if (nextChar == ':') {
|
||||
m_list.pushBack(estyle::LexerElement(estyle::lexer::NAMESPACE, iii, iii+2));
|
||||
iii++;
|
||||
} else {
|
||||
m_list.pushBack(estyle::LexerElement(estyle::lexer::COLON, iii, iii+1));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (currentChar == ';') {
|
||||
@ -529,8 +552,13 @@ void estyle::Lexer::parse() {
|
||||
}
|
||||
}
|
||||
|
||||
estyle::Lexer::Lexer(const etk::String& _input) :
|
||||
m_stream(_input) {
|
||||
estyle::Lexer::Lexer() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void estyle::Lexer::lexify(const etk::String& _input) {
|
||||
m_stream = _input;
|
||||
ESTYLE_DEBUG("Parse stream");
|
||||
parse();
|
||||
ESTYLE_DEBUG("find:");
|
||||
@ -586,3 +614,37 @@ etk::String estyle::Lexer::getFileLine(int32_t _position) const {
|
||||
ESTYLE_WARNING("extract " << positionStart << " " << positionStop);
|
||||
return m_stream.extract(positionStart, positionStop);
|
||||
}
|
||||
|
||||
// squash element name space like "::lklkmlk" and "lmkmlk::lmkmlk::mlklk" in 1 element
|
||||
void estyle::Lexer::postAnnalyse_namespace() {
|
||||
auto it = m_list.begin();
|
||||
while (it != m_list.end()) {
|
||||
if (it->getTocken() == estyle::lexer::NAMESPACE) {
|
||||
// Remove next first ...
|
||||
{
|
||||
auto itTmp = it;
|
||||
++itTmp;
|
||||
if (it != m_list.end() {
|
||||
if (itTmp->getTocken() == estyle::lexer::ID) {
|
||||
it.setStop(itTmp->getStop());
|
||||
it.setTocken(estyle::lexer::ID);
|
||||
// This work because I use etk::Vector ...
|
||||
m_list.erase(itTmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (it != m_list.begin() {
|
||||
auto itTmp = it;
|
||||
--itTmp;
|
||||
if (itTmp->getTocken() == estyle::lexer::ID) {
|
||||
itTmp.setStop(itTmp->getStop());
|
||||
it = m_list.erase(it);
|
||||
ESTYLE_WARNING("collapse '" << m_stream.extract(itTmp.getStart(), itTmp.getStop()) << "'");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
ESTYLE_WARNING("collapse '" << m_stream.extract(it->getStart(), it->getStop()) << "'");
|
||||
}
|
||||
++it;
|
||||
}
|
||||
}
|
@ -24,20 +24,33 @@ namespace estyle {
|
||||
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;
|
||||
}
|
||||
};
|
||||
class Lexer {
|
||||
private:
|
||||
etk::String m_stream;
|
||||
etk::Vector<estyle::LexerElement> m_list;
|
||||
public:
|
||||
Lexer(const etk::String& _input);
|
||||
|
||||
Lexer();
|
||||
void lexify(const etk::String& _input);
|
||||
public:
|
||||
// squash element name space like "::lklkmlk" and "lmkmlk::lmkmlk::mlklk" in 1 element
|
||||
void postAnnalyse_namespace();
|
||||
public:
|
||||
size_t size() const {
|
||||
return m_list.size();
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ etk::String estyle::lexer::toString(estyle::lexer::tocken _token) {
|
||||
case estyle::lexer::OR_OR: return "||";
|
||||
case estyle::lexer::XOR: return "^";
|
||||
case estyle::lexer::XOR_EQUAL: return "^=";
|
||||
case estyle::lexer::NAMESPACE: return "::";
|
||||
case estyle::lexer::COLON: return ":";
|
||||
case estyle::lexer::SEMICOLON: return ";";
|
||||
case estyle::lexer::PARENTHESE_IN: return "(";
|
||||
@ -94,6 +95,15 @@ etk::String estyle::lexer::toString(estyle::lexer::tocken _token) {
|
||||
case estyle::lexer::RESERVED_NAMESPACE: return "namespace";
|
||||
case estyle::lexer::RESERVED_CLASS: return "class";
|
||||
case estyle::lexer::RESERVED_STRUCT: return "struct";
|
||||
case estyle::lexer::RESERVED_THROW: return "throw";
|
||||
case estyle::lexer::RESERVED_TRY: return "try";
|
||||
case estyle::lexer::RESERVED_CATCH: return "catch";
|
||||
case estyle::lexer::RESERVED_SHARP_IF: return "#if";
|
||||
case estyle::lexer::RESERVED_SHARP_ELSE_IF: return "#elif";
|
||||
case estyle::lexer::RESERVED_SHARP_IF_DEFINE: return "#ifdef";
|
||||
case estyle::lexer::RESERVED_SHARP_IF_NOT_DEFINE: return "#ifndef";
|
||||
case estyle::lexer::RESERVED_SHARP_END_IF: return "#endif";
|
||||
case estyle::lexer::RESERVED_SHARP_ELSE: return "#else";
|
||||
|
||||
case estyle::lexer::BASIC_TYPE_INTEGER_008: return "int8_t";
|
||||
case estyle::lexer::BASIC_TYPE_INTEGER_008_UNSIGNED: return "uint8_t";
|
||||
|
@ -43,6 +43,7 @@ namespace estyle {
|
||||
XOR, //!< element "^"
|
||||
XOR_EQUAL, //!< element "^="
|
||||
COLON, //!< element ":"
|
||||
NAMESPACE, //!< element ":"
|
||||
SEMICOLON, //!< element ";"
|
||||
PARENTHESE_IN, //!< element "("
|
||||
PARENTHESE_OUT, //!< element ")"
|
||||
@ -95,6 +96,15 @@ namespace estyle {
|
||||
RESERVED_NAMESPACE, //!< element "namespace"
|
||||
RESERVED_CLASS, //!< element "class"
|
||||
RESERVED_STRUCT, //!< element "struct"
|
||||
RESERVED_THROW, //!< element "throw"
|
||||
RESERVED_TRY, //!< element "try"
|
||||
RESERVED_CATCH, //!< element "catch"
|
||||
RESERVED_SHARP_IF, //!< element "#if"
|
||||
RESERVED_SHARP_ELSE_IF, //!< element "#elif"
|
||||
RESERVED_SHARP_IF_DEFINE, //!< element "#ifdef"
|
||||
RESERVED_SHARP_IF_NOT_DEFINE, //!< element "#ifndef"
|
||||
RESERVED_SHARP_END_IF, //!< element "#endif"
|
||||
RESERVED_SHARP_ELSE, //!< element "#else"
|
||||
RESERVED_NEW_LINE, //!< Neew line
|
||||
RESERVED_LIST_END,
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user