20#ifndef LIBREPCB_CORE_SEXPRESSION_H
21#define LIBREPCB_CORE_SEXPRESSION_H
26#include "../fileio/filepath.h"
49std::unique_ptr<SExpression>
serialize(
const T& obj);
105 QList<SExpression*>
getChildren(
const QString& name)
noexcept;
106 QList<const SExpression*>
getChildren(
const QString& name)
const noexcept;
163 void setName(
const QString& name);
164 void setValue(
const QString& value);
169 void appendChild(std::unique_ptr<SExpression> child);
170 template <
typename T>
175 void appendChild(
const QString& child, std::unique_ptr<SExpression> obj) {
179 template <
typename T>
193 return !(*
this == rhs);
199 static std::unique_ptr<SExpression>
createList(
const QString& name);
200 static std::unique_ptr<SExpression>
createToken(
const QString& token);
201 static std::unique_ptr<SExpression>
createString(
const QString&
string);
203 static std::unique_ptr<SExpression>
parse(
const QByteArray& content,
213 int& index) noexcept;
221 static QString
parseToken(const QString& content,
int& index,
223 static QString
parseString(const QString& content,
int& index,
226 bool skipNewline = false);
227 static QString
escapeString(const QString&
string) noexcept;
This class represents absolute, well-formatted paths to files or directories.
Definition filepath.h:127
The SExpression class.
Definition sexpression.h:69
void appendChild(const QString &child, std::unique_ptr< SExpression > obj)
Definition sexpression.h:175
SExpression * tryGetChild(const QString &path) noexcept
Try get a child by path.
Definition sexpression.cpp:149
void removeChild(const SExpression &child)
Definition sexpression.cpp:226
void removeChildrenWithNodeRecursive(const SExpression &search) noexcept
Definition sexpression.cpp:236
Type
Definition sexpression.h:78
@ String
values with double quotes (e.g. "Foo!")
@ Token
values without quotes (e.g. -12.34)
@ List
has a tag name and an arbitrary number of children
@ LineBreak
manual line break inside a List
QString toString(int indent, Mode mode) const
Definition sexpression.cpp:354
SExpression & appendChild(const QString &child, const T &obj)
Definition sexpression.h:180
static void skipWhitespaceAndComments(const QString &content, int &index, bool skipNewline=false)
Definition sexpression.cpp:584
static bool skipLineBreaks(const std::vector< std::unique_ptr< SExpression > > &children, int &index) noexcept
Definition sexpression.cpp:452
SExpression & appendList(const QString &name)
Definition sexpression.cpp:212
static std::unique_ptr< SExpression > parse(const QByteArray &content, const FilePath &filePath, Mode mode=Mode::LibrePCB)
Definition sexpression.cpp:416
QList< SExpression * > getChildren(Type type) noexcept
Definition sexpression.cpp:94
const QString & getName() const
Definition sexpression.cpp:62
bool containsChild(const SExpression &child) const noexcept
Definition sexpression.cpp:79
static QString escapeString(const QString &string) noexcept
Definition sexpression.cpp:311
static std::unique_ptr< SExpression > createString(const QString &string)
Definition sexpression.cpp:407
Mode
Definition sexpression.h:74
@ LibrePCB
LibrePCB syntax (very strict)
@ Permissive
Compatibility with other tools (very permissive)
bool operator!=(const SExpression &rhs) const noexcept
Definition sexpression.h:192
static std::unique_ptr< SExpression > parseList(const QString &content, int &index, const FilePath &filePath, Mode mode)
Definition sexpression.cpp:484
QByteArray toByteArray(Mode mode=Mode::LibrePCB) const
Definition sexpression.cpp:259
FilePath mFilePath
Definition sexpression.h:237
bool isList() const noexcept
Definition sexpression.h:93
bool isMultiLine() const noexcept
Definition sexpression.cpp:439
std::vector< std::unique_ptr< SExpression > > mChildren
Definition sexpression.h:236
Type getType() const noexcept
Definition sexpression.h:92
bool isString() const noexcept
Definition sexpression.h:95
const FilePath & getFilePath() const noexcept
Definition sexpression.h:91
const QString & getValue() const
Definition sexpression.cpp:71
SExpression() noexcept
Definition sexpression.cpp:41
void ensureLineBreak()
Definition sexpression.cpp:206
QString mValue
either a list name, a token or a string
Definition sexpression.h:234
static std::unique_ptr< SExpression > createToken(const QString &token)
Definition sexpression.cpp:403
SExpression & getChild(int index)
Definition sexpression.cpp:86
static QString parseToken(const QString &content, int &index, const FilePath &filePath, Mode mode)
Definition sexpression.cpp:512
friend uint qHash(const SExpression &node, uint seed) noexcept
Definition sexpression.cpp:794
void setName(const QString &name)
Definition sexpression.cpp:186
static std::unique_ptr< SExpression > createList(const QString &name)
Definition sexpression.cpp:399
SExpression & appendChild(const T &obj)
Definition sexpression.h:171
bool isLineBreak() const noexcept
Definition sexpression.h:96
void setValue(const QString &value)
Definition sexpression.cpp:194
bool operator<(const SExpression &rhs) const noexcept
Definition sexpression.cpp:282
bool operator==(const SExpression &rhs) const noexcept
Definition sexpression.cpp:271
SExpression & operator=(const SExpression &rhs) noexcept
Definition sexpression.cpp:296
std::size_t getChildCount() const noexcept
Definition sexpression.h:99
static QString parseString(const QString &content, int &index, const FilePath &filePath)
Definition sexpression.cpp:530
static std::unique_ptr< SExpression > createLineBreak()
Definition sexpression.cpp:411
static bool isValidToken(const QString &token, Mode mode) noexcept
Definition sexpression.cpp:334
bool isToken() const noexcept
Definition sexpression.h:94
void appendChild(std::unique_ptr< SExpression > child)
Definition sexpression.cpp:217
Type mType
Definition sexpression.h:233
void replaceRecursive(const SExpression &search, const SExpression &replace) noexcept
Definition sexpression.cpp:248
static bool isValidTokenChar(const QChar &c, Mode mode) noexcept
Definition sexpression.cpp:346
Definition occmodel.cpp:76
std::unique_ptr< SExpression > serialize(const AttributeKey &obj)
Definition attributekey.h:99
AttributeKey deserialize(const SExpression &node)
Definition attributekey.h:104