The with() rule uses where() internally, which means the output of the given strategy is not returned. I found this to be surprising in in some cases rather troublesome as I just wanted to mark some rule invokations in “should not fail” without otherwise affecting their usage.

So, I made a wrapper like this:

/** 
  * Run s; if it fails, report a fatal error with m as the message
  *
  * @param m Information to include in the fatal error message
  * @param s Strategy to execute
  */
req(s|message): input -> output
  with with(output := <s> | message) 

One thing missing is be a facility to capture the name/identity of a passed rule automatically. I’m often writing something like:

foo: Foo(bar) -> <req(foo|"foo failed unexpectedly")> Foo(bar,<new>)

Ideally some kind of macro or introspection facility would be able to generate the message (including the strategy name / source code) without it being passed explicitly.

Submitted by Dobes Vandermeer on 19 November 2012 at 19:28

On 20 November 2012 at 01:31 Dobes Vandermeer removed tag error

On 20 November 2012 at 14:20 Lennart Kats commented:

This is by design, for symmetry with where().


On 20 November 2012 at 22:24 Dobes Vandermeer commented:

I see - but there’s no “non-where-like” version in the library, perhaps the one I provided here could be put in the standard library somewhere for people who want their “with” without the “where”.

Probably people will sometimes want with to behave like where, and sometimes not.


On 21 November 2012 at 09:16 Lennart Kats commented:

Okay, I reformulated your issue title into a feature request :)

BTW, you can get close to what the compiler could do if you implement one yourself based on https://svn.strategoxt.org/repos/StrategoXT/strategoxt/trunk/stratego-libraries/lib/spec/lang/with.str.


On 7 December 2012 at 11:13 Gabriël Konat tagged feature

On 8 January 2013 at 13:46 Eelco Visser tagged stratego

On 8 January 2013 at 13:46 Eelco Visser tagged minor

On 10 March 2013 at 10:54 Guido Wachsmuth commented:

Given your example

foo: Foo(bar) -> <req(foo|"foo failed unexpectedly")> Foo(bar,<new>)

You can write this simply as:

foo: Foo(bar) -> result with result := <foo> Foo(bar, <new>)

When the with clause fails, you get a stack trace for foo.

Log in to post comments