Spaces not required in some parser instructions
The following syntax is currently valid:
from finesse import parse
model = parse("lasery ( P=1f=2)")
model
contains a laser
called "y". Its properties P
and f
are correctly set to 1 and 2. The reason this works is because we tell SLY to ignore all whitespace, when actually it is important for this sort of production. It could (probably - haven't tried) be fixed by no longer ignoring whitespace, but we'd have to add a whole bunch of rules to merge contiguous whitespace together and ignore it only where it can be ignored. Parser rules would also get more complicated because we'd have to include extra WHITESPACE
tokens in the right places. I think this will be quite some work.
Another option would be to redesign the grammar to actually make whitespace not important. This seems to be one of the reasons why other languages use commas, brackets, etc. to separate tokens in many productions. For instance, we could put the component name back inside the brackets and require that parameters be separated by commas:
laser ( l1, P=1, f=2 )
This syntax doesn't rely on whitespace; "laser(l1,P=1,f=2)" would also be valid, but wouldn't result in silly things like "lasery" being parsed as a laser
called y
(in this case it would be a syntax error).
Some downsides: this looks even less like kat2 script, and the component name has to go back inside the brackets. I can't remember why we moved it out of the brackets, but I recall there was some technical reason for this that we encountered during the hackathon. Maybe someone remembers why we did this?
The non-bracket version would also still require some thought. Using the above grammar but without brackets, this would be laser l1, P=1, f=2
which is a bit weird. And because we'd be ignoring whitespace, the following would work too: laser l1, P=1, f=2 laser l2 P=1, f=1
(newlines are also whitespace). And because there's no bracket delimiter, then technically laserl1,P=1,f=2
would still be possible to write. We might want to get rid of this option altogether and force brackets.
Thoughts?