Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actions that return a value may execute without replacement by that return value #1207

Open
eh-adblockplus-org opened this issue Aug 5, 2018 · 0 comments

Comments

@eh-adblockplus-org
Copy link

In the example below, test t2 fails, not by failing the assertion, but with an ordinary false return value. The example is constructed as a model of a mistaken declaration, such as a typo. Even though B, the return value of b, is not convertible to A, the action executes anyway but the return value does not substitute for the default node in the parse tree.

This behavior is, at best, confusing. What should never happen is that all of the following occur:

  • The action runs.
  • The return value is ignored.
  • There's no error generated.

It would be best if there were a compilation error so that such a grammar can never be parsed. There are other possible actions. One would be to not run the action at all, preferably with a warning somewhere. Another would be to generate a run-time error upon detection of the inconsistency, by default terminating the program (thus it wouldn't matter whether before or after the action runs).

module action_03

import Message ;
import ParseTree ;

syntax A
	= a: "1"
	| b: "2"
	| c: "3" ;
syntax B = b: "4" ;

anno str A @ msg ;
anno str B @ msg ;
bool executed ;
A a()
{
	executed = true;
	A x = (A)`1` ;
	x@msg = "action \"a\" executed" ;
	return x ;
}
B b()
{
	executed = true;
	B x = (B)`4` ;
	x@msg = "action \"b\" executed" ;
	return x ;
}
void c()
{
	executed = true ;
}

test bool t1()
{
	executed = false ;
	Tree t = parse( #A, "1" ) ;
	assert executed ;
	return t@msg ? ;
}
test bool t2()
{
	executed = false ;
	Tree t = parse( #A, "2" ) ;
	assert executed ;
	return t@msg ? ;
}
test bool t3()
{
	executed = false ;
	Tree t = parse( #A, "3" ) ;
	assert executed ;
	return ! t@msg ? ;
}
test bool t4()
{
	executed = false ;
	Tree t = parse( #B, "4" ) ;
	assert executed ;
	return t@msg ? ;
}

Version is 0.10.0.201807232201 under Eclipse Photon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant