131 lines
2.7 KiB
C++
131 lines
2.7 KiB
C++
/**
|
|
* @author Edouard DUPIN
|
|
* @copyright 2017, Edouard DUPIN, all right reserved
|
|
* @license MPL-2 (see license file)
|
|
*/
|
|
#include <estyle/Generator.hpp>
|
|
#include <estyle/debug.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
estyle::Generator::Generator():
|
|
propertyEndOfLine(this, "end-of-line", true, "true: End with \\n, false \\r\\n"),
|
|
propertyDoxygenOneLine(this, "doxygen-1-line-type", true, "true: single line doxygen comment is done with '//!', false '///'"),
|
|
propertyDoxygenMultipleLine(this, "doxygen-N-line-type", 0, "0: /** */ ...") {
|
|
/*
|
|
/ **
|
|
*
|
|
* /
|
|
*/
|
|
propertyDoxygenMultipleLine.add(0, "normal");
|
|
/*
|
|
/ *!
|
|
*
|
|
* /
|
|
*/
|
|
propertyDoxygenMultipleLine.add(1, "normal-exclamation");
|
|
/*
|
|
/ **
|
|
|
|
* /
|
|
*/
|
|
propertyDoxygenMultipleLine.add(2, "no-star");
|
|
/*
|
|
/ *!
|
|
|
|
* /
|
|
*/
|
|
propertyDoxygenMultipleLine.add(3, "no-star-exclamation");
|
|
/*
|
|
///
|
|
///
|
|
///
|
|
*/
|
|
propertyDoxygenMultipleLine.add(4, "single-line");
|
|
/*
|
|
//!
|
|
//!
|
|
//!
|
|
*/
|
|
propertyDoxygenMultipleLine.add(5, "single-line-exclamation");
|
|
}
|
|
|
|
estyle::Generator::~Generator() {
|
|
|
|
}
|
|
|
|
etk::String estyle::Generator::getEndOfLine() {
|
|
if (propertyEndOfLine.get() == true) {
|
|
return "\n";
|
|
}
|
|
return "\r\n";
|
|
}
|
|
|
|
etk::String estyle::Generator::getDoxygenOneLine(int32_t _indentation) {
|
|
if (propertyDoxygenOneLine.get() == true) {
|
|
return "//!";
|
|
}
|
|
return "///";
|
|
}
|
|
etk::String estyle::Generator::getDoxygenNLine(int32_t _indentation, const etk::String& _data) {
|
|
if (propertyDoxygenMultipleLine.get() == 0) {
|
|
|
|
|
|
}
|
|
etk::String out;
|
|
out += "/**";
|
|
out += _data;
|
|
out += "*/";
|
|
return out;
|
|
}
|
|
|
|
|
|
etk::String estyle::Generator::process(const etk::String& _code) {
|
|
estyle::Lexer lexer(_code);
|
|
etk::String out;
|
|
int32_t indentation = 0;
|
|
for (size_t iii = 0; iii < lexer.size(); ++iii) {
|
|
enum estyle::lexer::tocken elem = lexer.getTocken(iii);
|
|
if (elem == estyle::lexer::RESERVED_COMMENT_1_LINE) {
|
|
out += "//";
|
|
out += lexer.getData(iii);
|
|
out += getEndOfLine();
|
|
continue;
|
|
}
|
|
if (elem == estyle::lexer::RESERVED_DOCUMENTATION_1_LINE) {
|
|
out += getDoxygenOneLine(indentation);
|
|
out += lexer.getData(iii);
|
|
out += getEndOfLine();
|
|
continue;
|
|
}
|
|
if (elem == estyle::lexer::RESERVED_COMMENT_N_LINE) {
|
|
out += "/*";
|
|
out += lexer.getData(iii);
|
|
out += "*/";
|
|
if (iii+1 < lexer.size()) {
|
|
if (lexer.getTocken(iii+1) == estyle::lexer::RESERVED_NEW_LINE) {
|
|
out += getEndOfLine();
|
|
++iii;
|
|
}
|
|
}
|
|
continue;
|
|
}
|
|
if (elem == estyle::lexer::RESERVED_DOCUMENTATION_1_LINE) {
|
|
out += getDoxygenNLine(indentation, lexer.getData(iii));
|
|
out += 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();
|
|
++iii;
|
|
}
|
|
}
|
|
continue;
|
|
}
|
|
|
|
}
|
|
|
|
return out;
|
|
}; |