Repository: SDXorg/pysd (language: python)

Issue:
Error reading Vensim model (parsimonious.exceptions.IncompleteParseError)
Hello,

I am not able to read a relatively complex Vensim model with eight model views. 

I tried two ways and neither worked.

1. Read the model with the default arguments:

model = pysd.read_vensim('C:\\Users\\...path...\\model.mdl')
*** TypeError: cannot unpack non-iterable NoneType object

2. Read the model with split_views = True

model = pysd.read_vensim('C:\\Users\\...path...\\model.mdl', split_views=True)
*** parsimonious.exceptions.IncompleteParseError: Rule 'line' matched in its entirety, but it didn't consume all the text. The non-matching portion of the text begins with '|14|BU|0-0-128' (line 1, column 71).

In case 2, the text '|14|BU|0-0-128' raising the error is located toward the end of the mdl file (in text view), having to do with the sketch information generated automatically by Vensim. In particular, the line is in a block related to the eighth and last view:
...
10,73,simulator mode,194,665,68,11,8,131,0,18,-1,0,0,0,-1--1--1,0-0-0,|14|BU|0-0-128
12,74,105057302,192,632,80,20,3,60,0,0,0,0,0,0
simulator mode,0,1,1
30,75,f1303_17 - Copy0027.bmp,370,641,79,29,8,3,0,0,-1,0,0,0
12,76,34931712,812,203,221,110,3,188,0,0,1,0,0,0
...

Thanks for any advice.


Discussion / hints:
Hi @mak63-dev,

Thanks for reporting this error.

Can you please try using either underline or bold font, but not both, and let us know if this solves the problem?

Thank you

Fix patch:
diff --git a/pysd/translators/vensim/parsing_grammars/sketch.peg b/pysd/translators/vensim/parsing_grammars/sketch.peg
index 14f69e2d..4decd221 100644
--- a/pysd/translators/vensim/parsing_grammars/sketch.peg
+++ b/pysd/translators/vensim/parsing_grammars/sketch.peg
@@ -35,7 +35,7 @@ other_objects = other_objects_code "," anything
 
 # fonts
 font_properties = font_name? "|" font_size? "|" font_style? "|" color
-font_style =  "B" / "I" / "U" / "S" / "V"  # italics, bold, underline, etc
+font_style =  ("B" / "I" / "U" / "S" / "V")+  # italics, bold, underline, etc
 font_size =  ~r"\d+"  # this needs to be made a regex to match any font
 font_name = ~r"(?<=,)[^\|\d]+(?=\|)"
 
diff --git a/requirements.txt b/requirements.txt
index 2e14f4ea..8d35a4d9 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -6,7 +6,7 @@ lxml
 regex
 chardet
 black
-openpyxl>=3.1
+openpyxl>=3.1.2
 scipy
 progressbar2
 portion


Test patch:
diff --git a/tests/requirements.txt b/tests/requirements.txt
index ec944b8d..a8c583e3 100644
--- a/tests/requirements.txt
+++ b/tests/requirements.txt
@@ -7,7 +7,7 @@ pytest-xdist
 coverage
 coveralls
 psutil
-netCDF4>=1.6.*
+netCDF4>=1.6
 dask[array]
 dask[diagnostics]
 dask[distributed]