Skip to content

Refactor AST into a struct containing AST.Node enum #130

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

Merged
merged 2 commits into from
Jan 27, 2022

Conversation

hamishknight
Copy link
Contributor

Introduce AST as a new root type, with AST.Node becoming the type used to represent a particular node in the AST. This will allow us to store top-level state on the AST type rather than for each AST.Node.

@hamishknight
Copy link
Contributor Author

@swift-ci please test Linux

@hamishknight hamishknight requested a review from milseman January 26, 2022 19:11
Comment on lines 121 to 131
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2021-2022 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
//===----------------------------------------------------------------------===//

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rxwei Does it make sense to include the copyright notice here? As otherwise it gets removed when re-running the generator.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes it does. I'm already adding it here: #114, but the PR is blocked until there's a new toolchain.

Copy link
Contributor

@rxwei rxwei Jan 26, 2022

Choose a reason for hiding this comment

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

It might be better not to change this so that I won't have to resolve conflicts for my chain of 3 PRs 😂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I was just thinking that, though I think there will still be a conflict as I'm still changing Concatenation.swift, but at least that can be resolved by re-running the generator

Copy link
Member

@milseman milseman left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -127,7 +127,7 @@ extension Parser {
}
fatalError("Unhandled termination condition")
}
return ast
return .init(ast)
Copy link
Member

Choose a reason for hiding this comment

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

Where do global options come in?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We'll parse them here and store them on AST

Copy link
Member

Choose a reason for hiding this comment

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

Oh, right, that will be based on top of this. SGTM

Introduce `AST` as a new root type, with `AST.Node`
becoming the type used to represent a particular
node in the AST. This will allow us to store top-level
state on the `AST` type rather than for each `AST.Node`.
Fix places that are currently producing and consuming
AST nodes to use `AST.Node` instead of `AST`.

This requires adding entry-points for both `AST`
and `AST.Node` for:

- renderAsCanonical
- printAsCanonical
- printAsPattern
- _render(in:)
@hamishknight
Copy link
Contributor Author

@swift-ci please test Linux

1 similar comment
@milseman
Copy link
Member

@swift-ci please test Linux

@hamishknight hamishknight merged commit 074ee9f into swiftlang:main Jan 27, 2022
@hamishknight hamishknight deleted the one-of-a-kind branch January 27, 2022 10:49
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.

3 participants