ckparser 0.3__tar.gz → 0.3.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ckparser
3
- Version: 0.3
3
+ Version: 0.3.1
4
4
  Summary: Parse Paradox Jomini data files to Python/JSON and revert them back experimentally.
5
5
  Author: Marc Debureaux (debnet)
6
6
  License-Expression: MIT
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ckparser
3
- Version: 0.3
3
+ Version: 0.3.1
4
4
  Summary: Parse Paradox Jomini data files to Python/JSON and revert them back experimentally.
5
5
  Author: Marc Debureaux (debnet)
6
6
  License-Expression: MIT
@@ -41,7 +41,7 @@ import re
41
41
  import time
42
42
 
43
43
  # Script version
44
- __version__ = "0.3"
44
+ __version__ = "0.3.1"
45
45
 
46
46
  # Logger (because logging is awesome)
47
47
  logger = logging.getLogger(__name__)
@@ -102,17 +102,17 @@ regex_string_multiline = re.compile(r"\"[^\"]*\"", re.MULTILINE)
102
102
  # Regex for quoted strings inside quoted strings
103
103
  regex_inner_string = re.compile(r"\|(?P<index>\d+)\|")
104
104
  # Regex to remove comments in files
105
- regex_comment = re.compile(r"(?P<space>\s*)(?P<comment>#.*)")
105
+ regex_comment = re.compile(r"(?P<space>\s*)(?P<comment>#.*)", re.MULTILINE)
106
106
  # Regex to fix blocks with no equal sign
107
- regex_block = re.compile(r"^([^\s\{\=]+)\s*\{\s*$", re.MULTILINE)
107
+ regex_missing = re.compile(r"^\s*([\w\.]+)\s+([{])", re.MULTILINE)
108
108
  # Regex to remove "list" prefix
109
109
  regex_list = re.compile(r"\s*=\s*list\s+([\{\"\|])", re.MULTILINE)
110
110
  # Regex for color blocks (color = [rgb|hsv] { x y z })
111
- regex_color = re.compile(r"=\s*(?P<type>\w+)\s*{")
111
+ regex_color = re.compile(r"=\s*(?P<type>\w+)\s*{", re.MULTILINE)
112
112
  # Regex to parse items with format key=value
113
113
  regex_inline = re.compile(r"([^\s\"]+\s*[?!<=>]+\s*(([^@\"]\[?[^\s]+\]?)|(\"[^\"]+\")|(@\[[^\]]+\]))|(@\w+))")
114
114
  # Regex to parse blocks with bracket below the key/operator
115
- regex_values = re.compile(r"(\s*([?!<=>]+)\s+\{)|(\s+\s*([?!<=>])+\s*\{)")
115
+ regex_block = re.compile(r"(\s*([?!<=>]+)\s+\{)|(\s+\s*([?!<=>])+\s*\{)", re.MULTILINE)
116
116
  # Regex to parse lines with format key=value
117
117
  regex_line = re.compile(r"\"?(?P<key>[^\s\"]+)\"?\s*(?P<operator>[?!<=>]+)\s*(list\s*)?(?P<value>.*)")
118
118
  # Regex to parse independent items in a list
@@ -126,7 +126,7 @@ regex_locale = re.compile(r"^\s*(?P<key>[^\:#]+)\:(\d+)?\s\"(?P<value>.+)\".*$")
126
126
  # Regex for keywords
127
127
  regex_keyword = re.compile(r"(" + "|".join(map(re.escape, sorted(keywords, key=len, reverse=True))) + r") ")
128
128
  # Regex for fixing line count when bracket is below the key/operator
129
- regex_count = re.compile(r"([?!<=>]+)\s*§\n+\s*\{")
129
+ regex_count = re.compile(r"([?!<=>]+)\s*([§\n]+)\s*\{")
130
130
  # Regex for string indexes
131
131
  regex_index = re.compile(r"\|(\d+)\|")
132
132
  # Regex for variables
@@ -234,15 +234,21 @@ def parse_text(text, return_text_on_error=False, comments=False, dates=False, fi
234
234
  text = regex_comment.sub(replace_comment, text)
235
235
  else:
236
236
  text = regex_comment.sub("", text)
237
- text = text.replace("{", "\n{\n").replace("}", "\n}\n")
238
237
  text = regex_string_multiline.sub(replace, text)
239
- text = regex_list.sub(r"|list=\g<1>", text)
238
+ if missings := regex_missing.findall(text):
239
+ if filename:
240
+ logger.warning(f"Filename: {filename}")
241
+ for key, val in missings:
242
+ logger.warning(f"Potential missing `=` operator between `{key}` and `{val}` needs to be fixed.")
243
+ text = regex_missing.sub(r"\g<1>=\g<2>", text)
240
244
  text = regex_color.sub(r"={\n\g<1>", text)
245
+ text = regex_list.sub(r"|list=\g<1>", text)
246
+ text = text.replace("{", "\n{\n").replace("}", "\n}\n")
241
247
  text = regex_inline.sub(r"\g<1>\n", text)
242
- text = regex_values.sub(r"\g<2>\g<4>{", text)
248
+ text = regex_block.sub(r"\g<2>\g<4>{", text)
243
249
  text = regex_empty.sub(r"\n", text)
244
250
  text = regex_keyword.sub(r"\1|", text)
245
- text = regex_count.sub(r"\g<1>{\n§", text)
251
+ text = regex_count.sub(r"\g<1>{\n\g<2>", text)
246
252
  text = regex_index.sub(lambda match: strings[match.group(1)], text)
247
253
 
248
254
  # Parsing document line by line
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "ckparser"
7
- version = "0.3"
7
+ version = "0.3.1"
8
8
  description = "Parse Paradox Jomini data files to Python/JSON and revert them back experimentally."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
File without changes
File without changes
File without changes
File without changes