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

Let annotations take an argumentList rather than expressionList | keyValueList #633

Closed
SantiagoBautista opened this issue May 31, 2018 · 6 comments

Comments

@SantiagoBautista
Copy link
Contributor

SantiagoBautista commented May 31, 2018

Currently in the P4-16 grammar, annotations can take either an expression list or a keyValuePair List for their arguments and this allows arguments to annotations to be named:

annotation
    : '@' name
    | '@' name '(' expressionList ')'
    | '@' name '(' keyValueList ')'
    ;

But this makes the grammar ambiguous, because there is no way of telling whether the empty list is an expressionList or a keyValueList.

There is a non-ambiguous and nicer way of achieving exactly the same behavior:
there is a non-terminal in P4-16 grammar called argumentList , and each argument can either be an expression or a name '=' expression (i.e. a keyValuePair).

So if annotations took an argumentList, instead of either an expressionList or a keyValueList, we would have exactly the same behavior, but without introducing ambiguity to the grammar.

I will open a Pull Request implementing this solution.

SantiagoBautista added a commit to SantiagoBautista/p4-spec that referenced this issue May 31, 2018
If annotations take argumentList instead
of either expressionList or keyValueList,
the exact same behavior is acheived,
but without introducing ambiguity.
@jnfoster
Copy link
Collaborator

jnfoster commented May 31, 2018 via email

@SantiagoBautista
Copy link
Contributor Author

SantiagoBautista commented May 31, 2018

To be precise, there is another difference: if annotations take argumentList, then one single annotation can take both key-value pairs and expressions; whereas with the current grammar one annotation can either only take expressions or only take key-value pairs.
So the simplification I propose would allow a more flexible behavior (both because of '_' and the possibility of mixing expressions and key-value pairs), that strictly contains the current behavior.

But this extra flexibility can, I guess, be useful, and AFAIK it doesn't introduce any problems.

@SantiagoBautista
Copy link
Contributor Author

SantiagoBautista commented May 31, 2018

For information:
This issue is related to #605 and #625 .
So @mbudiu-vmw @ChrisDodd and @chrispsommers could be interested.

@chrispsommers
Copy link
Contributor

@SantiagoBautista I like this, good catch!

@SantiagoBautista
Copy link
Contributor Author

Thank you @chrispsommers !

@mihaibudiu
Copy link
Contributor

This is no longer relevant, since we now have free-form annotations.

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

4 participants