Conversation
🦋 Changeset detectedLatest commit: a6d9180 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
crates/solidity/outputs/npm/package/src/ast/generated/frontend.ts
Outdated
Show resolved
Hide resolved
crates/solidity/outputs/npm/package/src/ast/generated/frontend.ts
Outdated
Show resolved
Hide resolved
Xanewok
left a comment
There was a problem hiding this comment.
Initial pass, I'll come back to this later. Overall, it's great to see that land soon; good job!
|
I like the proposed naming!
…On Thu, 21 Dec 2023 at 11:32, Omar Tawfik ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In crates/codegen/parser/generator/src/code_generator.rs
<#719 (comment)>
:
> @@ -62,6 +63,18 @@ impl CodeGenerator {
CargoWorkspace::locate_source_crate("codegen_parser_runtime")?.join("src");
let mut codegen = Codegen::read_write(&runtime_dir)?;
+ {
+ #[derive(Serialize)]
+ pub struct Template<'a> {
+ pub ast_types: &'a AstTypes,
+ }
+ codegen.render(
+ Template { ast_types },
+ runtime_dir.join("napi/templates/ast_backend.rs.jinja2"),
+ output_dir.join("napi/napi_ast_backend.rs"),
I can change to:
- ast_model.rs for the codegen model builder
- ast_selectors instead of the backend
- ast_types for the front end
WDYT?
—
Reply to this email directly, view it on GitHub
<#719 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAXTFXNABXX2OU4PBFPGEADYKQF3NAVCNFSM6AAAAABA5AFGQCVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTOOJSGY4TMNRSHE>
.
You are receiving this because your review was requested.Message ID:
***@***.***>
|
|
Agreed on Q1 and module split; this will only get unnecessarily complicated
down the line if we don’t restructure it 👍
…On Thu, 21 Dec 2023 at 11:29, Omar Tawfik ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In crates/codegen/parser/generator/src/ast.rs
<#719 (comment)>
:
> @@ -0,0 +1,298 @@
+use codegen_language_definition::model;
+use indexmap::{IndexMap, IndexSet};
+use itertools::Itertools;
+use serde::Serialize;
+
+#[derive(Default, Serialize)]
+pub struct AstTypes {
Sure. Happy to rename.
Re: module organization: I think this is related to the bigger issue, of
having a monolith codegen step that is tied to both rust/typescript.
I suggest we dedicate some time in Q1 to figure out a better way to
organize this pipeline.
—
Reply to this email directly, view it on GitHub
<#719 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAXTFXM2K4JYKI4RYGPEWM3YKQFPRAVCNFSM6AAAAABA5AFGQCVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTOOJSGY4TCNZWGY>
.
You are receiving this because your review was requested.Message ID:
***@***.***>
|
d654844 to
f053b06
Compare
f053b06 to
57a9930
Compare
57a9930 to
a6d9180
Compare
Xanewok
left a comment
There was a problem hiding this comment.
I'm excited to finally have the AST types, great job 🎉 I left some comments for the doc example and for the frontend/backend distinction. Also, it'd be great to clean up a bit the codegen pipeline since it's getting messy but we decided to punt that to Q1.
I understand we have a holiday season now and so there's some time pressure, so I don't want to block this now; we can address further feedback separately/later in Q1.
Quite a holiday gift; happy holidays and again, great job 🎉
| )?; | ||
|
|
||
| CodeGenerator::write_source(&crate_dir.join("src/generated"), &grammar)?; | ||
| CodeGenerator::write_frontend( |
There was a problem hiding this comment.
I'd like to change the backend/frontend naming here as well since it's slightly confusing, but let's do that in a follow-up.
|
|
||
| #[derive(Debug, thiserror::Error)] | ||
| enum Error { | ||
| // Should not theoritically happen, since we're only called from our own generated AST types. |
There was a problem hiding this comment.
| // Should not theoritically happen, since we're only called from our own generated AST types. | |
| // Should not theoretically happen, since we're only called from our own generated AST types. |
| #[error("Unexpected parent node with RuleKind '{0}'.")] | ||
| UnexpectedParent(RuleKind), | ||
|
|
||
| // Should not theoritically happen, since we're only called from our own generated AST types. |
There was a problem hiding this comment.
| // Should not theoritically happen, since we're only called from our own generated AST types. | |
| // Should not theoretically happen, since we're only called from our own generated AST types. |
| #[error("Unexpected trailing children at index '{0}'.")] | ||
| UnexpectedTrailing(usize), | ||
|
|
||
| // Should not theoritically happen, unless AST error recovery was changed. |
There was a problem hiding this comment.
| // Should not theoritically happen, unless AST error recovery was changed. | |
| // Should not theoretically happen, unless AST error recovery was changed. |
| Ok(None) | ||
| } | ||
|
|
||
| fn finalize(&mut self) -> Result<()> { |
There was a problem hiding this comment.
nit: If I understand the intent correctly, this should probably consume the type with self to better express intent/disallow calling twice
| ``` | ||
|
|
||
| ### Example 2: List the top-level contracts and their names | ||
| ### Example 2: Reading Contracts using Cursors |
There was a problem hiding this comment.
Saying we "read" them in this example is, I feel like, a bit too generous - we're only fetching the name, which is a direct token child of the encompassing rule. It'd be better if we had some more examples on how to practically read the contracts (listing public/external functions, errors etc.) and use that wording there
There was a problem hiding this comment.
also I feel that "contracts" should be lower case since it refers to contracts generally; Cursor is okay since it's the Cursor API/structs we expose
| The `Cursor` type provides procedural-style functions that allow you to navigate the source in a step-by-step manner. In addition to `goToNext`, we can go to the parent, first child, next sibling, etc., as well as nodes with a given kind. | ||
|
|
||
| To list the top-level contracts and their names, we need to visit the `ContractDefinition` rule nodes and then their `Identifier` children. | ||
| Let's start with this piece of solidity source code: |
There was a problem hiding this comment.
| Let's start with this piece of solidity source code: | |
| Let's start with this piece of Solidity source code: |
|
|
||
| AST types are a set of TypeScript classes that provide a typed view of the untyped CST nodes. | ||
| You can convert any untyped CST node to its corresponding AST type using their constructors. | ||
| AST types are immutable, and are constructed on the fly, as they are used/accessed for the first time. |
There was a problem hiding this comment.
| AST types are immutable, and are constructed on the fly, as they are used/accessed for the first time. | |
| AST types are immutable and are constructed on the fly as they are used/accessed for the first time. |
small suggestion: Maybe "lazily" would fit better instead of "on the fly"? Seems like it would be more intuitive for the (programming) reader.
- address later feedback on NomicFoundation#719 - fix syntax highlighting for TS templates - use `ReadonlyArray<T>` in return types instead of `Array<T>`. - use `undefined` instead of `null` for optional fields, as it is more idiomatic.
- address later feedback on #719 - fix syntax highlighting for TS templates - use `ReadonlyArray<T>` in return types instead of `Array<T>`. - use `undefined` instead of `null` for optional fields, as it is more idiomatic.
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and publish to npm yourself or [setup this action to publish automatically](https://github.com/changesets/action#with-publishing). If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @nomicfoundation/slang@0.13.0 ### Minor Changes - [#710](#710) [`2025b6cb`](2025b6c) Thanks [@Xanewok](https://github.com/Xanewok)! - CST children nodes are now named - [#723](#723) [`b3dc6bcd`](b3dc6bc) Thanks [@Xanewok](https://github.com/Xanewok)! - Properly parse unreserved keywords in an identifier position, i.e. `from`, `emit`, `global` etc. - [#728](#728) [`662a672c`](662a672) Thanks [@Xanewok](https://github.com/Xanewok)! - Remove Language#scan API; use the parser API instead - [#719](#719) [`1ad6bb37`](1ad6bb3) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - introduce strong types for all Solidity non terminals in the TypeScript API. ### Patch Changes - [#719](#719) [`1ad6bb37`](1ad6bb3) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - unify Rust/TypeScript node helpers: `*_with_kind()`, `*_with_kinds()`, `*_is_kind()`), ... - [#731](#731) [`3deaea2e`](3deaea2) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - add `RuleNode.unparse()` to the TypeScript API Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and publish to npm yourself or [setup this action to publish automatically](https://github.com/changesets/action#with-publishing). If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @nomicfoundation/slang@0.13.0 ### Minor Changes - [#710](NomicFoundation/slang#710) [`2025b6cb`](NomicFoundation/slang@2025b6c) Thanks [@Xanewok](https://github.com/Xanewok)! - CST children nodes are now named - [#723](NomicFoundation/slang#723) [`b3dc6bcd`](NomicFoundation/slang@b3dc6bc) Thanks [@Xanewok](https://github.com/Xanewok)! - Properly parse unreserved keywords in an identifier position, i.e. `from`, `emit`, `global` etc. - [#728](NomicFoundation/slang#728) [`662a672c`](NomicFoundation/slang@662a672) Thanks [@Xanewok](https://github.com/Xanewok)! - Remove Language#scan API; use the parser API instead - [#719](NomicFoundation/slang#719) [`1ad6bb37`](NomicFoundation/slang@1ad6bb3) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - introduce strong types for all Solidity non terminals in the TypeScript API. ### Patch Changes - [#719](NomicFoundation/slang#719) [`1ad6bb37`](NomicFoundation/slang@1ad6bb3) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - unify Rust/TypeScript node helpers: `*_with_kind()`, `*_with_kinds()`, `*_is_kind()`), ... - [#731](NomicFoundation/slang#731) [`3deaea2e`](NomicFoundation/slang@3deaea2) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - add `RuleNode.unparse()` to the TypeScript API Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Adds TypeScript AST types, and some initial tests. Additionally:
Itemto be an enum ofRc<>variants, instead of anRc<>to an enum, to make it easier to clone/store individual variants separately.*_with_kind(),*_with_kinds(),*_is_kind()), ...