Skip to content

Commit

Permalink
init: rework string handling and add writing capability with formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
Trico-Everfire committed May 5, 2024
1 parent 2e0f2c7 commit 48bee80
Show file tree
Hide file tree
Showing 8 changed files with 20,872 additions and 90 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ cmake-build-*/

# Generated
test/Helpers.h
test/res/test_results/test.fgd
15 changes: 11 additions & 4 deletions include/fgdpp/fgdpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
#include <string_view>
#include <vector>

#include "sourcepp/detail/StringUtils.h"
#include "structs/entityproperties.h"

namespace fgdpp {


class FGD {
std::string rawFGDFile;

Expand All @@ -34,7 +36,7 @@ class FGD {
struct Token {
TokenType type;
Range range;
std::string_view string;
sourcepp::detail::UtilStringView string;
int line;
ParseError associatedError;
};
Expand All @@ -43,20 +45,25 @@ class FGD {

public:
FGD(std::string_view path, bool parseIncludes);
FGD() = default;

private:
bool TokenizeFile();

//PARSER.
//PARSER.
bool ParseFile();
public:
FGDFile FGDFileContents;
ParsingError parseError{ParseError::NO_ERROR, 0, {0, 0}};

bool ParseFile();

#ifdef FGDPP_UNIFIED_FGD
bool TagListDelimiter(std::vector<Token>::const_iterator& iter, TagList& tagList);
#endif

//WRITE

[[nodiscard]] sourcepp::detail::UtilStringView Write() const;

};

} // namespace fgdpp
53 changes: 27 additions & 26 deletions include/fgdpp/structs/entityproperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace fgdpp {
enum class ParseError {
NO_ERROR = 0,
TOKENIZATION_ERROR,
// PARSING_ERROR,
INVALID_DEFINITION,
INVALID_EQUALS,
INVALID_OPEN_BRACE,
Expand Down Expand Up @@ -39,16 +40,16 @@ struct ParsingError {

#ifdef FGDPP_UNIFIED_FGD
struct TagList {
std::vector<std::string_view> tags;
std::vector<sourcepp::detail::UtilStringView> tags;
};
#endif

struct ClassProperty {
std::vector<std::string_view> properties;
std::vector<sourcepp::detail::UtilStringView> properties;
};

struct ClassProperties {
std::string_view name;
sourcepp::detail::UtilStringView name;
std::vector<ClassProperty> classProperties;
};

Expand All @@ -66,8 +67,8 @@ enum class EntityIOPropertyType {
};

struct Choice {
std::string_view value;
std::string_view displayName;
sourcepp::detail::UtilStringView value;
sourcepp::detail::UtilStringView displayName;
#ifdef FGDPP_UNIFIED_FGD
TagList tagList;
#endif
Expand All @@ -76,29 +77,29 @@ struct Choice {
struct Flag {
int value;
bool checked;
std::string_view displayName;
sourcepp::detail::UtilStringView displayName;
#ifdef FGDPP_UNIFIED_FGD
TagList tagList;
#endif
};

struct EntityProperties {
std::string_view propertyName;
std::string_view type;
std::string_view displayName; // The following 3 are optional and may be empty as a result.
std::string_view defaultValue;
std::vector<std::string_view> propertyDescription;
sourcepp::detail::UtilStringView propertyName;
sourcepp::detail::UtilStringView type;
sourcepp::detail::UtilStringView displayName; // The following 3 are optional and may be empty as a result.
sourcepp::detail::UtilStringView defaultValue;
std::vector<sourcepp::detail::UtilStringView> propertyDescription;
bool readOnly;
bool reportable;

#ifdef FGDPP_UNIFIED_FGD
TagList tagList;
#endif

int choiceCount; // This is a special case if the EntityPropertyType is t_choices
// This is a special case if the EntityPropertyType is t_choices
std::vector<Choice> choices;

int flagCount; // This is a special case if the EntityPropertyType is t_flags
// This is a special case if the EntityPropertyType is t_flags
std::vector<Flag> flags;
};

Expand All @@ -108,10 +109,10 @@ enum class IO {
};

struct InputOutput {
std::string_view name;
std::vector<std::string_view> description;
sourcepp::detail::UtilStringView name;
std::vector<sourcepp::detail::UtilStringView> description;
IO putType;
std::string_view stringType;
sourcepp::detail::UtilStringView stringType;
EntityIOPropertyType type;
#ifdef FGDPP_UNIFIED_FGD
TagList tagList;
Expand All @@ -120,17 +121,17 @@ struct InputOutput {

#ifdef FGDPP_UNIFIED_FGD
struct EntityResource {
std::string_view key;
std::string_view value;
sourcepp::detail::UtilStringView key;
sourcepp::detail::UtilStringView value;
TagList tagList;
};
#endif

struct Entity {
std::string_view type;
sourcepp::detail::UtilStringView type;
std::vector<ClassProperties> classProperties;
std::string_view entityName;
std::vector<std::string_view> entityDescription;
sourcepp::detail::UtilStringView entityName;
std::vector<sourcepp::detail::UtilStringView> entityDescription;
std::vector<EntityProperties> entityProperties;
std::vector<InputOutput> inputOutput;
#ifdef FGDPP_UNIFIED_FGD
Expand All @@ -139,20 +140,20 @@ struct Entity {
};

struct AutoVisGroupChild {
std::string_view name;
std::vector<std::string_view> children;
sourcepp::detail::UtilStringView name;
std::vector<sourcepp::detail::UtilStringView> children;
};

struct AutoVisGroup {
std::string_view name;
sourcepp::detail::UtilStringView name;
struct std::vector<AutoVisGroupChild> children;
};

struct FGDFile {
Range mapSize{0,0};
std::vector<Entity> entities;
std::vector<std::string_view> materialExclusions;
std::vector<std::string_view> includes;
std::vector<sourcepp::detail::UtilStringView> materialExclusions;
std::vector<sourcepp::detail::UtilStringView> includes;
std::vector<AutoVisGroup> autoVisGroups;
};

Expand Down
Loading

0 comments on commit 48bee80

Please sign in to comment.