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

Document the grammar parsed by each ast type #393

Merged
merged 4 commits into from
Dec 20, 2024
Merged

Document the grammar parsed by each ast type #393

merged 4 commits into from
Dec 20, 2024

Conversation

mcy
Copy link
Member

@mcy mcy commented Dec 16, 2024

I chose to use modified regex syntax for the grammar definition, for two reasons:

  1. EBNF is quite verbose and difficult to read, which is why it's not actually used by very many language specifications (Go and Python are the only ones I can think of that do; C++, Java, Rust, and EcmaScript all use something closer to regular expressions; none of them use {} and [] the way EBNF does).

  2. Everyone knows regex syntax, and I frankly find it more succinct and easier to follow.

@mcy mcy requested a review from jhump December 16, 2024 19:23
experimental/ast/decl_def.go Outdated Show resolved Hide resolved
experimental/ast/decl_file.go Show resolved Hide resolved
experimental/ast/expr.go Outdated Show resolved Hide resolved
experimental/ast/expr.go Outdated Show resolved Hide resolved
experimental/ast/expr_array.go Outdated Show resolved Hide resolved
Comment on lines 35 to 38
// Path := `.`? component (sep component)*
//
// component := Ident | `(` Path `)`
// sep := `.` | `/`
Copy link
Member

Choose a reason for hiding this comment

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

Let's make the case consistently PascalCase here, too. Though we could use snake_case for "ident" since it's a lexical element that isn't defined in here.

Suggested change
// Path := `.`? component (sep component)*
//
// component := Ident | `(` Path `)`
// sep := `.` | `/`
// Path := `.`? Component (Sep Component)*
//
// Component := ident | `(` Path `)`
// Sep := `.` | `/`

experimental/ast/type.go Show resolved Hide resolved
experimental/ast/type.go Outdated Show resolved Hide resolved
experimental/ast/type.go Outdated Show resolved Hide resolved
experimental/ast/type_generic.go Outdated Show resolved Hide resolved
@mcy mcy enabled auto-merge (squash) December 20, 2024 19:43
@mcy mcy merged commit 77b1b7c into main Dec 20, 2024
8 checks passed
@mcy mcy deleted the mcy/ast-grammar branch December 20, 2024 19:46
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.

2 participants