arr-ai / arrai

The ultimate data engine.
http://arr.ai
Apache License 2.0
20 stars 15 forks source link

Pretty printer #511

Closed ericzhang6222 closed 4 years ago

ericzhang6222 commented 4 years ago

Fixes #171 .

Changes proposed in this pull request:

Checklist:

coveralls commented 4 years ago

Pull Request Test Coverage Report for Build 734ecd1e2bdb35a0b6104d6488ad4100a0707885-PR-511


Changes Missing Coverage Covered Lines Changed/Added Lines %
syntax/std_fmt.go 8 10 80.0%
syntax/format.go 75 88 85.23%
<!-- Total: 83 98 84.69% -->
Files with Coverage Reduction New Missed Lines %
syntax/import_cache.go 1 77.27%
rel/value_set_generic.go 2 74.47%
rel/value_set_str.go 6 60.23%
<!-- Total: 9 -->
Totals Coverage Status
Change from base Build e48178762c57f67f5ccfd3c330783a6fcfb5c785: 0.3%
Covered Lines: 4382
Relevant Lines: 9172

💛 - Coveralls
marcelocantos commented 4 years ago

(In a separate PR) relations should be formatted as tables, e.g.: for a "simple" table: {|a, b| (1, 2), (12, 13)}:

{|a , b |
 (1 , 2 ),
 (13, 14),
}

For a "complex" table, revert to set-of-tuples representation:

{
  (
    a: {1, 2},
    b: {3, 4},
  ),
  (
    a: {20, 30},
    b: {40, 50},
  ),
}
ericzhang6222 commented 4 years ago

Simple structures should be inlined. E.g., [1, 2, 3] should format as is.

There's no hard and fast rule for what constitutes "simple". As a bare minimum, inline any array or set (up to some threshold length) with only trivial elements (numbers, strings, byte arrays, (), {} and true).

The threshold could be fixed, or maybe a function of the current indent level.

Will do it in a separated PR. As @nofun97 want a MVP to help debugging ASAP, so I didn't do in this PR.