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

Pratt parsing and explicit node elision #4

Merged
merged 5 commits into from
Dec 23, 2024
Merged

Conversation

0x2a-42
Copy link
Owner

@0x2a-42 0x2a-42 commented Dec 22, 2024

Fix for #2.

Node elision for rules is now an explicit operation and no longer determined by certain rule patterns. Left recursive rules are now parsed by a Pratt parser.

Migration Guide

The empty node rename operator @ is no longer allowed. It was previously used to avoid matching certain rule patterns, which is no longer necessary.

Operator Precedence

Use the node elision operator for the non-recursive branches.

Before

bin_expr:
  bin_expr ('*' | '/') bin_expr
| bin_expr ('+' | '-') bin_expr
| primary_expr
;

After

bin_expr:
  bin_expr ('*' | '/') bin_expr
| bin_expr ('+' | '-') bin_expr
| primary_expr ^
;

Unconditional Forwarding

Add the elision operator after the rule name.

Before

stmt:
  for_stmt
| while_stmt
| expr_stmt
| return_stmt
;

After

stmt^:
  for_stmt
| while_stmt
| expr_stmt
| return_stmt
;

Conditional Forwarding

Add the elision operator after the rule name and create a node explicitly.

Before

assign_expr: bin_expr ['=' assign_expr];

After

assign_expr^: bin_expr ['=' assign_expr >];

Right Recursive Forwarding

Use the node elision operator for the non-recursive branches.

Before

unary_expr:
  ('+' | '-') unary_expr
| primary_expr
;

After

unary_expr:
  ('+' | '-') unary_expr
| primary_expr ^
;

Maybe Empty

Add the elision operator after the rule name and create a node explicitly.

Before

generic_args:
  ['<' type_list '>']
;

After

generic_args^:
  ['<' type_list '>' >]
;

@0x2a-42 0x2a-42 merged commit 82a3bfd into main Dec 23, 2024
2 checks passed
@0x2a-42 0x2a-42 deleted the pratt_parsing_node_elision branch December 23, 2024 00:27
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

Successfully merging this pull request may close these issues.

1 participant