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

Add documentation for JSON AST #2343

Open
Tracked by #959
Hexi1997 opened this issue Feb 23, 2023 · 4 comments
Open
Tracked by #959

Add documentation for JSON AST #2343

Hexi1997 opened this issue Feb 23, 2023 · 4 comments
Labels
Documentation Improvements or additions to documentation Feedback

Comments

@Hexi1997
Copy link

Issue to be solved

Add doc for cadence-parser

Suggested Solution

No response

@turbolent
Copy link
Member

Could you please describe what kind of documentation you need for the package?

You can see an example usage in the tests: https://github.com/onflow/cadence/blob/master/npm-packages/cadence-parser/tests/index.test.ts#L5-L7

@turbolent turbolent added Documentation Improvements or additions to documentation and removed Feature labels Feb 27, 2023
@turbolent turbolent removed their assignment Feb 27, 2023
@Hexi1997
Copy link
Author

Could you please describe what kind of documentation you need for the package?

You can see an example usage in the tests: https://github.com/onflow/cadence/blob/master/npm-packages/cadence-parser/tests/index.test.ts#L5-L7

ok, my statement may not be very clear, I mean a doc like https://solidity-ast.netlify.app/
image

Perhaps the type of ast is more accurate!

@turbolent turbolent changed the title Add doc for cadence-parser Add documentation for JSON AST Feb 28, 2023
@turbolent
Copy link
Member

I see, thanks for clarifying. We do not have documentation for the JSON encoding of the AST element types yet, but you can maybe just look at the Go type definitions for now, they should be fairly self-explanatory.

You can find all AST element type definitions in the runtime/ast package: https://github.com/onflow/cadence/tree/master/runtime/ast. For example, the binary expression element type is defined here:

type BinaryExpression struct {
Left Expression
Right Expression
Operation Operation
}

All element types have a MarshalJSON function that implements how the element is encoded to JSON, e.g.:
func (e *BinaryExpression) MarshalJSON() ([]byte, error) {
type Alias BinaryExpression
return json.Marshal(&struct {
*Alias
Type string
Range
}{
Type: "BinaryExpression",
Range: NewUnmeteredRangeFromPositioned(e),
Alias: (*Alias)(e),
})
}

@turbolent
Copy link
Member

turbolent commented Feb 28, 2023

In addition, we have an AST explorer tool that lets you write Cadence code and inspect the AST: https://github.com/onflow/cadence/tree/master/tools/astexplorer

@j1010001 j1010001 mentioned this issue Apr 18, 2023
36 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Improvements or additions to documentation Feedback
Projects
None yet
Development

No branches or pull requests

2 participants