pomsky-lang / pomsky

A new, portable, regular expression language
https://pomsky-lang.org
Apache License 2.0
1.28k stars 19 forks source link

Forward references aren't validated #84

Open Aloso opened 1 year ago

Aloso commented 1 year ago

Forward references can only appear within a repeated group that also contains the group the reference refers to. For example:

:first( :second( ::third ) :third() )+

This is ok because both the reference ::third and the referenced group :third() are within the first group, which is repeated.

Describe the bug

Pomsky does not check that forward references fulfill the above criteria. Ruby allows forward references, but fails to compile when they're invalid, so this should be validated by Pomsky as well.

To Reproduce

Compile one of these with Pomsky using the Ruby flavor:

:first( :second( ::third ) :third() ) # no repetition

::third :first( :second() :third() ) # no common parent group

then try to compile the result with Ruby.

Expected behavior

Since Ruby doesn't accept invalid forward references, Pomsky shouldn't either.