Skip to content

Commit

Permalink
linting fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
apple1417 committed Dec 21, 2024
1 parent 2169012 commit b063a0f
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 24 deletions.
4 changes: 2 additions & 2 deletions text_mod_loader/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ but to summarize, simply add a few tags to the first comment block at the top of

Text Mod Loader supports the following tags.

| Tag Name | Multiple | Intepretation |
| Tag Name | Multiple | Interpretation |
| :--------------- | :------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `@author` | Allowed | The mod's author(s), all joined into a list, replacing `TextModLoader`. |
| `@description` | Allowed | Joined in the order encountered to create the mod's description. A tag with an empty value (after stripping whitespace) joins surrounding values with a newline, all other pairs are joined using a space. |
Expand Down Expand Up @@ -51,4 +51,4 @@ Text Mod Loader supports the following tags.
- Forced all mod info to be reloaded whenever you update TML.

## Text Mod Loader v1.0
- Inital Release.
- Initial Release.
2 changes: 1 addition & 1 deletion text_mod_loader/blimp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python

# This file is just a helper to let you run the BLIMP tag test suite against the file parser
# It should be run in a regular intepreter, it (obviously) won't do anything from inside the game
# It should be run in a regular interpreter, it (obviously) won't do anything from inside the game
# https://github.com/apple1417/blcmm-parsing/tree/master/blimp#tests
if __name__ == "__main__":
import json
Expand Down
16 changes: 8 additions & 8 deletions text_mod_loader/file_parser/blcm_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ void extract_description(pugi::xml_document& doc, ParseResult& parse_result) {

static const constexpr CaseInsensitiveStringView comment = "comment";
if (child_name == comment) {
auto comment = child.child_value();
if (is_command(comment)) {
auto value = child.child_value();
if (is_command(value)) {
// This comment was really holding a command, the description's over
break;
}
parse_result.add_comment(comment);
parse_result.add_comment(value);
continue;
}

static const constexpr CaseInsensitiveStringView category = "category";
if (child_name == category) {
CaseInsensitiveStringView category_name = child.attribute("name").as_string();
const CaseInsensitiveStringView category_name = child.attribute("name").as_string();

static const constexpr CaseInsensitiveStringView description = "description";
if (category_name.find(description) == CaseInsensitiveStringView::npos) {
Expand All @@ -56,12 +56,12 @@ void extract_description(pugi::xml_document& doc, ParseResult& parse_result) {

for (auto grandchild : child) {
const std::string_view grandchild_name = grandchild.name();
if (grandchild_name == "comment") {
auto comment = grandchild.child_value();
if (is_command(comment)) {
if (grandchild_name == comment) {
auto value = grandchild.child_value();
if (is_command(value)) {
break;
}
parse_result.add_comment(comment);
parse_result.add_comment(value);
continue;
}

Expand Down
9 changes: 5 additions & 4 deletions text_mod_loader/file_parser/filtertool_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ void parse_filtertool_file(std::istream& stream, ParseResult& parse_result) {
for (; std::getline(stream, line);) {
auto first_non_space =
std::ranges::find_if_not(line, [](auto chr) { return std::isspace(chr); });
auto last_non_space = std::find_if_not(line.rbegin(), line.rend(),
[](auto chr) { return std::isspace(chr); });
auto last_non_space = std::ranges::find_if_not(std::ranges::reverse_view(line),
[](auto chr) { return std::isspace(chr); });

std::string_view trimmed{first_non_space, last_non_space.base()};
const std::string_view trimmed{first_non_space, last_non_space.base()};

if (trimmed.starts_with("#<") && trimmed.ends_with('>')) {
if (!started_description_category) {
CaseInsensitiveStringView category_name{trimmed.begin() + 2, trimmed.end() - 1};
const CaseInsensitiveStringView category_name{trimmed.begin() + 2,
trimmed.end() - 1};

static const constexpr CaseInsensitiveStringView description = "description";
if (category_name.find(description) != CaseInsensitiveStringView::npos) {
Expand Down
6 changes: 3 additions & 3 deletions text_mod_loader/file_parser/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ pybind11::error_already_set file_not_found(const std::filesystem::path& filename
*/
void look_for_spark_service(std::istream& input, ParseResult& parse_result) {
for (std::string line; std::getline(input, line);) {
// Aproximately matching the regex:
// /\s+set\s+Transient.SparkServiceConfiguration_\d+\s+(keys|values)/i
// Approximately matching the regex:
// /\s+set\s+Transient.SparkServiceConfiguration_(\d+)\s+(keys|values)/i

const constexpr CaseInsensitiveStringView set = "set";
const constexpr CaseInsensitiveStringView transient =
"Transient.SparkServiceConfiguration_";
const constexpr CaseInsensitiveStringView keys = "Keys";
const constexpr CaseInsensitiveStringView values = "Values";

CaseInsensitiveStringView line_view{line};
const CaseInsensitiveStringView line_view{line};
auto set_offset = line_view.find(set);
if (set_offset == std::string::npos) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion text_mod_loader/file_parser/parse_result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void ParseResult::discard_comments(void) {
}

void ParseResult::add_comment(const char* comment) {
std::string_view comment_view{comment};
const std::string_view comment_view{comment};

if (comment_view.empty()) {
return;
Expand Down
12 changes: 11 additions & 1 deletion text_mod_loader/file_parser/parse_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@

namespace tml {

struct ParseResult {
// By default, pybind tries to compile with visibility hidden
// If we have default visibility in a type holding pybind objects as members, this may cause a
// warning, since our type has greater visibility than it's members
// This macro sets the right visibility
#if defined(__MINGW32__)
#define PY_OBJECT_VISIBILITY __attribute__((visibility("hidden")))
#else
#define PY_OBJECT_VISIBILITY
#endif

struct PY_OBJECT_VISIBILITY ParseResult {
// Unordered map doesn't like working with python strings, have to store tags as a python dict
py::dict blimp_tags;
std::vector<py::str> untagged_lines;
Expand Down
2 changes: 1 addition & 1 deletion text_mod_loader/file_parser/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ bool is_command(CaseInsensitiveStringView str, bool allow_spark) {
}

auto word_end = std::find_if(non_space, str.end(), [](auto chr) { return std::isspace(chr); });
CaseInsensitiveStringView first_word{non_space, word_end};
const CaseInsensitiveStringView first_word{non_space, word_end};
return first_word == "say" || first_word == "exec" || first_word == "set";
}

Expand Down
2 changes: 1 addition & 1 deletion text_mod_loader/hotfixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def mark_hotfixes_used() -> None:

def is_hotfix_service(idx: int) -> bool:
"""
Checks if the given Spark Service index corosponds to the hotfix service.
Checks if the given Spark Service index corresponds to the hotfix service.
Args:
idx: The Spark Service index to check.
Expand Down
4 changes: 2 additions & 2 deletions text_mod_loader/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def join_lines_markdown_like(lines: Iterable[str]) -> str:
"""
Joins a list of lines similarly to how markdown does it.
Adjacent lines get space seperated, you need an entirely empty line to add a newline.
Adjacent lines get space separated, you need an entirely empty line to add a newline.
Args:
lines: The lines to join.
Expand Down Expand Up @@ -139,7 +139,7 @@ def load_mod_info(path: Path) -> ModInfo:
if (description_list := parse_result.blimp_tags.get("@description")) is not None:
description = join_lines_markdown_like(description_list)
else:
# If there's no explict description tags, extract it from the untagged lines instead
# If there's no explicit description tags, extract it from the untagged lines instead
strip_chars = find_edge_characters(parse_result.untagged_lines)
description = join_lines_markdown_like(
line.strip(strip_chars) for line in parse_result.untagged_lines
Expand Down

0 comments on commit b063a0f

Please sign in to comment.