ruby / ruby/prettyprint

Formatting for a Ruby-like language

Open
#1 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
29
Forks
11
PR merge metrics
No merged PRs in 30d

Description

Hi,

I was about to implement Wadler's prettier printer, and I'm very happy to find that you already did that. Thanks for this.

I have a few questions:

  1. In a language such as Ruby where \n is meaningful, it's important to be able to emit a line break. I don't see how to do that with the current API. Am I missing something?

  2. Likewise, in Ruby in many places you can drop a separator when you are on a single line, or just do with a \n otherwise. For instance expressions in a block can be separated by ; , or \n (in which case the ; is useless). Or the then-part of an if can be on the same line with then, or simply separated with \n.
    I can't see a way to express that in the current api. I can see that this violates some invariants stated by Wadler ("As an invariant, we require in (x <|> y) that all layouts in x and y flatten to the same layout"), but I can't see how this invariant would break the correctness of the rendered layout. It does not break the second invariant, that appears to be more critical to get correct results ("we require that no first line of a document in x is shorter than some first line of a document in y; or, equivalently, that every first line in x is at least as long as every first line in y").

  3. What are the known uses of this library?

  4. I'd like to suggest to modify the documentation (I can provide a PR) which is misleading. It says in several places something like "By default, the class assumes that primitive elements are strings and each byte in the strings have single column in width". This is wrong: since the library uses str.length it does count the number of characters, not of bytes.

Cheers!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the current pretty-printing API and the documentation passages about primitive elements, then compare their description with the implementation's use of str.length. The documentation request is complete when the character-versus-byte behavior is accurately explained; the line-break and separator questions require maintainer clarification before implementation can be scoped.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.