Working on generating string literals for inclusion in generated code.
This commit is contained in:
parent
0c3bb27e58
commit
092ed67d5e
8 changed files with 218 additions and 3 deletions
|
|
@ -65,6 +65,7 @@ for (auto row: result) {
|
|||
return t;
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<LanguageConfig> buildPglabCppLanguageConfig()
|
||||
{
|
||||
auto config = std::make_shared<LanguageConfig>();
|
||||
|
|
|
|||
8
pglablib/codebuilder/StringEscapeRule.cpp
Normal file
8
pglablib/codebuilder/StringEscapeRule.cpp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#include "StringEscapeRule.h"
|
||||
|
||||
/**
|
||||
*/
|
||||
QString convert(QStringRef in, ConvertToNumericEscape conversion, NumericEscapeFormat format, QString prefix)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
47
pglablib/codebuilder/StringEscapeRule.h
Normal file
47
pglablib/codebuilder/StringEscapeRule.h
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
#ifndef STRINGESCAPERULE_H
|
||||
#define STRINGESCAPERULE_H
|
||||
|
||||
#include <QString>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
enum class ConvertToNumericEscape {
|
||||
Utf8, ///< Generates upto four escapes for 4 utf8 chars
|
||||
Utf16, ///< Generates upto four escapes for 2 utf16 chars
|
||||
Utf32, ///< Generates a single escape for the unicode codepoint
|
||||
};
|
||||
|
||||
|
||||
enum class NumericEscapeFormat {
|
||||
Decimal,
|
||||
HexUpper,
|
||||
HexLower
|
||||
};
|
||||
|
||||
class CharToNumericConversion {
|
||||
public:
|
||||
ConvertToNumericEscape m_toNumericEscape;
|
||||
NumericEscapeFormat m_numericEscapeFormat;
|
||||
int m_minNumericDigits, m_maxNumericDigits;
|
||||
};
|
||||
|
||||
/** The basic method of applying a StringEscapeRule is to find all matches
|
||||
* in the string for the m_matchRegex.
|
||||
*
|
||||
* if m_numericConversion is set then the match is taken out of the string and replaced
|
||||
* with one or more numerical escapes.
|
||||
* if no conversion is needed the match is simple prefixed with m_prefixWidth
|
||||
*/
|
||||
class StringEscapeRule {
|
||||
public:
|
||||
/** Regular expression that finds characters in the string that need replacing.
|
||||
* Each character to replace should always generate one match.
|
||||
*/
|
||||
QString m_matchRegex;
|
||||
/** As often a simple escape character like \ or a doubling scheme is used this
|
||||
* field often provides enough flexibility.
|
||||
*/
|
||||
QString m_prefixWith;
|
||||
// boost::optional<CharToNumericConversion> m_numericConversion;
|
||||
};
|
||||
|
||||
#endif // STRINGESCAPERULE_H
|
||||
10
pglablib/codebuilder/StringLiteralRules.cpp
Normal file
10
pglablib/codebuilder/StringLiteralRules.cpp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#include "StringLiteralRules.h"
|
||||
#include <QTextStream>
|
||||
|
||||
void StringLiteralRules::OutputString(QTextStream &stream, QString string_literal)
|
||||
{
|
||||
stream << m_stringStart;
|
||||
|
||||
|
||||
stream << m_stringEnd;
|
||||
}
|
||||
37
pglablib/codebuilder/StringLiteralRules.h
Normal file
37
pglablib/codebuilder/StringLiteralRules.h
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#ifndef STRINGLITERALRULES_H
|
||||
#define STRINGLITERALRULES_H
|
||||
|
||||
#include "StringEscapeRule.h"
|
||||
#include <vector>
|
||||
|
||||
class QTextStream;
|
||||
|
||||
class StringLiteralRules {
|
||||
public:
|
||||
/** What should be put in front of the string to make it a string literal
|
||||
*
|
||||
* For instance a plain char string in C this would just be a double quote "
|
||||
* But for a C++11 utf8 string literal it would be u8"
|
||||
*/
|
||||
QString m_stringStart;
|
||||
/** Similar to stringStart
|
||||
*/
|
||||
QString m_stringEnd;
|
||||
|
||||
/** If true the assumption is that the newlines
|
||||
* in the source string are not escaped so no line breaking is done.
|
||||
* However we should still get a multiline string if the source was.
|
||||
*
|
||||
* When false the assumption is that we can split the string using stringEnd,
|
||||
* stringStart and the concatOperator. There is a preference to split on whitespace.
|
||||
*/
|
||||
bool m_supportsMultiLine;
|
||||
QString m_concatOperator;
|
||||
|
||||
std::vector<StringEscapeRule> m_escapeRules;
|
||||
|
||||
void OutputString(QTextStream &stream, QString string_literal);
|
||||
};
|
||||
|
||||
|
||||
#endif // STRINGLITERALRULES_H
|
||||
|
|
@ -61,7 +61,9 @@ codebuilder/DefaultConfigs.cpp \
|
|||
codebuilder/TypeMappings.cpp \
|
||||
codebuilder/IndentationConfig.cpp \
|
||||
codebuilder/StructureTemplate.cpp \
|
||||
FormatToStream.cpp
|
||||
FormatToStream.cpp \
|
||||
codebuilder/StringLiteralRules.cpp \
|
||||
codebuilder/StringEscapeRule.cpp
|
||||
|
||||
HEADERS += \
|
||||
Pglablib.h \
|
||||
|
|
@ -105,7 +107,9 @@ codebuilder/TypeMappings.h \
|
|||
codebuilder/IndentationConfig.h \
|
||||
codebuilder/StructureTemplate.h \
|
||||
FormatToStream.h \
|
||||
codebuilder/ResultLoopTemplate.h
|
||||
codebuilder/ResultLoopTemplate.h \
|
||||
codebuilder/StringEscapeRule.h \
|
||||
codebuilder/StringLiteralRules.h
|
||||
|
||||
unix {
|
||||
target.path = /usr/lib
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue