marcusaram / snakeyaml

Automatically exported from code.google.com/p/snakeyaml
Apache License 2.0
1 stars 0 forks source link

Enhancement: PRETTY formatter #53

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
This is an enhancement requests for a PRETTY format that combines BLOCK and 
FLOW. 

That is, it would look more like Java and less like Python by emitting {} like 
FLOW does, but 
indenting like BLOCK does. 

  Seems like that would be easier and more fool proof for people to edit. 

Original issue reported on code.google.com by obast...@gmail.com on 19 Feb 2010 at 4:32

GoogleCodeExporter commented 9 years ago
I did not quite catch you. Can you please give an example ?

(please keep in mind that the flow styles are part of the YAML specification)

Original comment by py4fun@gmail.com on 19 Feb 2010 at 5:00

GoogleCodeExporter commented 9 years ago
Sorry, meant to do that, but I have the flu. 

Instead of:

    creationDate: !!java.util.GregorianCalendar {time: !!timestamp '2010-02-19T16:59:37.895Z',
       timeInMillis: 1266598777895}

Output

    creationDate: !!java.util.GregorianCalendar {
           time: !!timestamp '2010-02-19T16:59:37.895Z',
           timeInMillis: 1266598777895
    }

I notice that that examples in the YAML spec tend to be written this way, with 
\n after the comments, and 
indentation similar to the block style. 

Original comment by obast...@gmail.com on 19 Feb 2010 at 5:12

GoogleCodeExporter commented 9 years ago
I am afraid I will not have time to implement it. Feel free to contribute the 
solution.

Original comment by aso...@gmail.com on 22 Feb 2010 at 12:45

GoogleCodeExporter commented 9 years ago
Ok, I'll look into it. 

Original comment by obast...@gmail.com on 22 Feb 2010 at 4:55

GoogleCodeExporter commented 9 years ago
So I looked into this. I found the Emitter code very confusing. 

The indentation is actually ok it seems, all I'm really asking for is to emit 
linebreaks after the '{', '}', and ',' in the 
folded style but I couldn't figure out how to do that. 

Could you give me a hint?

Original comment by obast...@gmail.com on 25 Feb 2010 at 4:47

GoogleCodeExporter commented 9 years ago
Emitter is a state machine with a stack of states to handle nested structures.

>all I'm really asking for is to emit linebreaks after the '{', '}', and ',' in 
the
folded style
It is not that simple. There are many things that influence the output. Check
expectFlowMapping(), ExpectFlowMappingKey.

Original comment by aso...@gmail.com on 25 Feb 2010 at 10:14

GoogleCodeExporter commented 9 years ago
Ah, thanks for the hint. 

I have a sample attached showing the result of turning "setPrettyFlow(true)" in 
the options. 

Tell me what you think, the next step is going through and revising all the 
test cases to make sure it can be read 
both ways. 

Original comment by obast...@gmail.com on 26 Feb 2010 at 4:44

Attachments:

GoogleCodeExporter commented 9 years ago
Looks cool !

A couple of questions:
1) why do timestamps have a tag ?
2) trailing ']' and '}' are missing
3) I think it is better to introduce one more flow style. Although I am not 
sure.

Original comment by aso...@gmail.com on 26 Feb 2010 at 8:16

GoogleCodeExporter commented 9 years ago
1. Because they're Gregorian Calendars?
2. They're there I just excerpted a much longer document.
3. Maybe. FLOW/BLOCK are very much a part of the yaml spec, but it seemed to 
make sense to have it as an 
option like canonical. 

Original comment by obast...@gmail.com on 27 Feb 2010 at 12:12

GoogleCodeExporter commented 9 years ago
I am looking forward to test your patch.

1. I am afraid it is a bug. Let's keep it separate.
2. Ok
3. Yes, let's use it in the same way as canonical

Original comment by aso...@gmail.com on 27 Feb 2010 at 9:18

GoogleCodeExporter commented 9 years ago
Ok, so I updated some unit tests to deal with pretty formatting here and there. 
It was somewhat selective. 

So what do I need to do to get the changes back to you?

Original comment by obast...@gmail.com on 3 Mar 2010 at 6:33

GoogleCodeExporter commented 9 years ago
Here's a total guess, I did hg diff and saved the output. 

Original comment by obast...@gmail.com on 3 Mar 2010 at 7:41

Attachments:

GoogleCodeExporter commented 9 years ago
1) create a Mercurial clone and push your changes there
(http://code.google.com/p/snakeyaml/source/clones)
2) hg diff > patch.txt
3) zip and attach here the src folder

Original comment by aso...@gmail.com on 3 Mar 2010 at 7:50

GoogleCodeExporter commented 9 years ago
Thank you. Your patch it taken. Check the latest source.

It will be released in version 1.7

Original comment by aso...@gmail.com on 3 Mar 2010 at 8:21

GoogleCodeExporter commented 9 years ago
Since 'prettyFlow' and 'canonical' formats are mutually exclusive shall we 
reflect it 
in the interface ?
May be instead of setters we should make one method 
DumperOptions.setFormat(Enum) ?
The possible values for enum are:
- Standard (default)
- Canonical
- FlowNewLine (I do not have a good name)

Original comment by py4fun@gmail.com on 4 Mar 2010 at 8:33

GoogleCodeExporter commented 9 years ago
I have found a place in Emitter.ExpectFirstFlowSequenceItem which was 
introduced by 
this issue and not covered by tests.
Can you please provide a test to check it works as expected ?
You can run 'mvn clean site' to generate coverage report.

Original comment by py4fun@gmail.com on 4 Mar 2010 at 3:47

Attachments:

GoogleCodeExporter commented 9 years ago
comment 15:

They're not quite mutually exclusive, as you can see in the coverage for 16. 
canonical tends to put in the 
exact same line breaks, but as you can see in this case (empty sequence) 
prettyFlow is putting in an extra one. 

comment 16:

Ok, so if I'm reading this right, this is the [ ] case. 

Hmmm... I wonder if I should do that, or if I should take out the if 
(prettyFlow) here and in 
ExpectFirstFlowMappingItem, so that it outputs {} and [] instead of
{

}

and

[

]

What do you think?

Original comment by obast...@gmail.com on 4 Mar 2010 at 5:19

GoogleCodeExporter commented 9 years ago
Just tried this, the right answer is to remove the if (prettyFlow) for these 
"first" cases. Right now it writes
   {

  }

When:
   {

 }

Is "prettier"

I'll send you a patch in a moment. 

Original comment by obast...@gmail.com on 4 Mar 2010 at 5:34

GoogleCodeExporter commented 9 years ago
Just tried this, the right answer is to remove the if (prettyFlow) for these 
"first" cases. Right now it writes
   {

  }

When:
   {
 }

Is "prettier"

Here's the patch. 

Original comment by obast...@gmail.com on 4 Mar 2010 at 5:39

Attachments:

GoogleCodeExporter commented 9 years ago
The patch is taken.
Since they are not mutually exclusive let us leave it as it is now.

Original comment by py4fun@gmail.com on 4 Mar 2010 at 6:47