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

Warn about actions not being run by the interpreter #547

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bjansen
Copy link
Collaborator

@bjansen bjansen commented Apr 27, 2022

This is a proposed fix for #523

…interpreter

Signed-off-by: Bastien Jansen <bastien.jansen@gmx.com>
Signed-off-by: Bastien Jansen <bastien.jansen@gmx.com>
@bjansen bjansen added this to the 1.19 milestone Apr 27, 2022
@bjansen bjansen requested a review from parrt April 27, 2022 20:51

private void warnAboutPredicatesAndActions() {
if (!warnedAboutPredicates) {
notifyErrorListeners("WARNING: predicates and actions are not run by this interpreter. " +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest using correct location of action/sempred (pass it to the method), not the first line.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that it's already the case:

	public final void notifyErrorListeners(String msg)	{
		notifyErrorListeners(getCurrentToken(), msg, null);
	}

I can see the correct line:column in the generated message, as you can see in #523 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see but I'm not sure it's correct. It should point line:column in the grammar not in the input.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was actually thinking of a generic message saying that there are actions or predicates in the grammar. If there are multiple, I'm not sure a single line and call them from the grammar will be useful and could be misleading.

The mechanism @bjansen proposes is better in the sense that it warns only if an action/pred is seen during the parse, rather than generically if there are ever any actions visible.

@KvanTTT 's Point is still valid though that it's pointing into the input stream with getCurrentToken(). On the other hand, maybe it makes sense to simply make it more specific that upon reaching input token foo, we bypassed an action?

Copy link
Collaborator Author

@bjansen bjansen Apr 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it warns only if an action/pred is seen during the parse

That was indeed what I wanted to achieve.

I guess if an action is not run, there's a high probability there will be parse errors. So if we use getCurrentToken(), doesn't it make sense to "group" two error messages on the same token? One saying "hey we didn't expect this token here", and the other saying "but wait we skipped an action so it might be what's causing the error".

OTOH if we point to some location in the grammar, we're not actually "linking" the warning to any problem in the input.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more likely that a predicate what caused problems but of course predicate usually don't make sense without other actions to set state. I don't think we have handy access to map an action back into the grammar file/line/column. I think it's fine to simply identify the problem and indicate that, at this point at the input, we have skipped something that could be important.

}
outerMostPanel.add(editor, EDITOR_SPOT_COMPONENT);
}
editorSplitter.setFirstComponent(editor);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love the simplification of this code!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, that was a pleasant surprise!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed a problem though: the bottom console grows automatically with each new line of text that is added inside. That's not really desired

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to set a maximum height?

@parrt
Copy link
Member

parrt commented Apr 29, 2022

hi @bjansen I added a few in-line comments. Looking great!

@parrt
Copy link
Member

parrt commented May 13, 2022

Should I wait for this before pushing 1.19?

@bjansen bjansen modified the milestones: 1.19, 1.soon Mar 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants