pomsky icon indicating copy to clipboard operation
pomsky copied to clipboard

[docs] negating references

Open fbstj opened this issue 3 years ago • 3 comments

oftentimes a "quote finding" or "bracket finding" regex might be something like \"[^"]*\" or \([^()]\). one of the examples for references is :(['"' "'"]) !['"' "'"]* ::1 which would not match "shan't"[^1]. does/should :(['"' "'"]) (!::1)* ::1 work to match that? is it worth adding a later example of such a thing? or is it better to show/link to an example for handling "inline \" quoted \" escaped"strings instead?

[^1]: I also see that the formal grammar has a "simpler" '"' !'"'+ '"' | "'" !"'"+ "'" named String example which doesn't have the limits of the reference example.

fbstj avatar Jun 09 '22 11:06 fbstj

(!::1) isn't possible because backreferences can't be negated AFAIK. What regex should this compile to?

I agree that this example for references is bad, but I couldn't come up with a better example.

Aloso avatar Jun 09 '22 13:06 Aloso

if they can't be negated then that should possibly be mentioned, (unless the error message is great?) or if there is a better example that can be added later then it should maybe be mentioned: "this simple string matching example is more of a conceptual example than something you'd want to actually use this feature for, check this other example / blog post for a reason for actually needing this feature"

but yeah negating the back-reference was a question that I definitely had whilst reading, since you have other negations in previous sections, and complex ones too. the html tag one (<:(['a'-'z']+)>[!'<']+</::1>) is a good example imo

fbstj avatar Jun 09 '22 14:06 fbstj

One part of this issue is now fixed: Error messages for negation have been improved.

$ rulex "!::test"

Error: 
  × This expression can't be negated
   ╭────
 1 │ !::test
   · ┬
   · ╰── error occurred here
   ╰────

I'll make new release soon, then you can try it in the playground.

Aloso avatar Jun 12 '22 20:06 Aloso