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

move each OperatorDefinition to its own Production #374

Closed
OmarTawfik opened this issue Mar 20, 2023 · 0 comments · Fixed by #477
Closed

move each OperatorDefinition to its own Production #374

OmarTawfik opened this issue Mar 20, 2023 · 0 comments · Fixed by #477
Assignees

Comments

@OmarTawfik
Copy link
Collaborator

OmarTawfik commented Mar 20, 2023

Originally posted by @OmarTawfik in #332 (comment):

In the current grammar, name here is the name of the parent expression node (that contains both the operator and operands). There is no way to define a name for the operator node.

- name: "UnarySuffixExpression" # name of parent node
  model: "UnarySuffix"
  choice: # cannot name the operator node
    - terminal: "++"
    - terminal: "--"

Moreover, this shape forces us to duplicate the entire base expression node for each version break in one of the operators. See #432 for example. I suspect these versions will only keep growing, making it harder to read, understand, and diff its contents.

I suggest moving the definition of each operator to its own Production (as a ParserRef, where it can be versioned separately. The main Expression.operators list can remain unversioned, unless a version actually adds/removes operators, or changes their precedence.

Additionally, this includes it in visit_parser visitor checks. We don't do that now, which is a bug.

pub struct OperatorDefinition {
    pub name: String,
    pub model: OperatorModel,
    pub operator: ParserRef,
}

This allows us to do:

- name: "UnarySuffixExpression"
  model: "UnarySuffix"
  operator: "UnarySuffixOperator"
  
- name: "UnarySuffixOperator"
  unversioned:
    choice:
        - terminal: "++"
        - terminal: "--"
@OmarTawfik OmarTawfik added this to the 2️⃣ Beta Preview milestone Mar 20, 2023
@OmarTawfik OmarTawfik changed the title use ParserRef in OperatorDefinition move each OperatorDefinition to its own Production May 3, 2023
OmarTawfik added a commit that referenced this issue May 19, 2023
Allows us to:

- de-duplicate large operators across different versions
- add names to operators if needed (will do in a following PR)

closes #374
OmarTawfik added a commit that referenced this issue May 19, 2023
Allows us to:

- de-duplicate large operators across different versions
- add names to operators, doing in #353

note: some of the additional nodes (like `ConditionalOperator`) will be inlined in #323

closes #374
OmarTawfik added a commit that referenced this issue May 22, 2023
Allows us to:

- de-duplicate large operators across different versions
- add names to operators, doing in #353

note: some of the additional nodes (like `ConditionalOperator`) will be inlined in #323

closes #374
OmarTawfik added a commit that referenced this issue May 23, 2023
Allows us to:

- de-duplicate large operators across different versions
- add names to operators, doing in #353

note: some of the additional nodes (like `ConditionalOperator`) will be inlined in #323

closes #374
OmarTawfik added a commit that referenced this issue May 23, 2023
Allows us to:

- de-duplicate large operators across different versions
- add names to operators, doing in #353

note: some of the additional nodes (like `ConditionalOperator`) will be inlined in #323

closes #374
@OmarTawfik OmarTawfik linked a pull request May 23, 2023 that will close this issue
OmarTawfik added a commit that referenced this issue May 24, 2023
Allows us to:

- de-duplicate large operators across different versions
- add names to operators, doing in #353

note: some of the additional nodes (like `ConditionalOperator`) will be inlined in #323

closes #374
@OmarTawfik OmarTawfik added this to the 1️⃣ Alpha Preview milestone Jul 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants