Whitespace argument matching
alexgran875 opened this issue · 3 comments
Describe the bug
Match templates are sensitive to whitespaces.
Reproducing
I am trying to match this:
bit.ly/3CR6CrE
However, if I remove the whitespaces in the original code then it doesn't match anymore (removed whitespace in front of state_fn_call()):
bit.ly/3o03TWI
To remedy that, I also need to remove the whitespace in the match template (removed whitespace in front of :[function_call]):
bit.ly/3k9hlGM
Expected behavior
I would expect Comby to identically match both cases with the same match template and not behave differently depending on whether there is a whitespace before the next argument in the code.
Additional context
I believe this to be a bug, but I am new to Comby so maybe this is intended behavior. If this is intended behavior, is there any away to make a generic matching template to match both cases with whitespaces and without whitespaces between the function arguments?
Hi 👋
I believe this to be a bug, but I am new to Comby so maybe this is intended behavior.
This is not a bug, but indeed a limitation right now, as you point out. Comby is sensitive to the presence of whitespace, but not the amount. There are only some contexts where "zero or more spaces" is desired, rather than "one or more spaces". Those contexts are typically cases like this, around separators ,
and, say, delimiters (<optional space>...)
, but in other contexts, the presence of whitespace is significant. For example, func foo
should not be treated as funcfoo
.
I would expect Comby to identically match both cases with the same match template and not behave differently depending on whether there is a whitespace before the next argument in the code.
I have some work in progress, to make whitespace optional in certain contexts, like punctuation/separators/delimiters, but right now it's not possible.
My recommended fix is that you inline regular expressions that indeed tell comby that the whitespace is optional in these positions (i.e, before and after ,
). It doesn't look as pretty, but currently that's the only workaround, until I finish the work for making whitespace matching contextually parameterizable :-) Here is a single template, using inlined regex, that matches all those varieties: https://bit.ly/3kaMd9P
Thank you for your help! That fixed my issue!
I just tried using comby for the first time and noticed the same issue. If automatic support isn't in the near horizon, perhaps there could be some kind of shortcut for "zero or more whitespace" in the meanwhile? :[~\s*]
is bit cumbersome to repeat multiple times in a template.
I have no opinions on the possible syntax though.