[DEV] continue build

This commit is contained in:
Edouard DUPIN 2017-12-11 22:00:24 +01:00
parent 2e7feacb3d
commit 7d3c72a405
6 changed files with 262 additions and 127 deletions

View File

@ -85,33 +85,33 @@ etk::String estyle::Generator::getDoxygenNLine(const etk::String& _data) {
void estyle::Generator::addSpace(etk::String& _data) { void estyle::Generator::addSpace() {
if (_data.size() == 0) { if (m_output.size() == 0) {
return; return;
} }
if (_data.back() == '\0') { if (m_output.back() == '\0') {
ESTYLE_TODO("TODO : Do indentation... : '" << _data << "'"); ESTYLE_TODO("TODO : Do indentation... : '" << m_output << "'");
} }
if (_data.back() == '\n') { if (m_output.back() == '\n') {
if (propertyIndentWithTabulation.get() == true) { if (propertyIndentWithTabulation.get() == true) {
for (int32_t iii=0; iii<m_indentation; ++iii) { for (int32_t iii=0; iii<m_indentation; ++iii) {
_data += "\t"; m_output += "\t";
} }
} else { } else {
for (int32_t iii=0; iii<m_indentation; ++iii) { for (int32_t iii=0; iii<m_indentation; ++iii) {
for (int32_t jjj=0; jjj<propertyIndentSize.get(); ++jjj) { for (int32_t jjj=0; jjj<propertyIndentSize.get(); ++jjj) {
_data += " "; m_output += " ";
} }
} }
} }
ESTYLE_TODO("TODO : Do indentation..."); ESTYLE_TODO("TODO : Do indentation...");
return; return;
} }
if ( _data.back() == ' ' if ( m_output.back() == ' '
|| _data.back() == '\t') { || m_output.back() == '\t') {
return; return;
} }
_data += " "; m_output += " ";
} }
enum class stack { enum class stack {
@ -130,161 +130,167 @@ enum class stack {
etk::Vector<enum stack> m_urrentStack; etk::Vector<enum stack> m_urrentStack;
etk::String estyle::Generator::process(const etk::String& _code) { etk::String estyle::Generator::process(const etk::String& _code) {
estyle::Lexer lexer(_code); m_lexer.lexify(_code);
etk::String out; process(0, estyle::lexer::END_OF_FILE) {
for (size_t iii = 0; iii < lexer.size(); ++iii) { return m_output;
enum estyle::lexer::tocken elem = lexer.getTocken(iii); };
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) { if (elem == estyle::lexer::RESERVED_COMMENT_1_LINE) {
out += "//"; m_output += "//";
out += lexer.getData(iii); m_output += m_lexer.getData(iii);
out += getEndOfLine(); m_output += getEndOfLine();
continue; continue;
} }
if (elem == estyle::lexer::RESERVED_DOCUMENTATION_1_LINE) { if (elem == estyle::lexer::RESERVED_DOCUMENTATION_1_LINE) {
out += getDoxygenOneLine(); m_output += getDoxygenOneLine();
out += lexer.getData(iii); m_output += m_lexer.getData(iii);
out += getEndOfLine(); m_output += getEndOfLine();
continue; continue;
} }
if (elem == estyle::lexer::RESERVED_COMMENT_N_LINE) { if (elem == estyle::lexer::RESERVED_COMMENT_N_LINE) {
addSpace(out); addSpace();
out += "/*"; m_output += "/*";
out += lexer.getData(iii); m_output += m_lexer.getData(iii);
out += "*/"; m_output += "*/";
if (iii+1 < lexer.size()) { if (iii+1 < m_lexer.size()) {
if (lexer.getTocken(iii+1) == estyle::lexer::RESERVED_NEW_LINE) { if (m_lexer.getTocken(iii+1) == estyle::lexer::RESERVED_NEW_LINE) {
out += getEndOfLine(); m_output += getEndOfLine();
++iii; ++iii;
} }
} }
continue; continue;
} }
if (elem == estyle::lexer::RESERVED_DOCUMENTATION_1_LINE) { if (elem == estyle::lexer::RESERVED_DOCUMENTATION_1_LINE) {
addSpace(out); addSpace();
out += getDoxygenNLine(lexer.getData(iii)); m_output += getDoxygenNLine(m_lexer.getData(iii));
out += getEndOfLine(); m_output += getEndOfLine();
// TODO : Some mode can create error like /** */ becaming /// ... // TODO : Some mode can create error like /** */ becaming /// ...
if (iii+1 < lexer.size()) { if (iii+1 < m_lexer.size()) {
if (lexer.getTocken(iii+1) == estyle::lexer::RESERVED_NEW_LINE) { if (m_lexer.getTocken(iii+1) == estyle::lexer::RESERVED_NEW_LINE) {
out += getEndOfLine(); m_output += getEndOfLine();
++iii; ++iii;
} }
} }
continue; continue;
} }
if (elem == estyle::lexer::BASIC_TYPE_INTEGER_SIZE_T) { if (elem == estyle::lexer::BASIC_TYPE_INTEGER_SIZE_T) {
addSpace(out); addSpace();
out += "size_t"; m_output += "size_t";
continue; continue;
} }
if (elem == estyle::lexer::BASIC_TYPE_INTEGER_008) { if (elem == estyle::lexer::BASIC_TYPE_INTEGER_008) {
addSpace(out); addSpace();
out += "int8_t"; m_output += "int8_t";
continue; continue;
} }
if (elem == estyle::lexer::BASIC_TYPE_INTEGER_008_UNSIGNED) { if (elem == estyle::lexer::BASIC_TYPE_INTEGER_008_UNSIGNED) {
addSpace(out); addSpace();
out += "uint8_t"; m_output += "uint8_t";
continue; continue;
} }
if (elem == estyle::lexer::BASIC_TYPE_INTEGER_016) { if (elem == estyle::lexer::BASIC_TYPE_INTEGER_016) {
addSpace(out); addSpace();
out += "int16_t"; m_output += "int16_t";
continue; continue;
} }
if (elem == estyle::lexer::BASIC_TYPE_INTEGER_016_UNSIGNED) { if (elem == estyle::lexer::BASIC_TYPE_INTEGER_016_UNSIGNED) {
addSpace(out); addSpace();
out += "uint16_t"; m_output += "uint16_t";
continue; continue;
} }
if (elem == estyle::lexer::BASIC_TYPE_INTEGER_032) { if (elem == estyle::lexer::BASIC_TYPE_INTEGER_032) {
addSpace(out); addSpace();
out += "int32_t"; m_output += "int32_t";
continue; continue;
} }
if (elem == estyle::lexer::BASIC_TYPE_INTEGER_032_UNSIGNED) { if (elem == estyle::lexer::BASIC_TYPE_INTEGER_032_UNSIGNED) {
addSpace(out); addSpace();
out += "uint32_t"; m_output += "uint32_t";
continue; continue;
} }
if (elem == estyle::lexer::BASIC_TYPE_INTEGER_064) { if (elem == estyle::lexer::BASIC_TYPE_INTEGER_064) {
addSpace(out); addSpace();
out += "int64_t"; m_output += "int64_t";
continue; continue;
} }
if (elem == estyle::lexer::BASIC_TYPE_INTEGER_064_UNSIGNED) { if (elem == estyle::lexer::BASIC_TYPE_INTEGER_064_UNSIGNED) {
addSpace(out); addSpace();
out += "uint64_t"; m_output += "uint64_t";
continue; continue;
} }
if (elem == estyle::lexer::BASIC_TYPE_INTEGER_128) { if (elem == estyle::lexer::BASIC_TYPE_INTEGER_128) {
addSpace(out); addSpace();
out += "int128_t"; m_output += "int128_t";
continue; continue;
} }
if (elem == estyle::lexer::BASIC_TYPE_INTEGER_128_UNSIGNED) { if (elem == estyle::lexer::BASIC_TYPE_INTEGER_128_UNSIGNED) {
addSpace(out); addSpace();
out += "uint128_t"; m_output += "uint128_t";
continue; continue;
} }
if (elem == estyle::lexer::BASIC_TYPE_FLOAT_32) { if (elem == estyle::lexer::BASIC_TYPE_FLOAT_32) {
addSpace(out); addSpace();
out += "float"; m_output += "float";
continue; continue;
} }
if (elem == estyle::lexer::BASIC_TYPE_FLOAT_64) { if (elem == estyle::lexer::BASIC_TYPE_FLOAT_64) {
addSpace(out); addSpace();
out += "double"; m_output += "double";
continue; continue;
} }
if (elem == estyle::lexer::BASIC_TYPE_FLOAT_96) { if (elem == estyle::lexer::BASIC_TYPE_FLOAT_96) {
addSpace(out); addSpace();
out += "triple"; m_output += "triple";
continue; continue;
} }
if (elem == estyle::lexer::BASIC_TYPE_BOOLEAN) { if (elem == estyle::lexer::BASIC_TYPE_BOOLEAN) {
addSpace(out); addSpace();
out += "bool"; m_output += "bool";
continue; continue;
} }
if (elem == estyle::lexer::BASIC_TYPE_VOID) { if (elem == estyle::lexer::BASIC_TYPE_VOID) {
addSpace(out); addSpace();
out += "void"; m_output += "void";
continue; continue;
} }
if (elem == estyle::lexer::SEMICOLON) { if (elem == estyle::lexer::SEMICOLON) {
out += ";"; m_output += ";";
out += getEndOfLine(); m_output += getEndOfLine();
continue; continue;
} }
if (elem == estyle::lexer::ID) { if (elem == estyle::lexer::ID) {
addSpace(out); addSpace();
out += lexer.getData(iii); m_output += m_lexer.getData(iii);
continue; continue;
} }
if (elem == estyle::lexer::EQUAL) { if (elem == estyle::lexer::EQUAL) {
out += "="; m_output += "=";
continue; continue;
} }
if (elem == estyle::lexer::STRING) { if (elem == estyle::lexer::STRING) {
out += "\""; m_output += "\"";
out += lexer.getData(iii); m_output += m_lexer.getData(iii);
out += "\""; m_output += "\"";
continue; continue;
} }
if (elem == estyle::lexer::SIMPLE_QUOTE_STRING) { if (elem == estyle::lexer::SIMPLE_QUOTE_STRING) {
out += "'"; m_output += "'";
out += lexer.getData(iii); m_output += m_lexer.getData(iii);
out += "'"; m_output += "'";
continue; continue;
} }
if (elem == estyle::lexer::BRACE_IN) { if (elem == estyle::lexer::BRACE_IN) {
m_urrentStack.pushBack(stack::BLOCK); m_urrentStack.pushBack(stack::BLOCK);
out += getEndOfLine(); m_output += getEndOfLine();
//addSpace(out); //addSpace();
out += "{"; m_output += "{";
out += getEndOfLine(); m_output += getEndOfLine();
m_indentation++; m_indentation++;
continue; continue;
} }
@ -298,23 +304,23 @@ etk::String estyle::Generator::process(const etk::String& _code) {
} else { } else {
m_urrentStack.popBack(); m_urrentStack.popBack();
} }
out += getEndOfLine(); m_output += getEndOfLine();
addSpace(out); addSpace();
out += "}"; m_output += "}";
out += getEndOfLine(); m_output += getEndOfLine();
continue; continue;
} }
if (elem == estyle::lexer::RESERVED_IF) { if (elem == estyle::lexer::RESERVED_IF) {
addSpace(out); addSpace();
int32_t spaceOffset = 4; int32_t spaceOffset = 4;
out += "if "; m_output += "if ";
for (size_t jjj=iii+1; jjj<lexer.size(); ++jjj) { for (size_t jjj=iii+1; jjj<m_lexer.size(); ++jjj) {
enum estyle::lexer::tocken elem = lexer.getTocken(jjj); enum estyle::lexer::tocken elem = m_lexer.getTocken(jjj);
if (elem == estyle::lexer::RESERVED_NEW_LINE) { if (elem == estyle::lexer::RESERVED_NEW_LINE) {
// OK ==> normal case ... // OK ==> normal case ...
} else if (elem == estyle::lexer::PARENTHESE_IN) { } else if (elem == estyle::lexer::PARENTHESE_IN) {
// find condition section ... // find condition section ...
iii = generateCondition(lexer, jjj, out, spaceOffset); iii = generateCondition(jjj, m_output, spaceOffset);
break; break;
} else { } else {
ESTYLE_ERROR("Get 'if' without '(' element"); ESTYLE_ERROR("Get 'if' without '(' element");
@ -323,28 +329,27 @@ etk::String estyle::Generator::process(const etk::String& _code) {
continue; continue;
} }
// default other case: // default other case:
addSpace(out); addSpace();
out += lexer.getData(iii); m_output += m_lexer.getData(iii);
} }
return m_lexer.size();
return out; }
};
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 sectionEnd = endOfSection(_pos);
int32_t nbCondition = countCurrentLevelCondition(_lexer, _pos); int32_t nbCondition = countCurrentLevelCondition(_pos);
if (nbCondition == 0) { if (nbCondition == 0) {
for (size_t iii=_pos; iii<=sectionEnd; ++iii) { for (size_t iii=_pos; iii<=sectionEnd; ++iii) {
addSpace(_data); addSpace(_data);
_data += _lexer.getData(iii); _data += m_lexer.getData(iii);
} }
} else { } else {
_data += "( "; _data += "( ";
for (size_t iii=_pos+1; iii<=sectionEnd; ++iii) { 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) { 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 } else if ( elem == estyle::lexer::AND_AND
|| elem == estyle::lexer::OR_OR) { || elem == estyle::lexer::OR_OR) {
_data += getEndOfLine(); _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) { for (int32_t ooo=0; ooo<_offset; ++ooo) {
_data += " "; _data += " ";
} }
_data += " " + _lexer.getData(iii) + " "; _data += " " + m_lexer.getData(iii) + " ";
} else { } else {
addSpace(_data); 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; return sectionEnd;
} }
size_t estyle::Generator::endOfSection(estyle::Lexer& _lexer, size_t _pos) { size_t estyle::Generator::endOfSection(size_t _pos) {
ESTYLE_INFO(" " << _lexer.getTocken(_pos) << " " << _pos << " [BEGIN]"); ESTYLE_INFO(" " << m_lexer.getTocken(_pos) << " " << _pos << " [BEGIN]");
enum estyle::lexer::tocken endTocken = estyle::lexer::END_OF_FILE; 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) { if (elem == estyle::lexer::PARENTHESE_IN) {
endTocken = estyle::lexer::PARENTHESE_OUT; endTocken = estyle::lexer::PARENTHESE_OUT;
} else if (elem == estyle::lexer::BRACKET_IN) { } 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) { } else if (elem == estyle::lexer::BRACE_IN) {
endTocken = estyle::lexer::BRACE_OUT; endTocken = estyle::lexer::BRACE_OUT;
} else { } 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; return _pos;
} }
for (size_t iii=_pos+1; iii < _lexer.size(); ++iii) { for (size_t iii=_pos+1; iii < m_lexer.size(); ++iii) {
elem = _lexer.getTocken(iii); elem = m_lexer.getTocken(iii);
if (elem == endTocken) { if (elem == endTocken) {
return iii; return iii;
} }
if ( elem == estyle::lexer::PARENTHESE_IN if ( elem == estyle::lexer::PARENTHESE_IN
|| elem == estyle::lexer::BRACKET_IN || elem == estyle::lexer::BRACKET_IN
|| elem == estyle::lexer::BRACE_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; int32_t out;
enum estyle::lexer::tocken endTocken = estyle::lexer::END_OF_FILE; 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) { if (elem == estyle::lexer::PARENTHESE_IN) {
endTocken = estyle::lexer::PARENTHESE_OUT; endTocken = estyle::lexer::PARENTHESE_OUT;
} else if (elem == estyle::lexer::BRACKET_IN) { } 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) { } else if (elem == estyle::lexer::BRACE_IN) {
endTocken = estyle::lexer::BRACE_OUT; endTocken = estyle::lexer::BRACE_OUT;
} else { } 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; return _pos;
} }
for (size_t iii=_pos+1; iii < _lexer.size(); ++iii) { for (size_t iii=_pos+1; iii < m_lexer.size(); ++iii) {
elem = _lexer.getTocken(iii); elem = m_lexer.getTocken(iii);
if (elem == endTocken) { if (elem == endTocken) {
return out; return out;
} }
if ( elem == estyle::lexer::PARENTHESE_IN if ( elem == estyle::lexer::PARENTHESE_IN
|| elem == estyle::lexer::BRACKET_IN || elem == estyle::lexer::BRACKET_IN
|| elem == estyle::lexer::BRACE_IN) { || elem == estyle::lexer::BRACE_IN) {
iii = endOfSection(_lexer, iii); iii = endOfSection(iii);
} }
if ( elem == estyle::lexer::AND_AND if ( elem == estyle::lexer::AND_AND
|| elem == estyle::lexer::OR_OR) { || elem == estyle::lexer::OR_OR) {
@ -424,3 +429,35 @@ int32_t estyle::Generator::countCurrentLevelCondition(estyle::Lexer& _lexer, siz
return out; 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;
}

View File

@ -17,23 +17,26 @@ namespace estyle {
public: public:
Generator(); Generator();
~Generator(); ~Generator();
protected: public:
eproperty::Value<bool> propertyEndOfLine; eproperty::Value<bool> propertyEndOfLine;
eproperty::Value<bool> propertyIndentWithTabulation; eproperty::Value<bool> propertyIndentWithTabulation;
eproperty::Value<int8_t> propertyIndentSize; eproperty::Value<int8_t> propertyIndentSize;
eproperty::Value<bool> propertyDoxygenOneLine; eproperty::Value<bool> propertyDoxygenOneLine;
eproperty::List<int32_t> propertyDoxygenMultipleLine; eproperty::List<int32_t> propertyDoxygenMultipleLine;
private:
estyle::Lexer m_lexer;
int32_t m_indentation = 0;
etk::String m_output;
public: public:
etk::String process(const etk::String& _code); etk::String process(const etk::String& _code);
private: private:
void addSpace(etk::String& _data); void addSpace();
etk::String getEndOfLine(); etk::String getEndOfLine();
etk::String getDoxygenOneLine(); etk::String getDoxygenOneLine();
etk::String getDoxygenNLine(const etk::String& _data); etk::String getDoxygenNLine(const etk::String& _data);
int32_t m_indentation = 0; size_t endOfSection(size_t _pos);
size_t endOfSection(estyle::Lexer& _lexer, size_t _pos); int32_t countCurrentLevelCondition(size_t _pos);
int32_t countCurrentLevelCondition(estyle::Lexer& _lexer, size_t _pos); size_t generateCondition(size_t _pos, etk::String& _data, int32_t _offset);
size_t generateCondition(estyle::Lexer& _lexer, size_t _pos, etk::String& _data, int32_t _offset);
}; };
} }

View File

@ -242,6 +242,24 @@ void estyle::Lexer::parse() {
tockenElement = estyle::lexer::BOOLEAN; tockenElement = estyle::lexer::BOOLEAN;
} else if (idData == "false") { } else if (idData == "false") {
tockenElement = estyle::lexer::BOOLEAN; 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)); m_list.pushBack(estyle::LexerElement(tockenElement, tokenStart, iii));
iii--; iii--;
@ -478,7 +496,12 @@ void estyle::Lexer::parse() {
continue; continue;
} }
if (currentChar == ':') { 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; continue;
} }
if (currentChar == ';') { if (currentChar == ';') {
@ -529,8 +552,13 @@ void estyle::Lexer::parse() {
} }
} }
estyle::Lexer::Lexer(const etk::String& _input) : estyle::Lexer::Lexer() {
m_stream(_input) {
}
void estyle::Lexer::lexify(const etk::String& _input) {
m_stream = _input;
ESTYLE_DEBUG("Parse stream"); ESTYLE_DEBUG("Parse stream");
parse(); parse();
ESTYLE_DEBUG("find:"); ESTYLE_DEBUG("find:");
@ -586,3 +614,37 @@ etk::String estyle::Lexer::getFileLine(int32_t _position) const {
ESTYLE_WARNING("extract " << positionStart << " " << positionStop); ESTYLE_WARNING("extract " << positionStart << " " << positionStop);
return m_stream.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;
}
}

View File

@ -24,20 +24,33 @@ namespace estyle {
enum estyle::lexer::tocken getTocken() const { enum estyle::lexer::tocken getTocken() const {
return m_tocken; return m_tocken;
} }
void setTocken(enum estyle::lexer::tocken _tocken) {
m_tocken = _tocken;
}
int32_t getStart() const { int32_t getStart() const {
return m_start; return m_start;
} }
void setStart(int32_t _pos) {
m_start = _pos;
}
int32_t getStop() const { int32_t getStop() const {
return m_stop; return m_stop;
} }
void setStop(int32_t _pos) {
m_stop = _pos;
}
}; };
class Lexer { class Lexer {
private: private:
etk::String m_stream; etk::String m_stream;
etk::Vector<estyle::LexerElement> m_list; etk::Vector<estyle::LexerElement> m_list;
public: 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 { size_t size() const {
return m_list.size(); return m_list.size();
} }

View File

@ -42,6 +42,7 @@ etk::String estyle::lexer::toString(estyle::lexer::tocken _token) {
case estyle::lexer::OR_OR: return "||"; case estyle::lexer::OR_OR: return "||";
case estyle::lexer::XOR: return "^"; case estyle::lexer::XOR: return "^";
case estyle::lexer::XOR_EQUAL: return "^="; case estyle::lexer::XOR_EQUAL: return "^=";
case estyle::lexer::NAMESPACE: return "::";
case estyle::lexer::COLON: return ":"; case estyle::lexer::COLON: return ":";
case estyle::lexer::SEMICOLON: return ";"; case estyle::lexer::SEMICOLON: return ";";
case estyle::lexer::PARENTHESE_IN: 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_NAMESPACE: return "namespace";
case estyle::lexer::RESERVED_CLASS: return "class"; case estyle::lexer::RESERVED_CLASS: return "class";
case estyle::lexer::RESERVED_STRUCT: return "struct"; 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: return "int8_t";
case estyle::lexer::BASIC_TYPE_INTEGER_008_UNSIGNED: return "uint8_t"; case estyle::lexer::BASIC_TYPE_INTEGER_008_UNSIGNED: return "uint8_t";

View File

@ -43,6 +43,7 @@ namespace estyle {
XOR, //!< element "^" XOR, //!< element "^"
XOR_EQUAL, //!< element "^=" XOR_EQUAL, //!< element "^="
COLON, //!< element ":" COLON, //!< element ":"
NAMESPACE, //!< element ":"
SEMICOLON, //!< element ";" SEMICOLON, //!< element ";"
PARENTHESE_IN, //!< element "(" PARENTHESE_IN, //!< element "("
PARENTHESE_OUT, //!< element ")" PARENTHESE_OUT, //!< element ")"
@ -95,6 +96,15 @@ namespace estyle {
RESERVED_NAMESPACE, //!< element "namespace" RESERVED_NAMESPACE, //!< element "namespace"
RESERVED_CLASS, //!< element "class" RESERVED_CLASS, //!< element "class"
RESERVED_STRUCT, //!< element "struct" 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_NEW_LINE, //!< Neew line
RESERVED_LIST_END, RESERVED_LIST_END,