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

feat: Add Cl.parse Clarity value parser #1681

Merged
merged 11 commits into from
Jun 17, 2024
Merged

feat: Add Cl.parse Clarity value parser #1681

merged 11 commits into from
Jun 17, 2024

Conversation

janniks
Copy link
Collaborator

@janniks janniks commented Apr 24, 2024

This PR was published to npm with the version 6.15.0
e.g. npm install @stacks/[email protected] --save-exact

  • Adds Cl.parse, which allows us to parse clarity syntax as JS representation ClarityValue.
  • Renames prettyPrint to stringify (matching JSON. more closely in naming) got feedback from users that they were expecting prettyPrint to console.log and they were confused that there wasn't any output.

Examples

Cl.parse(`"my string"`);
Cl.parse('-4');
Cl.parse('u5');
Cl.parse('false');
Cl.parse('{ a: 3 }');
Cl.parse('(list 1 2 3)');

Copy link

vercel bot commented Apr 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
stacksjs-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 13, 2024 6:03am

@janniks janniks changed the title draft: clarity value parser feat: Add Cl.parse clarity value parser Apr 30, 2024
@janniks janniks requested a review from hugocaillard May 6, 2024 06:51
@janniks janniks marked this pull request as ready for review May 6, 2024 06:56
@janniks janniks changed the title feat: Add Cl.parse clarity value parser feat: Add Cl.parse Clarity value parser May 6, 2024
Copy link
Contributor

@hugocaillard hugocaillard left a comment

Choose a reason for hiding this comment

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

I tried it and found this use case that throws a parse error:

{ a: 0x68656c6c6f21 }

packages/transactions/src/clarity/parser.ts Outdated Show resolved Hide resolved
@janniks
Copy link
Collaborator Author

janniks commented May 6, 2024

I tried it and found this use case that throws a parse error:

{ a: 0x68656c6c6f21 }

@hugocaillard Good catch, noticed that nested values will be tricky with overlaps. I thought the entire combinator solved this, but that's not used for the nested values.. 🙃 -- updated the order to fix this case, there might be more though..

In this case it was detecting the 0x.. as 0 matches an int, and will continue instead of trying other cl-values.

Copy link
Contributor

@hugocaillard hugocaillard left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@janniks janniks merged commit b9f8775 into main Jun 17, 2024
9 checks passed
@janniks janniks deleted the feat/clarity-parser branch June 17, 2024 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants