Skip to content

Commit

Permalink
support ignore mpc in comments and unparsable operation
Browse files Browse the repository at this point in the history
  • Loading branch information
yasirroni committed Nov 13, 2024
1 parent f2bdbc0 commit 5d2f938
Show file tree
Hide file tree
Showing 2 changed files with 451 additions and 27 deletions.
10 changes: 7 additions & 3 deletions matpowercaseframes/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ def find_name(string):


def find_attributes(string):
pattern = "mpc\\.(?P<attribute>.*?)\\s*=\\s*"
return re.findall(pattern, string, re.DOTALL)
pattern = "^\\s*mpc\\.(?P<attribute>[^\\s=]*)"
match = re.findall(pattern, string, re.MULTILINE)
return match


def parse_file(attribute, string):
Expand Down Expand Up @@ -49,7 +50,10 @@ def search_file(attribute, string):
# ["gen", "gencost", "bus", "branch", "dcline", "dclinecost"] or any keys
pattern = r"mpc\.{}\s*=\s*\[[\n]?(?P<data>.*?)[\n]?\];".format(attribute)

match = re.search(pattern, string, re.DOTALL)
try:
match = re.search(pattern, string, re.DOTALL)
except Exception:
return None

if match is None:
return None
Expand Down
Loading

0 comments on commit 5d2f938

Please sign in to comment.