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

Improve pretty printing #618

Merged
merged 5 commits into from
Aug 14, 2019
Merged

Improve pretty printing #618

merged 5 commits into from
Aug 14, 2019

Conversation

rossberg
Copy link
Contributor

Various tweaks to our pretty printers:

  • Add a printNat function
  • Fix debug_show on empty arrays (would just show "]" before)
  • Allow to show at type None (otherwise e.g. empty arrays are rejected)
  • Print Word values in hex
  • Generally, unify output between the different printers (options, variants, numbers).
  • While there, remove decodeUTF8

Side note: we have as many as 4 implementations of pretty-printing for values: in value.ml, in show.ml, in coverage.ml, and in prelude.as. Sigh.

@rossberg rossberg requested a review from ggreif August 14, 2019 12:15
Copy link
Contributor

@ggreif ggreif left a comment

Choose a reason for hiding this comment

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

LGTM!

I have resurrected and fixed a roundtrip test. Please git pull before git rebase/merge! Thanks!

let i = Conv.of_signed_Word32 (as_word32 v)
in if i <= 0x10FFFF then k (Char i) else raise (Invalid_argument "codepoint out of bounds")
let i = Conv.int_of_word32_u (as_word32 v)
in if i < 0x110000 then k (Char i) else raise (Invalid_argument "character value out of bounds")
Copy link
Contributor

Choose a reason for hiding this comment

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

This will cause a conflict with master.

@@ -82,14 +81,6 @@ escape ch | '\\' `elem` show ch = "\\u{" <> hex (fromEnum ch) <> "}"
escape '"' = "\\\""
escape ch = pure ch

prop_charToText (UTF8 char) = monadicIO $ do
let testCase = "assert (switch (decodeUTF8 (charToText '"
Copy link
Contributor

Choose a reason for hiding this comment

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

I'll bring this test back soon (with t.chars().next()).

Copy link
Contributor

Choose a reason for hiding this comment

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

I am working on it, may land in the branch soon.

Copy link
Contributor

Choose a reason for hiding this comment

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

Done and pushed. Please pull before rebasing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool, thanks!

@ggreif ggreif mentioned this pull request Aug 14, 2019
@rossberg rossberg merged commit 5288dab into master Aug 14, 2019
@rossberg rossberg deleted the pretty branch August 14, 2019 16:07
@matthewhammer
Copy link
Contributor

Thanks for this!

dfinity-bot added a commit that referenced this pull request Feb 22, 2024
## Changelog for motoko-base:
Branch: next-moc
Commits: [dfinity/motoko-base@520ccf5d...712d0587](dfinity/motoko-base@520ccf5...712d058)

* [`cba05e81`](dfinity/motoko-base@cba05e8) Publish on Mops ([dfinity/motoko-base⁠#618](https://github.com/dfinity/motoko-base/issues/618))
* [`d81f5527`](dfinity/motoko-base@d81f552) Add commit hash to `matchers` dependency ([dfinity/motoko-base⁠#621](https://github.com/dfinity/motoko-base/issues/621))
* [`c86d76ff`](dfinity/motoko-base@c86d76f) doc: update `List.mo` ([dfinity/motoko-base⁠#616](https://github.com/dfinity/motoko-base/issues/616))
* [`4c2a90e7`](dfinity/motoko-base@4c2a90e) Fix compiler warning in `Array.take()` method ([dfinity/motoko-base⁠#611](https://github.com/dfinity/motoko-base/issues/611))
mergify bot pushed a commit that referenced this pull request Feb 22, 2024
## Changelog for motoko-base:
Branch: next-moc
Commits: [dfinity/motoko-base@520ccf5d...712d0587](dfinity/motoko-base@520ccf5...712d058)

* [`cba05e81`](dfinity/motoko-base@cba05e8) Publish on Mops ([dfinity/motoko-base⁠#618](https://github.com/dfinity/motoko-base/issues/618))
* [`d81f5527`](dfinity/motoko-base@d81f552) Add commit hash to `matchers` dependency ([dfinity/motoko-base⁠#621](https://github.com/dfinity/motoko-base/issues/621))
* [`c86d76ff`](dfinity/motoko-base@c86d76f) doc: update `List.mo` ([dfinity/motoko-base⁠#616](https://github.com/dfinity/motoko-base/issues/616))
* [`4c2a90e7`](dfinity/motoko-base@4c2a90e) Fix compiler warning in `Array.take()` method ([dfinity/motoko-base⁠#611](https://github.com/dfinity/motoko-base/issues/611))
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