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

Added the ability to dump the token stream or ast in bin. #278

Merged
merged 8 commits into from Mar 25, 2020

Conversation

HalidOdat
Copy link
Member

The dump functionality works both for files and REPL.

With --dump-tokens or -t for short it dumps the token stream to stdout and --dump-ast or -a for short to dump the ast to stdout.

The dumping of tokens and ast is mutually exclusive and when dumping it wont run the code.

The dump functionality works both for files and REPL.

With --dump-tokens or -t for short it dumps the token stream to stdout  and --dump-ast or -a for short to dump the ast to stdout.

The dumping of tokens and ast is mutually exclusive. and when dumping it wont run the code.
@HalidOdat HalidOdat mentioned this pull request Mar 17, 2020
@Razican
Copy link
Member

Razican commented Mar 17, 2020

Seems nice, maybe it would be interesting to print tokes/ast in a given format (JSON for example) in order for other tools to analyze it?

@HalidOdat
Copy link
Member Author

Hmmm. That seems like a really nice idea. Thanks 👍

- Changed the --dump-tokens and --dump-ast to be an optional argument that optionally takes a value of format type ([--opt=[val]]).
- The default format for --dump-tokens and --dump-ast is Debug format which calls std::fmt::Debug.
- Added Json and JsonMinified format for both dumps,  use serde_json internally.
- It is easy to support other format types, such as Toml with toml-rs for example.
@HalidOdat
Copy link
Member Author

HalidOdat commented Mar 18, 2020

With the last commit 84d4105, I changed --dump-tokens and --dump-ast to optionally take a format type, by default it is Debug format which internally uses the std::fmt::Debug trait. But you can change it by providing a format type like: Debug, Json, JsonMinified. The input value is case insensitive.

Example:

cargo run -- test.js --dump-tokens #=Debug 

or

cargo run -- test.js --dump-tokens=Json # pretty printed json.

or

cargo run -- test.js --dump-tokens=JsonMinified # minified json.

Its the same with --dump-ast.

@jasonwilliams
Copy link
Member

This looks great @HalidOdat i will take a proper look soon but no issues so far

@Razican
Copy link
Member

Razican commented Mar 18, 2020

It looks great, yes! Maybe the serde dependency could be an optional dependency in the lib, maybe behind a feature flag? This would reduce the dependency list for users of the lib that don't need the JSON representation.

And I would say that if we want output in JSON, it should be minified by default, with the option to make it pretty if desired.

@HalidOdat
Copy link
Member Author

Thanks for the input. I will see what I can do.

- Serde serialization and deserialization can be switched on by using the feature flag "serde-ast".
- Now Json  dumping format prints the data in minefied JSON form by default.
- Removed JsonMinified.
- Added JsonPretty as a way to dump the data in pretty printed JSON format.
@HalidOdat
Copy link
Member Author

With this commit 8a34176, I made serde serialization and deserialization to be a feature of boa library it can be activated with the feature flag serde-ast.

And with this commit 96c74ae, I changed Json format to be minified by default. Removed the JsonMineified format and added JsonPretty, which as the name implies it dumps with pretty print JSON format.

@Razican
Copy link
Member

Razican commented Mar 18, 2020

Looks perfect to me, great job!

@HalidOdat
Copy link
Member Author

Thanks!

@jasonwilliams
Copy link
Member

Maybe we can get this in before the parser change then rebase the parser branch on top of this?

@HalidOdat
Copy link
Member Author

I think so, too.

@jasonwilliams jasonwilliams merged commit 5a85c59 into boa-dev:master Mar 25, 2020
@HalidOdat HalidOdat deleted the better-bin branch April 13, 2020 19:40
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.

None yet

3 participants