sbnf icon indicating copy to clipboard operation
sbnf copied to clipboard

Manual branch point as an alternative to adjusting regexes to be equivalent

Open eugenesvk opened this issue 2 years ago • 4 comments

SBNF ... Due to the complexities of regex, a branch point is only created with equivalent regexes.

Could an alternative solution to manually fixing the regexes to be equivalent (rather error-prone in more complicated composable regex rules) to manually indicate that a branch point needs to be created?

So you could write

main : 'aa?'{scope1 ⸙1} 'b'
     | 'a'  {scope2 ⸙1} 'c' ;

instead of

main : 'aa'{scope1} 'b'
     | 'a'{scope1} 'b'
     | 'a'{scope2} 'c' ;

eugenesvk avatar Jun 05 '23 13:06 eugenesvk

I don't see how this is all that useful beyond tiny examples. Branch points can and do start anywhere, usually across different rules. Maybe a way to specify a "ambiguity regex" for this use case?

BenjaminSchaaf avatar Sep 27 '23 08:09 BenjaminSchaaf

The need arose very much from a non-tiny example precisely because it wasn't tiny, and the rules were composed from many sub-rules, so you couldn't see whether the rules were equivalent (especially when tweaking those sub-rules) and thus track the changes progressively (with a manual branch you are certain it branched, so you can only focus on the post-branching rules)

Not sure what "ambiguity regex" is, so don't know whether it can help resolve this

eugenesvk avatar Sep 27 '23 12:09 eugenesvk

By "ambiguity regex" I mean specifying a regex with which to check for equivalent regexes. ie. a way to say 'aa?' is equivalent to 'a'.

Here's a counterexample to the proposed behavior:

a : 'a' ;
aa : 'aa?' ;
aaa : 'aa*' ;

one : a | aa ;
two : a | aa | aaa ;

Both a and aa start two different branch points from different rules.

BenjaminSchaaf avatar Sep 27 '23 13:09 BenjaminSchaaf

Maybe this could also work

eugenesvk avatar Sep 27 '23 14:09 eugenesvk