-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fgdpp): replace parser with faster library
- Loading branch information
1 parent
9c75aa1
commit de8eace
Showing
16 changed files
with
11,156 additions
and
11,800 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,116 @@ | ||
#pragma once | ||
|
||
#include <list> | ||
#include <string> | ||
#include <string_view> | ||
#include <unordered_map> | ||
#include <vector> | ||
|
||
#include "structs/EntityProperties.h" | ||
#include <sourcepp/math/Vector.h> | ||
|
||
class BufferStream; | ||
class BufferStreamReadOnly; | ||
|
||
namespace fgdpp { | ||
|
||
class FGD { | ||
std::string rawFGDFile; | ||
|
||
//TOKENIZER | ||
public: | ||
enum TokenType { | ||
COMMENT = 0, // // | ||
DEFINITION, // @something | ||
EQUALS, // = | ||
OPEN_BRACE, // { | ||
CLOSE_BRACE, // } | ||
OPEN_BRACKET, // [ | ||
CLOSE_BRACKET, // ] | ||
OPEN_PARENTHESIS, // ( | ||
CLOSE_PARENTHESIS, // ) | ||
COMMA, // , | ||
STRING, // "something" | ||
PLUS, // + | ||
LITERAL, // anything that isn't any of the other tokens. | ||
COLUMN, // : | ||
NUMBER, // numbers -200000 ... 0 ... 2000000 | ||
struct Entity { | ||
struct ClassProperty { | ||
std::string_view name; | ||
std::string_view arguments; | ||
}; | ||
|
||
struct Field { | ||
std::string_view name; | ||
std::string_view valueType; | ||
std::string_view displayName; | ||
std::string_view valueDefault; | ||
std::string_view description; | ||
}; | ||
|
||
struct FieldChoices { | ||
struct Choice { | ||
std::string_view value; | ||
std::string_view displayName; | ||
}; | ||
|
||
std::string_view name; | ||
std::string_view displayName; | ||
std::string_view valueDefault; | ||
std::string_view description; | ||
std::vector<Choice> choices; | ||
}; | ||
|
||
struct FieldFlags { | ||
struct Flag { | ||
std::string_view value; | ||
std::string_view displayName; | ||
std::string_view enabledByDefault; | ||
std::string_view description; | ||
}; | ||
|
||
std::string_view name; | ||
std::vector<Flag> flags; | ||
}; | ||
|
||
struct IO { | ||
std::string_view name; | ||
std::string_view valueType; | ||
std::string_view description; | ||
}; | ||
|
||
std::string_view classType; | ||
std::vector<ClassProperty> classProperties; | ||
|
||
std::string_view description; | ||
|
||
std::vector<Field> fields; | ||
std::vector<FieldChoices> fieldsWithChoices; | ||
std::vector<FieldFlags> fieldsWithFlags; | ||
std::vector<IO> inputs; | ||
std::vector<IO> outputs; | ||
}; | ||
|
||
struct Token { | ||
TokenType type; | ||
Range range; | ||
std::string_view string; | ||
int line; | ||
ParseError associatedError; | ||
struct AutoVisGroup { | ||
std::string_view parentName; | ||
std::string_view name; | ||
std::vector<std::string_view> entities; | ||
}; | ||
|
||
std::vector<Token> tokenList; | ||
FGD() = default; | ||
|
||
public: | ||
FGD(std::string_view path, bool parseIncludes); | ||
explicit FGD(const std::string& fgdPath); | ||
|
||
private: | ||
bool TokenizeFile(); | ||
/** | ||
* Can be called multiple times in succession to load multiple FGD files. | ||
* The FGD file data will be merged with previously loaded data. | ||
* @param fgdPath The path to the FGD to load | ||
*/ | ||
void load(const std::string& fgdPath); | ||
|
||
//PARSER. | ||
public: | ||
FGDFile FGDFileContents; | ||
ParsingError parseError{ParseError::NO_ERROR, 0, {0, 0}}; | ||
[[nodiscard]] int getVersion() const; | ||
|
||
[[nodiscard]] sourcepp::math::Vec2i getMapSize() const; | ||
|
||
[[nodiscard]] const std::unordered_map<std::string_view, Entity>& getEntities() const; | ||
|
||
[[nodiscard]] const std::vector<std::string_view>& getMaterialExclusionDirs() const; | ||
|
||
[[nodiscard]] const std::vector<AutoVisGroup>& getAutoVisGroups() const; | ||
|
||
explicit operator bool() const; | ||
|
||
private: | ||
void readEntities(BufferStreamReadOnly& stream, const std::string& path, std::vector<std::string>& seenPaths); | ||
|
||
bool ParseFile(); | ||
std::list<std::string> backingData; | ||
|
||
#ifdef FGDPP_UNIFIED_FGD | ||
bool TagListDelimiter(std::vector<Token>::const_iterator& iter, TagList& tagList); | ||
#endif | ||
int version = 0; | ||
sourcepp::math::Vec2i mapSize{}; | ||
std::unordered_map<std::string_view, Entity> entities; | ||
std::vector<std::string_view> materialExclusionDirs; | ||
std::vector<AutoVisGroup> autoVisGroups; | ||
}; | ||
|
||
} // namespace fgdpp |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,3 @@ | ||
add_pretty_parser(fgdpp SOURCES | ||
"${CMAKE_CURRENT_SOURCE_DIR}/include/fgdpp/structs/EntityProperties.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/include/fgdpp/fgdpp.h" | ||
"${CMAKE_CURRENT_LIST_DIR}/fgdpp.cpp") | ||
|
||
if(FGDPP_ENABLE_SPEN_FGD_SUPPORT) | ||
target_compile_definitions(fgdpp PUBLIC FGDPP_UNIFIED_FGD) | ||
endif() |
Oops, something went wrong.