Coder Social home page Coder Social logo

yaml.jl's Introduction

YAML

CI codecov

YAML is a flexible data serialization format that is designed to be easily read and written by human beings.

This library parses YAML documents into native Julia types and dumps them back into YAML documents.

Synopsis

For most purposes there is one important function: YAML.load, which takes a string and parses it the first YAML document it finds.

To parse a file use YAML.load_file, and to parse every document in a file use YAML.load_all or YAML.load_all_file.

Given a YAML document like the following

receipt:     Oz-Ware Purchase Invoice
date:        2012-08-06
customer:
    given:   Dorothy
    family:  Gale

items:
    - part_no:   A4786
      descrip:   Water Bucket (Filled)
      price:     1.47
      quantity:  4

    - part_no:   E1628
      descrip:   High Heeled "Ruby" Slippers
      size:      8
      price:     100.27
      quantity:  1

bill-to:  &id001
    street: |
            123 Tornado Alley
            Suite 16
    city:   East Centerville
    state:  KS

ship-to:  *id001

specialDelivery:  >
    Follow the Yellow Brick
    Road to the Emerald City.
    Pay no attention to the
    man behind the curtain.

It can be loaded with

import YAML
data = YAML.load_file("test.yml")
println(data)

Which will show you something like this.

{"date"=>Aug 6, 2012 12:00:00 AM PDT,"ship-to"=>{"street"=>"123 Tornado Alley\nSuite 16\n","state"=>"KS","city"=>"East Centerville"},"customer"=>{"given"=>"Dorothy","family"=>"Gale"},"specialDelivery"=>"Follow the Yellow Brick\nRoad to the Emerald City.\nPay no attention to the\nman behind the curtain.\n","items"=>{{"price"=>1.47,"descrip"=>"Water Bucket (Filled)","part_no"=>"A4786","quantity"=>4}  …  {"price"=>100.27,"size"=>8,"descrip"=>"High Heeled \"Ruby\" Slippers","part_no"=>"E1628","quantity"=>1}},"bill-to"=>{"street"=>"123 Tornado Alley\nSuite 16\n","state"=>"KS","city"=>"East Centerville"},"receipt"=>"Oz-Ware Purchase Invoice"}

Note that ints and floats are recognized, as well as timestamps which are parsed into CalendarTime objects. Also, anchors and references work as expected, without making a copy.

Dictionaries are parsed into instances of Dict{Any,Any} by default. You can, however, specify a custom type in which to parse all dictionaries.

# using Symbol keys
data = YAML.load_file("test.yml"; dicttype=Dict{Symbol,Any})

# maintaining the order from the YAML file
using OrderedCollections
data = YAML.load_file("test.yml"; dicttype=OrderedDict{String,Any})

# specifying a default value
using DataStructures
data = YAML.load_file("test.yml"; dicttype=()->DefaultDict{String,Any}(Missing))

Writing to YAML

Similar to reading files, you can emit Julia objects to YAML files by calling write_file, or to a string object by calling write.

For example, you can reproduce the above file from the variable data

import YAML
YAML.write_file("test-output.yml", data)

which gives you (omitting the precise format but maintaining the content)

receipt: "Oz-Ware Purchase Invoice"
items:
  - part_no: "A4786"
    price: 1.47
    descrip: "Water Bucket (Filled)"
    quantity: 4
  - part_no: "E1628"
    price: 100.27
    size: 8
    descrip: "High Heeled "Ruby" Slippers"
    quantity: 1
customer:
  given: "Dorothy"
  family: "Gale"
ship-to:
  city: "East Centerville"
  street: |
      123 Tornado Alley
      Suite 16

  state: "KS"
bill-to:
  city: "East Centerville"
  street: |
      123 Tornado Alley
      Suite 16

  state: "KS"
specialDelivery: |
    Follow the Yellow Brick Road to the Emerald City. Pay no attention to the man behind the curtain.

date: 2012-08-06

Not yet implemented

  • When writing YAML files, you cannot use additional constructors like you can when reading.
  • Parsing sexigesimal numbers.
  • Fractions of seconds in timestamps.
  • Specific time-zone offsets in timestamps.
  • Application specific tags.

yaml.jl's People

Contributors

00vareladavid avatar bjarthur avatar carlolucibello avatar christopher-dg avatar dbeach24 avatar dcjones avatar ghyatzo avatar github-actions[bot] avatar gunnarfarneback avatar hexane360 avatar iainnz avatar jdlangs avatar jmkuhn avatar kescobo avatar mirkobunse avatar mlhetland avatar nico202 avatar nlw0 avatar omus avatar philreinhold avatar programmeroftheeve avatar quinnj avatar randyzwitch avatar rawlik avatar rikhuijzer avatar sawcordwell avatar sglyon avatar tanmaykm avatar yuyichao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yaml.jl's Issues

Support for boolean

does not support yaml "Yes"/"No" boolean True/False,
results in an ASCIIString instead

mork not defined

This was a pretty funny error message to receive

mork not defined
while loading In[6], in expression starting on line 3
 in process_empty_scalar at /Users/randyzwitch/.julia/YAML/src/parser.jl:578
 in parse_block_mapping_value at /Users/randyzwitch/.julia/YAML/src/parser.jl:424
 in next_event at /Users/randyzwitch/.julia/YAML/src/parser.jl:67
 in parse at /Users/randyzwitch/.julia/YAML/src/parser.jl:42
 in anonymous at /Users/randyzwitch/.julia/LazySequences/src/LazySequences.jl:102
 in seq at /Users/randyzwitch/.julia/LazySequences/src/LazySequences.jl:97
 in rest at /Users/randyzwitch/.julia/LazySequences/src/LazySequences.jl:31
 in pop_event at /Users/randyzwitch/.julia/YAML/src/composer.jl:30
 in compose_scalar_node at /Users/randyzwitch/.julia/YAML/src/composer.jl:94
 in compose_node at /Users/randyzwitch/.julia/YAML/src/composer.jl:82
 in compose_mapping_node at /Users/randyzwitch/.julia/YAML/src/composer.jl:153
 in compose_node at /Users/randyzwitch/.julia/YAML/src/composer.jl:82
 in compose_sequence_node at /Users/randyzwitch/.julia/YAML/src/composer.jl:127
 in compose_node at /Users/randyzwitch/.julia/YAML/src/composer.jl:82
 in compose_mapping_node at /Users/randyzwitch/.julia/YAML/src/composer.jl:154
 in compose_node at /Users/randyzwitch/.julia/YAML/src/composer.jl:82
 in compose_document at /Users/randyzwitch/.julia/YAML/src/composer.jl:50
 in compose at /Users/randyzwitch/.julia/YAML/src/composer.jl:38
 in load at /Users/randyzwitch/.julia/YAML/src/YAML.jl:21

What is this function supposed to do? Can mork be removed from the function signature or is it supposed to represent something?

function process_empty_scalar(stream::EventStream, mark::Mark)
    ScalarEvent(mork, mark, nothing, nothing, (true, false), "")
end

write_all_file for emitting?

This would basically be the companion to read_all and read_all_file. As far as I can tell it would be a pretty simple modification to add write_all_file accepting an Array{Any, 1} and just iterate over the array through the normal functions, adding begin/end document markers as necessary.

I can add this functionality if it hasn't already been implemented?

error parsing w/o leading space

according to two different online validators, both of the below YAML strings below are valid, yet YAML.jl is not able to parse the first one, which differs only by a single leading space before the hyphen on the last line.

julia> YAML.load("--- 
       path: /foo
       tiles: 
       - path: /bar")
ERROR: type EventStream has no field span
 in parse_node at /home/arthurb/.julia/v0.3/YAML/src/parser.jl:278
 in parse_block_mapping_value at /home/arthurb/.julia/v0.3/YAML/src/parser.jl:421
 in next_event at /home/arthurb/.julia/v0.3/YAML/src/parser.jl:67
 in parse at /home/arthurb/.julia/v0.3/YAML/src/parser.jl:42
 in anonymous at /home/arthurb/.julia/v0.3/LazySequences/src/LazySequences.jl:102
 in seq at /home/arthurb/.julia/v0.3/LazySequences/src/LazySequences.jl:97
 in rest at /home/arthurb/.julia/v0.3/LazySequences/src/LazySequences.jl:31
 in compose_scalar_node at /home/arthurb/.julia/v0.3/YAML/src/composer.jl:94
 in compose_node at /home/arthurb/.julia/v0.3/YAML/src/composer.jl:82
 in compose_mapping_node at /home/arthurb/.julia/v0.3/YAML/src/composer.jl:153
 in compose_node at /home/arthurb/.julia/v0.3/YAML/src/composer.jl:82
 in compose_document at /home/arthurb/.julia/v0.3/YAML/src/composer.jl:50
 in compose at /home/arthurb/.julia/v0.3/YAML/src/composer.jl:38
 in load at /home/arthurb/.julia/v0.3/YAML/src/YAML.jl:21
 in load at /home/arthurb/.julia/v0.3/YAML/src/YAML.jl:40

julia> YAML.load("--- 
       path: /foo
       tiles: 
        - path: /bar")
Dict{Any,Any} with 2 entries:
  "tiles" => {{"path"=>"/bar"}}
  "path"  => "/foo"

julia> Pkg.installed()
Dict{ASCIIString,VersionNumber} with 5 entries:
  "Dates"         => v"0.3.2"
  "YAML"          => v"0.1.7+"
  "Codecs"        => v"0.1.2"
  "Debug"         => v"0.0.4"
  "LazySequences" => v"0.1.0"

julia> VERSION
v"0.3.3"

scan_flow_scalar_breaks

When parsing a valid yaml, i get:
ERROR: MethodError: no method matching scan_flow_scalar_breaks(::Bool, ::YAML.Mark)

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

Error when loading "{x: 1, y: 2}"

I am running into an issue loading some YAML that works with python's YAML:

julia> import PyCall
julia> import YAML
julia> @PyCall.pyimport yaml
julia> yaml.load("{x: 1, y: 2}")
Dict{Any,Any} with 2 entries:
  "x" => 1
  "y" => 2
julia> YAML.load("{x: 1, y: 2}")
ERROR: type Void has no field next
 in enqueue! at /homedir/.julia/v0.4/YAML/src/queue.jl:60
 in fetch_value at /homedir/.julia/v0.4/YAML/src/scanner.jl:579
 in fetch_more_tokens at /homedir/.julia/v0.4/YAML/src/scanner.jl:197
 in peek at /homedir/.julia/v0.4/YAML/src/scanner.jl:149
 in parse_implicit_document_start at /homedir/.julia/v0.4/YAML/src/parser.jl:132
 in forward! at /homedir/.julia/v0.4/YAML/src/parser.jl:66
 in compose_document at /homedir/.julia/v0.4/YAML/src/composer.jl:42
 in compose at /homedir/.julia/v0.4/YAML/src/composer.jl:31
 in load at /homedir/.julia/v0.4/YAML/src/YAML.jl:70

Should this work? I am using julia 0.4.3 with YAML.jl 0.1.10.

New release

I would be useful with a new release so that the improvements from #48 and #64 can be enjoyed out of the box.

BUG: incorrect line numbering for windows files

When trying to implement a linter using YAML.jl, @ezgioz found an inconsistency in the line numbering when importing a file under windows (I think we discussed it with @sglyon a while ago). The bug can be replicated using the following code:

julia> s1 = "a: [1,2,3]\nb: [4,5,6]\nc: [7,8,9]\n"
"a: [1,2,3]\nb: [4,5,6]\nc: [7,8,9]\n"

julia> s2 = "a: [1,2,3]\r\nb: [4,5,6]\r\nc: [7,8,9]\r\n"
"a: [1,2,3]\r\nb: [4,5,6]\r\nc: [7,8,9]\r\n"

julia> yml_types = Dict{AbstractString,Function}("tag:yaml.org,2002:seq"=>((c,n)->println(n.start_mark)))
Dict{AbstractString,Function} with 1 entry:
  "tag:yaml.org,2002:seq" => #1

julia> YAML.load(s1, yml_types)
line 1, column 3
line 2, column 3
line 3, column 3
Dict{Any,Any} with 3 entries:
  "c" => nothing
  "b" => nothing
  "a" => nothing

julia> YAML.load(s2, yml_types)
line 1, column 3
line 3, column 3
line 5, column 3
Dict{Any,Any} with 3 entries:
  "c" => nothing
  "b" => nothing
  "a" => nothing

End of lines, are counted twice. Apparently, on windows, switching end-of-line conventions (by replacing \r\n by \n) fixes the problem.

I suspect the incorrect count comes from this line https://github.com/dcjones/YAML.jl/blob/master/src/scanner.jl#L128

if in(c, "\n\u0085\u2028\u2029") ||
     (c == '\r' && peek(stream.input) == '\n')
      stream.column = 0
      stream.line += 1

Replacing the condition by:

if in(c, "\n\u0085\u2028\u2029") ||
     (c == '\r' && peek(stream.input) == '\n')

seems to fix the problem, but I wouldn't swear there are no side effects since, the scanner.jl file seems to metnion the \r quite often.

String values with double quotes are serialized unescaped

julia> s = """quotes "are not" escaped"""
"quotes \"are not\" escaped"

julia> YAML.write_file("foo.yml", Dict("ahhhh" => s))

shell> cat foo.yml
ahhhh: "quotes "are not" escaped"

julia> YAML.load_file("foo.yml")
ERROR: while parsing a block mapping at line 1, column 0: expected <block end>, but found YAML.ScalarToken at line 1, column 16
Stacktrace:
 [1] parse_block_mapping_key(::YAML.EventStream) at /home/degraafc/.local/share/julia/packages/YAML/aMmWk/src/parser.jl:434
 [2] peek(::YAML.EventStream) at /home/degraafc/.local/share/julia/packages/YAML/aMmWk/src/parser.jl:54
 [3] _compose_mapping_node(::YAML.MappingStartEvent, ::YAML.Composer, ::Nothing) at /home/degraafc/.local/share/julia/packages/YAML/aMmWk/src/composer.jl:174
 [4] compose_mapping_node(::YAML.Composer, ::Nothing) at /home/degraafc/.local/share/julia/packages/YAML/aMmWk/src/composer.jl:184
 [5] handle_event(::YAML.MappingStartEvent, ::YAML.Composer) at /home/degraafc/.local/share/julia/packages/YAML/aMmWk/src/composer.jl:86
 [6] compose_node(::YAML.Composer) at /home/degraafc/.local/share/julia/packages/YAML/aMmWk/src/composer.jl:94
 [7] compose_document(::YAML.Composer) at /home/degraafc/.local/share/julia/packages/YAML/aMmWk/src/composer.jl:50
 [8] compose(::YAML.EventStream) at /home/degraafc/.local/share/julia/packages/YAML/aMmWk/src/composer.jl:38
 [9] load(::YAML.TokenStream, ::Nothing; dicttype::Type{Dict{Any,Any}}) at /home/degraafc/.local/share/julia/packages/YAML/aMmWk/src/YAML.jl:22
 [10] load at /home/degraafc/.local/share/julia/packages/YAML/aMmWk/src/YAML.jl:22 [inlined]
 [11] #load#10 at /home/degraafc/.local/share/julia/packages/YAML/aMmWk/src/YAML.jl:40 [inlined]
 [12] load at /home/degraafc/.local/share/julia/packages/YAML/aMmWk/src/YAML.jl:40 [inlined]
 [13] #17 at /home/degraafc/.local/share/julia/packages/YAML/aMmWk/src/YAML.jl:87 [inlined]
 [14] open(::YAML.var"#17#18"{Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},Nothing}, ::String, ::Vararg{String,N} where N; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at ./io.jl:325
 [15] open at ./io.jl:323 [inlined]
 [16] #load_file#16 at /home/degraafc/.local/share/julia/packages/YAML/aMmWk/src/YAML.jl:85 [inlined]
 [17] load_file at /home/degraafc/.local/share/julia/packages/YAML/aMmWk/src/YAML.jl:85 [inlined] (repeats 2 times)
 [18] top-level scope at REPL[14]:1

This problem goes away if the string has a newline in it, because then it gets put into a | string.

Terminate document with '...'

As discussed in #95, ending a file with multiple newlines can be error-prone (it's easy to accidentally strip them).
One way to get around this is to explicitly end the YAML document with ... (ref). That way there's only ever one trailing newline.

Another option would be to only do this if the file actually does end in a multiline string with trailing newlines (this is pretty rare, generally). The only thing I can think of being difficult for that is that not all ios let you see what you printed to them in the past.

Personally I think we should just always put the ..., since it ensures correctness. If people wanted their YAMLs to look exactly how they wanted, they'd probably be writing them by hand.

horrific performance

i've got a 90MB yaml file with 22000 entries. it takes only 4.2 seconds to parse with a custom C library. with YAML.jl it takes 176 seconds. and yes, this is the second time around.

julia's profiler says the bulk of the time is spent in composer.jl/compose_node(), and @code_warntype shows a handful of type instabilities therein. search for Union{Type{Nothing}, ...}, ::Any, and ::YAML.Node in the REPL snippet below.

i'm wondering whether making a NothingEvent would help.

julia> @code_warntype YAML.compose_node(composer, nothing, nothing)
Body::Union{Nothing, Node}
59 1 ── %1   = (Base.getfield)(composer, :input)::YAML.EventStream                 │╻ getproperty
   │    %2   = invoke YAML.peek(%1::YAML.EventStream)::Union{Nothing, Event}       │ 
60 │    %3   = (YAML.typeof)(%2)::Union{Type{Nothing}, Type{#s55} where #s55<:Event} 
   │    %4   = YAML.AliasEvent::Core.Compiler.Const(YAML.AliasEvent, false)        │ 
   │    %5   = (isa)(%3, Type{Nothing})::Bool                                      │ 
   └───        goto #3 if not %5                                                   │ 
   2 ── %7   = π (%3, Type{Nothing})                                               │ 
   │           (%7 <: %4)                                                          │╻ ==
   └───        goto #4                                                             │ 
   3 ── %10  = (%3 == YAML.AliasEvent)::Bool                                       │ 
   └───        goto #4                                                             │ 
   4 ┄─ %12  = φ (#2 => false, #3 => %10)::Bool                                    │ 
   └───        goto #14 if not %12                                                 │ 
61 5 ── %14  = (Base.getfield)(composer, :input)::YAML.EventStream                 │╻ getproperty
   │           invoke YAML.forward!(%14::YAML.EventStream)                         │ 
62 │    %16  = Base.getproperty::Core.Compiler.Const(getproperty, false)           │ 
   │    %17  = (isa)(%2, Nothing)::Bool                                            │ 
   └───        goto #7 if not %17                                                  │ 
   6 ── %19  = π (%2, Nothing)                                                     │ 
   │    %20  = invoke %16(%19::Any, :anchor::Symbol)::Any                          │ 
   └───        goto #8                                                             │ 
   7 ── %22  = (Base.getproperty)(%2, :anchor)::Any                                │ 
   └───        goto #8                                                             │ 
   8 ┄─ %24  = φ (#6 => %20, #7 => %22)::Any                                       │ 
63 │    %25  = (Base.getfield)(composer, :anchors)::Dict{AbstractString,YAML.Node} │╻ getproperty
   │    %26  = (YAML.haskey)(%25, %24)::Bool                                       │ 
   │    %27  = (Base.not_int)(%26)::Bool                                           │╻ !
   └───        goto #13 if not %27                                                 │ 
64 9 ── %29  = (Base.string)("found undefined alias '", %24, "'")::String          │ 
   │    %30  = Base.getproperty::Core.Compiler.Const(getproperty, false)           │ 
   │    %31  = (isa)(%2, Nothing)::Bool                                            │ 
   └───        goto #11 if not %31                                                 │ 
   10 ─ %33  = π (%2, Nothing)                                                     │ 
   │    %34  = invoke %30(%33::Any, :start_mark::Symbol)::Any                      │ 
   └───        goto #12                                                            │ 
   11 ─ %36  = (Base.getproperty)(%2, :start_mark)::Any                            │ 
   └───        goto #12                                                            │ 
   12 ┄ %38  = φ (#10 => %34, #11 => %36)::Any                                     │ 
   │    %39  = (YAML.ComposerError)(YAML.nothing, YAML.nothing, %29, %38)::YAML.ComposerError
   │           (YAML.throw)(%39)                                                   │ 
   └───        $(Expr(:unreachable))                                               │ 
67 13 ─ %42  = (Base.getfield)(composer, :anchors)::Dict{AbstractString,YAML.Node} │╻ getproperty
   │    %43  = (Base.getindex)(%42, %24)::YAML.Node                                │ 
   └───        return %43                                                          │ 
70 14 ─ %45  = Base.getproperty::Core.Compiler.Const(getproperty, false)           │ 
   │    %46  = (isa)(%2, Nothing)::Bool                                            │ 
   └───        goto #16 if not %46                                                 │ 
   15 ─ %48  = π (%2, Nothing)                                                     │ 
   │    %49  = invoke %45(%48::Any, :anchor::Symbol)::Any                          │ 
   └───        goto #17                                                            │ 
   16 ─ %51  = (Base.getproperty)(%2, :anchor)::Any                                │ 
   └───        goto #17                                                            │ 
   17 ┄ %53  = φ (#15 => %49, #16 => %51)::Any                                     │ 
71 │    %54  = (%53 === YAML.nothing)::Bool                                        │ 
   │    %55  = (Core.Intrinsics.not_int)(%54)::Bool                                │ 
   └───        goto #23 if not %55                                                 │ 
72 18 ─ %57  = (Base.getfield)(composer, :anchors)::Dict{AbstractString,YAML.Node} │╻ getproperty
   │    %58  = (YAML.haskey)(%57, %53)::Bool                                       │ 
   └───        goto #23 if not %58                                                 │ 
73 19 ─ %60  = (Base.string)("found duplicate anchor '", %53, "'; first occurance")::String
   │    %61  = (Base.getfield)(composer, :anchors)::Dict{AbstractString,YAML.Node} │╻ getproperty
   │    %62  = (Base.getindex)(%61, %53)::YAML.Node                                │ 
   │    %63  = (Base.getfield)(%62, :start_mark)::Any                              │╻ getproperty
   │    %64  = Base.getproperty::Core.Compiler.Const(getproperty, false)           │ 
   │    %65  = (isa)(%2, Nothing)::Bool                                            │ 
   └───        goto #21 if not %65                                                 │ 
   20 ─ %67  = π (%2, Nothing)                                                     │ 
   │    %68  = invoke %64(%67::Any, :start_mark::Symbol)::Any                      │ 
   └───        goto #22                                                            │ 
   21 ─ %70  = (Base.getproperty)(%2, :start_mark)::Any                            │ 
   └───        goto #22                                                            │ 
   22 ┄ %72  = φ (#20 => %68, #21 => %70)::Any                                     │ 
   │    %73  = (YAML.ComposerError)(%60, %63, "second occurence", %72)::YAML.ComposerError
   │           (YAML.throw)(%73)                                                   │ 
   └───        $(Expr(:unreachable))                                               │ 
80 23 ─ %76  = YAML.nothing::Core.Compiler.Const(nothing, false)                   │ 
81 │    %77  = (YAML.typeof)(%2)::Union{Type{Nothing}, Type{#s55} where #s55<:Event} 
   │    %78  = YAML.ScalarEvent::Core.Compiler.Const(YAML.ScalarEvent, false)      │ 
   │    %79  = (isa)(%77, Type{Nothing})::Bool                                     │ 
   └───        goto #25 if not %79                                                 │ 
   24 ─ %81  = π (%77, Type{Nothing})                                              │ 
   │           (%81 <: %78)                                                        │╻ ==
   └───        goto #26                                                            │ 
   25 ─ %84  = (%77 == YAML.ScalarEvent)::Bool                                     │ 
   └───        goto #26                                                            │ 
   26 ┄ %86  = φ (#24 => false, #25 => %84)::Bool                                  │ 
   └───        goto #28 if not %86                                                 │ 
82 27 ─ %88  = (YAML.compose_scalar_node)(composer, %53)::YAML.ScalarNode          │ 
   └───        goto #38                                                            │ 
83 28 ─ %90  = (YAML.typeof)(%2)::Union{Type{Nothing}, Type{#s55} where #s55<:Event} 
   │    %91  = YAML.SequenceStartEvent::Core.Compiler.Const(YAML.SequenceStartEvent, false)
   │    %92  = (isa)(%90, Type{Nothing})::Bool                                     │ 
   └───        goto #30 if not %92                                                 │ 
   29 ─ %94  = π (%90, Type{Nothing})                                              │ 
   │           (%94 <: %91)                                                        │╻ ==
   └───        goto #31                                                            │ 
   30 ─ %97  = (%90 == YAML.SequenceStartEvent)::Bool                              │ 
   └───        goto #31                                                            │ 
   31 ┄ %99  = φ (#29 => false, #30 => %97)::Bool                                  │ 
   └───        goto #33 if not %99                                                 │ 
84 32 ─ %101 = (YAML.compose_sequence_node)(composer, %53)::YAML.SequenceNode      │ 
   └───        goto #38                                                            │ 
85 33 ─ %103 = (YAML.typeof)(%2)::Union{Type{Nothing}, Type{#s55} where #s55<:Event} 
   │    %104 = YAML.MappingStartEvent::Core.Compiler.Const(YAML.MappingStartEvent, false)
   │    %105 = (isa)(%103, Type{Nothing})::Bool                                    │ 
   └───        goto #35 if not %105                                                │ 
   34 ─ %107 = π (%103, Type{Nothing})                                             │ 
   │           (%107 <: %104)                                                      │╻ ==
   └───        goto #36                                                            │ 
   35 ─ %110 = (%103 == YAML.MappingStartEvent)::Bool                              │ 
   └───        goto #36                                                            │ 
   36 ┄ %112 = φ (#34 => false, #35 => %110)::Bool                                 │ 
   └───        goto #38 if not %112                                                │ 
86 37 ─ %114 = (YAML.compose_mapping_node)(composer, %53)::YAML.MappingNode        │ 
89 38 ┄ %115 = φ (#27 => %88, #32 => %101, #37 => %114, #36 => %76)::Union{Nothing, MappingNode, ScalarNode, SequenceNode}
   └───        return %115                                                         │ 

Scanner Error parsing example hosted on YAML website

I mean the YAML document found here: http://yaml.org/start.html

Copy it into a text document, start julia, import the YAML module, then try to load the file:

julia> YAML.load(open("ex1.yaml"))
ERROR: ScannerError("while scanning a tag",line 1, column 4,"expected ' ', but found ^",line 1, column 20)
 in scan_tag at ~/.julia/YAML/src/scanner.jl:981
 in fetch_more_tokens at ~/.julia/YAML/src/scanner.jl:217
 in peek at ~/.julia/YAML/src/scanner.jl:149
 in parse_document_content at ~/.julia/YAML/src/parser.jl:199
 in peek at ~/.julia/YAML/src/parser.jl:47
 in compose_node at ~/.julia/YAML/src/composer.jl:52
 in compose_document at ~/.julia/YAML/src/composer.jl:43
 in compose at ~/.julia/YAML/src/composer.jl:31
 in load at ~/.julia/YAML/src/YAML.jl:26

I replaced my actual path with "~" in that code.
here's my version info:

julia> versioninfo()
Julia Version 0.3.9
Commit 31efe69 (2015-05-30 11:24 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin13.4.0)
  CPU: Intel(R) Core(TM)2 Duo CPU     T8300  @ 2.40GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Penryn)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3

Non-evaluated parsing

Currently, the load* commands outputs nested Julia structures consisting of standard Julia types, and specific Julia objects. I would find quite useful to have another type of structure, with all the information gathered during parsing (in particular, lines and command).
I currently achieve it using the following piece of code:

function yaml_node_from_string(fn::AbstractString)

        # Didn't find how to access the top node more easily.
        #
        yml_types = Dict{AbstractString,Function}()
        yml_types["!Cartesian"] = ((c,n)->n)
        yml_types["!Smolyak"] = ((c,n)->n)
        yml_types["!Normal"] = ((c,n)->n)
        yml_types["!MarkovChain"] = ((c,n)->n)
        yml_types["!Product"] = ((c,n)->n)
        yml_types["!PoissonProcess"] = ((c,n)->n)
        yml_types["!DeathProcess"] = ((c,n)->n)
        yml_types["!AgingProcess"] = ((c,n)->n)
        yml_types["!VAR1"] = ((c,n)->n)
        yml_types["tag:yaml.org,2002:null"] = ((c,n)->n)
        yml_types["tag:yaml.org,2002:bool"] = ((c,n)->n)
        yml_types["tag:yaml.org,2002:int"] = ((c,n)->n)
        yml_types["tag:yaml.org,2002:float"] = ((c,n)->n)
        yml_types["tag:yaml.org,2002:binary"] = ((c,n)->n)
        yml_types["tag:yaml.org,2002:timestamp"] = ((c,n)->n)
        yml_types["tag:yaml.org,2002:omap"] = ((c,n)->n)
        yml_types["tag:yaml.org,2002:pairs"] = ((c,n)->n)
        yml_types["tag:yaml.org,2002:set"] = ((c,n)->n)
        yml_types["tag:yaml.org,2002:str"] = ((c,n)->n)
        yml_types["tag:yaml.org,2002:seq"] = ((c,n)->n)
        yml_types["tag:yaml.org,2002:map"] = ((c,n)->n)


        return YAML.load(fn, yml_types)
end

The function above returns a *Node object, with other nodes nested in the value field. To manipulate it more easily I have added the functions:

Base.getindex(d::YAML.SequenceNode, k::Integer) = d.value[k]
Base.keys(s::YAML.MappingNode) =  [e[1].value for e=s.value]
Base.values(s::YAML.MappingNode) =  [e[2].value for e=s.value]
Base.getindex(d::YAML.MappingNode, s::AbstractString) = d.value[findfirst(keys(d),s)][2]
Base.getindex(d::YAML.MappingNode, s::Symbol) = d[string(s)]

which allow me to manipulate the resulting structure as if it was a Dict of Dicts and do something like:

s = """symbols:
    controls: [x, y]
    states: [a, b]
"""
data = yaml_node_from_string(s)
el = data[:symbols][:controls][1] # 
el.start_mark, el.end_mark        # (line 2, column 15, line 2, column 16)
el.value                                      # "x"

I'm happy to issue a PR but I have the following questions:

  • Maybe there is an easier way to achieve the same ?
  • For the import function how to rename yaml_node_from_string ? Alternative is to include a list of constructors in the library such that users can do load(data, YAML.raw_constructors) for
  • Right now, a tag appearing in a yaml stream which is not listed in raw_constructors raises an error. It would be nice to call a catchall constructor if supplied, assuming I didn't miss it.

Fix deprecation warning and wrong import in julia nightly

Issue created in order to track the state on julia nighly:

  1. All usages of immutable -> struct
    WARNING: deprecated syntax "immutable" at
    Use "struct" instead.

  2. All usages of type -> mutable struct
    WARNING: deprecated syntax "type" at
    Use "mutable struct" instead.

  3. The use of Date
    WARNING: importing deprecated binding Base.DateTime into YAML.
    ERROR: LoadError: UndefVarErroAll usages of immutable -> structr: Date not defined

  4. New sintax
    parametric method syntax decode{T <: Codec}(codec::Type{T}, s::AbstractString)
    Use "decode(codec::Type{T}, s::AbstractString) where T <: Codec" instead.

load hangs on most files

On my system, the file

- 1
- 2

can't be parsed using YAML.load. The function just hangs and needs to Ctrl-C'd out of.

sensible YAML 1.2 defaults - exponential notation

Sci notation could match more broadly for casting to float, according to the YAML 1.2 spec:

-? ( 0 | [1-9] [0-9]* ) ( \. [0-9]* )? ( [eE] [-+]? [0-9]+ )?

which coincides with julia notation:

5e9
5e+9
5e-9
5e09
5e+09
5e-09
5.e9
5E9
.5e9

see:

This seems like a good feature to "opt-in" on supporting YAML 1.2 by default. Perhaps there could be a "legacy" switch for the old YAML 1.1 behavior?

Data Loss From Loading File

In the documentation it shows data loss when loading a yaml file.
example below
bill-to: &id001

we lose the &id001 when we print out the file

Also is it even possible to specify a value like that when pushing a dictionary to a dictionary?
When we push to a dictionary in julia, it only allows us to either give that variable a descriptor or to provide it with another dictionary or array. What if we want both? Is there any way to do this?

I have not been able to get this to work. Below is an example of what I am having trouble doing:

something: something cool
(indent)onething: one
(indent)twothing: two

0-leaded int not parsed

All numbers starting with a leading "0" are parsed as octal. If the number is something like 0329 it fails to be parsed with ArgumentError since 9 is not in the possible range of values.
I'd fall-back to a base-10 parse or to a string conversion. yamllint keeps them as-is (03 is 3, 011 is 9, 019 is 019)

[PkgEval] YAML may have a testing issue on Julia 0.4 (2014-09-29)

PackageEvaluator.jl is a script that runs nightly. It attempts to load all Julia packages and run their tests (if available) on both the stable version of Julia (0.3) and the nightly build of the unstable version (0.4). The results of this script are used to generate a package listing enhanced with testing results.

On Julia 0.4

  • On 2014-09-28 the testing status was Tests pass.
  • On 2014-09-29 the testing status changed to Tests fail, but package loads.

Tests pass. means that PackageEvaluator found the tests for your package, executed them, and they all passed.

Tests fail, but package loads. means that PackageEvaluator found the tests for your package, executed them, and they didn't pass. However, trying to load your package with using worked.

This error on Julia 0.4 is possibly due to recently merged pull request JuliaLang/julia#8420.
This issue was filed because your testing status became worse. No additional issues will be filed if your package remains in this state, and no issue will be filed if it improves. If you'd like to opt-out of these status-change messages, reply to this message saying you'd like to and @IainNZ will add an exception. If you'd like to discuss PackageEvaluator.jl please file an issue at the repository. For example, your package may be untestable on the test machine due to a dependency - an exception can be added.

Test log:

>>> 'Pkg.add("YAML")' log
INFO: Installing Codecs v0.1.2
INFO: Installing Datetime v0.1.6
INFO: Installing LazySequences v0.1.0
INFO: Installing YAML v0.1.7
INFO: Building Datetime
INFO: Package database updated

>>> 'using YAML' log
Warning: imported binding for Date overwritten in module Datetime
Warning: imported binding for DateTime overwritten in module Datetime
Warning: Method definition now in module Dates at dates/conversions.jl:21 overwritten in module Datetime at /home/idunning/pkgtest/.julia/v0.4/Datetime/src/Datetime.jl:294.
Julia Version 0.4.0-dev+842
Commit e5d8c1a (2014-09-29 06:50 UTC)
Platform Info:
  System: Linux (x86_64-unknown-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU E5-2650 0 @ 2.00GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3
()
>>> test log
Warning: imported binding for Date overwritten in module Datetime
Warning: imported binding for DateTime overwritten in module Datetime
Warning: Method definition now in module Dates at dates/conversions.jl:21 overwritten in module Datetime at /home/idunning/pkgtest/.julia/v0.4/Datetime/src/Datetime.jl:294.
spec-02-01: PASSED
spec-02-02: PASSED
spec-02-03: PASSED
spec-02-04: PASSED
spec-02-05: PASSED
spec-02-06: PASSED
spec-02-07: PASSED
spec-02-08: PASSED
spec-02-09: PASSED
spec-02-10: PASSED
spec-02-11: PASSED
spec-02-12: PASSED
spec-02-13: PASSED
spec-02-14: PASSED
spec-02-15: PASSED
spec-02-16: PASSED
spec-02-17: PASSED
spec-02-18: PASSED
spec-02-19: PASSED
spec-02-20: PASSED
spec-02-21: PASSED
spec-02-22: PASSED

()WARNING: Set(a,b...) is deprecated, use Set({a,b...}) instead.
 in Set at deprecated.jl:26
 in equivalent at /home/idunning/pkgtest/.julia/v0.4/YAML/test/test.jl:35
 in anonymous at no file:79
 in include at ./boot.jl:245
 in include_from_node1 at loading.jl:128
 in process_options at ./client.jl:285
 in _start at ./client.jl:354
 in _start_3B_3625 at /home/idunning/julia04/usr/bin/../lib/julia/sys.so
WARNING: Set(a,b...) is deprecated, use Set({a,b...}) instead.
 in Set at deprecated.jl:26
 in equivalent at /home/idunning/pkgtest/.julia/v0.4/YAML/test/test.jl:35
 in anonymous at no file:79
 in include at ./boot.jl:245
 in include_from_node1 at loading.jl:128
 in process_options at ./client.jl:285
 in _start at ./client.jl:354
 in _start_3B_3625 at /home/idunning/julia04/usr/bin/../lib/julia/sys.so
WARNING: sexagesimal integers not yet implemented. Returning string.
WARNING: sexagesimal integers not yet implemented. Returning string.
WARNING: sexagesimal floats not yet implemented. Returning string.
ERROR: InexactError()
 in decode at /home/idunning/pkgtest/.julia/v0.4/Codecs/src/Codecs.jl:155
 in decode at /home/idunning/pkgtest/.julia/v0.4/Codecs/src/Codecs.jl:15
 in construct_yaml_binary at /home/idunning/pkgtest/.julia/v0.4/YAML/src/constructor.jl:344
 in construct_object at /home/idunning/pkgtest/.julia/v0.4/YAML/src/constructor.jl:79
 in construct_mapping at /home/idunning/pkgtest/.julia/v0.4/YAML/src/constructor.jl:147
 in construct_yaml_map at /home/idunning/pkgtest/.julia/v0.4/YAML/src/constructor.jl:325
 in construct_object at /home/idunning/pkgtest/.julia/v0.4/YAML/src/constructor.jl:79
 in construct_document at /home/idunning/pkgtest/.julia/v0.4/YAML/src/constructor.jl:33
 in load at /home/idunning/pkgtest/.julia/v0.4/YAML/src/YAML.jl:22
 in load_file at /home/idunning/pkgtest/.julia/v0.4/YAML/src/YAML.jl:46
 in anonymous at no file:77
 in include at ./boot.jl:245
 in include_from_node1 at loading.jl:128
 in process_options at ./client.jl:285
 in _start at ./client.jl:354
 in _start_3B_3625 at /home/idunning/julia04/usr/bin/../lib/julia/sys.so
while loading /home/idunning/pkgtest/.julia/v0.4/YAML/test/test.jl, in expression starting on line 76

>>> end of log

Application specific tags?

I know it's clearly stated at README that Application specific tags are not implemented. But it seems to me basic structures are already there, and I'm wondering is it possible to implement that functionality.

I'm trying to parse unity data for my project.
But there are some strings in unity data that YAML.jl can't handle

I can filter those strings manually, and read unity data with YAML.jl.
But if there is better way to do this, It will be really helpful for me 😄

here is a minimal example

using YAML

s1 = """
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1001 &100100000
Prefab:
  m_ObjectHideFlags: 1
  m_Modification:
    m_TransformParent: {fileID: 0}
    m_Modifications: []
  m_SourcePrefab: {fileID: 0}
  m_RootGameObject: {fileID: 1794587523630750}
--- !u!1 &1087941076346928
GameObject:
  m_ObjectHideFlags: 1
  m_PrefabInternal: {fileID: 100100000}
  m_Component:
  - component: {fileID: 224636974132200644}
  m_Layer: 5
  m_Icon: {fileID: 0}
  m_NavMeshLayer: 0
  m_IsActive: 1
"""
data = YAML.load(s1) # is not working

s2 = """
Prefab:
  m_ObjectHideFlags: 1
  m_Modification:
    m_TransformParent: {fileID: 0}
    m_Modifications: []
  m_SourcePrefab: {fileID: 0}
  m_RootGameObject: {fileID: 1794587523630750}
GameObject:
  m_ObjectHideFlags: 1
  m_PrefabInternal: {fileID: 100100000}
  m_Component:
  - component: {fileID: 224636974132200644}
  m_Layer: 5
  m_Icon: {fileID: 0}
  m_NavMeshLayer: 0
  m_IsActive: 1
"""
data = YAML.load(s2) # it works

"<<: hi" causes `load` to hang

The key "<<" causes load to consume CPU cycles indefinitely.
For example <<: hi

Julia Version 0.6.2
Commit d386e40c17 (2017-12-13 18:08 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM) i7-4712HQ CPU @ 2.30GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, haswell)

Wrong structure with empty dicts depending on order

Hello,

I noticed a strange behaviour with empty dicts:

import YAML
file_good = "test_good.yml"
data = Dict("key1" => [Dict("subkey1" => "subvalue1", "subkey2" => "subvalue2"), Dict()], "key2" => "value2")
YAML.write_file(file_good, data)
file_bad = "test_bad.yml"
data = Dict("dkey1" => [Dict("subkey1" => "subvalue1", "subkey2" => "subvalue2"), Dict()], "key2" => "value2")
YAML.write_file(file_bad, data)

file_good.yml:

key2: "value2"
key1:
  - subkey2: "subvalue2"
    subkey1: "subvalue1"
  - 

file_bad.yml:

dkey1:
  - subkey2: "subvalue2"
    subkey1: "subvalue1"
  - key2: "value2"

In the bad file, the structure becomes wrong, depending on the order the dict is read (that is why it was hard to reproduce this, I needed to try several names to make it appear).

Thank you for your investigation.

Sincerely.

Roundtrip load/save/load

Hello,

Currently YAML.jl is able to parse a string (or a file) and it returns a parsed YAML document (or several YAML documents) as Dict.

When #68 will be merged it will be possible to emit Julia objects to YAML strings and files.

Even after this PR merged, a rountrip won't be possible ie with YAML string, YAML.jl load function will return a Dict but not a Julia object.

So the following scenario for testing should probably be considered:

  • YAML String->Julia Object->YAML String
  • Julia Object->YAML String ->Julia Object

Kind regards

Delete project file

Please consider deleting the project file since it isn't needed yet and it causes the reverse dependency testing in CIBot to break.

New release so that write_file is available?

Hi there,

I have a need to write simple data structures to YAML and the new write_file function is sufficient.
Would it be possible to release a new version of this package so that write_file is available in the release?
(currently I have to ] add YAML#master, I'd prefer to just ] add YAML)

Cheers,
Jock

Julia segfault when running tests for the first time?

When running tests for the first time, I get the following Julia segfault error:

spec-02-01: PASSED
spec-02-02: PASSED
spec-02-03: PASSED
spec-02-04: PASSED
spec-02-05: PASSED
spec-02-06: PASSED
spec-02-07: PASSED
WARNING: sexagesimal integers not yet implemented. Returning string.
spec-02-08: PASSED
spec-02-09: PASSED
spec-02-10: PASSED
spec-02-11: PASSED
spec-02-12: PASSED
spec-02-13: PASSED
spec-02-14: PASSED
spec-02-15: PASSED
spec-02-16: PASSED
spec-02-17: PASSED
spec-02-18: PASSED
WARNING: sexagesimal integers not yet implemented. Returning string.
ERROR:
 in evalfile at loading.jl:156
 in anonymous at no file:78
 in include at boot.jl:238
 in include_from_node1 at loading.jl:114
 in process_options at client.jl:303
 in _start at client.jl:389fatal: error thrown and no exception handler available.
Base.TypeError(func=:apply_type, context="Vararg", expected=Type{T}, got=[1]    5857 segmentation fault  julia test.jl

Tests all pass when running again, however. It's not really an issue, but it seems odd that it happens only one time. Does anyone else experience this?

Scanner Error: while scanning a simple key

Sorry for all the errors, using this package for my new UAParser package

The mork fix fixed most of the errors I was seeing on my test files, but I now I'm seeing the following error:

using YAML
YAML.load(open("/Users/randyzwitch/.julia/UAParser/test/data/additional_os_tests.yaml"))


ScannerError("while scanning a simple key",Mark(0x00000000000028b5,0x00000000000000a2,0x0000000000000004),"could not find expected ':'",Mark(0x00000000000028cd,0x00000000000000a2,0x0000000000000010))
while loading In[7], in expression starting on line 1
 in remove_possible_simple_key at /Users/randyzwitch/.julia/YAML/src/scanner.jl:318
 in fetch_stream_end at /Users/randyzwitch/.julia/YAML/src/scanner.jl:411
 in fetch_more_tokens at /Users/randyzwitch/.julia/YAML/src/scanner.jl:217
 in next_token at /Users/randyzwitch/.julia/YAML/src/scanner.jl:191
 in tokenize at /Users/randyzwitch/.julia/YAML/src/scanner.jl:165
 in anonymous at /Users/randyzwitch/.julia/LazySequences/src/LazySequences.jl:102
 in seq at /Users/randyzwitch/.julia/LazySequences/src/LazySequences.jl:97
 in rest at /Users/randyzwitch/.julia/LazySequences/src/LazySequences.jl:31
 in pop_token at /Users/randyzwitch/.julia/YAML/src/parser.jl:54
 in parse_block_mapping_value at /Users/randyzwitch/.julia/YAML/src/parser.jl:418
 in next_event at /Users/randyzwitch/.julia/YAML/src/parser.jl:67
 in parse at /Users/randyzwitch/.julia/YAML/src/parser.jl:42
 in anonymous at /Users/randyzwitch/.julia/LazySequences/src/LazySequences.jl:102
 in seq at /Users/randyzwitch/.julia/LazySequences/src/LazySequences.jl:97
 in rest at /Users/randyzwitch/.julia/LazySequences/src/LazySequences.jl:31
 in pop_event at /Users/randyzwitch/.julia/YAML/src/composer.jl:30
 in compose_scalar_node at /Users/randyzwitch/.julia/YAML/src/composer.jl:94
 in compose_node at /Users/randyzwitch/.julia/YAML/src/composer.jl:82
 in compose_mapping_node at /Users/randyzwitch/.julia/YAML/src/composer.jl:153
 in compose_node at /Users/randyzwitch/.julia/YAML/src/composer.jl:82
 in compose_sequence_node at /Users/randyzwitch/.julia/YAML/src/composer.jl:127
 in compose_node at /Users/randyzwitch/.julia/YAML/src/composer.jl:82
 in compose_mapping_node at /Users/randyzwitch/.julia/YAML/src/composer.jl:154
 in compose_node at /Users/randyzwitch/.julia/YAML/src/composer.jl:82
 in compose_document at /Users/randyzwitch/.julia/YAML/src/composer.jl:50
 in compose at /Users/randyzwitch/.julia/YAML/src/composer.jl:38
 in load at /Users/randyzwitch/.julia/YAML/src/YAML.jl:21

Package should belong to JuliaIO

Hello BioJulia,

I'm fighting with entropy in the Julia world those days. It's becoming very,
very hard to know where to grasp a recommended / authoritative package among
Julia ones, even in 2019.

Doesn't this package would be better hosted at
JuliaIO so anyone concerned would
find it easily ?

Thanks

assertion failed: :((typeof(pop_event(composer))==StreamStartEvent))

I'm getting that assertion on pretty much everything:

julia> import YAML

julia> YAML.load("../settings.yml.default")
ERROR: assertion failed: :((typeof(pop_event(composer))==StreamStartEvent))
 in compose at /Users/keno/.julia/YAML/src/composer.jl:37
 in load at /Users/keno/.julia/YAML/src/YAML.jl:21
 in load at /Users/keno/.julia/YAML/src/YAML.jl:40

julia> YAML.load_file("../settings.yml.default")
ERROR: assertion failed: :((typeof(pop_event(composer))==StreamStartEvent))
 in compose at /Users/keno/.julia/YAML/src/composer.jl:37
 in load at /Users/keno/.julia/YAML/src/YAML.jl:21
 in load_file at /Users/keno/.julia/YAML/src/YAML.jl:46

The yml file:

Kenos-MacBook-Pro:src keno$ cat ../settings.yml.default
server_port:    8000
worker_port:    8000
docker_host:    127.0.0.1:4243

sensible YAML 1.2 defaults - only true and false for bools

In YAML 1.2 only true and false are implicitly cast to bools. This is in contrast to the grab-bag y, n, yes, no, on, off, etc. with any capitalization.

This commonly leads to more harm then good. A notable example being when working with chemical symbols of elements:

Mende­levium: Md
Nobel­ium: No
Lawren­cium: Lr

see:

This seems like a good feature to "opt-in" on supporting YAML 1.2 by default. Perhaps there could be a "legacy" switch for the old YAML 1.1 behavior?

Can't iterate over multiple documents in a file

With parsing multiple YAML documents, the following seems to fail

docs = YAML.load_all("---\nfoo: bar\n---\nfoo:baz\n")
for d in docs
    println(d)
end

Gives

ERROR: assertion failed: typeof(pop_event(composer)) == StreamStartEvent
 in compose at /Users/nathan/.julia/v0.4/YAML/src/composer.jl:37
 in next_document at /Users/nathan/.julia/v0.4/YAML/src/YAML.jl:33
 in anonymous at /Users/nathan/.julia/v0.4/LazySequences/src/LazySequences.jl:102
 in seq at /Users/nathan/.julia/v0.4/LazySequences/src/LazySequences.jl:97
 in next at /Users/nathan/.julia/v0.4/LazySequences/src/LazySequences.jl:125
 in anonymous at no file

My julia version = julia version 0.4.0-dev+571

Fix deprecation warnings

I think I can fix this and submit a PR, looks to be just swapping out bracket types

WARNING: deprecated syntax "{}" at /home/rzwitch/.julia/v0.4/YAML/src/scanner.jl:1029.
Use "[]" instead.

WARNING: deprecated syntax "{}" at /home/rzwitch/.julia/v0.4/YAML/src/scanner.jl:1151.
Use "[]" instead.

WARNING: deprecated syntax "{}" at /home/rzwitch/.julia/v0.4/YAML/src/scanner.jl:1171.
Use "[]" instead.

WARNING: deprecated syntax "{}" at /home/rzwitch/.julia/v0.4/YAML/src/scanner.jl:1191.
Use "[]" instead.

WARNING: deprecated syntax "{a=>b, ...}" at /home/rzwitch/.julia/v0.4/YAML/src/scanner.jl:1222.
Use "Dict{Any,Any}(a=>b, ...)" instead.

WARNING: deprecated syntax "{a=>b, ...}" at /home/rzwitch/.julia/v0.4/YAML/src/scanner.jl:1229.
Use "Dict{Any,Any}(a=>b, ...)" instead.

WARNING: deprecated syntax "{}" at /home/rzwitch/.julia/v0.4/YAML/src/scanner.jl:1234.
Use "[]" instead.

WARNING: deprecated syntax "{}" at /home/rzwitch/.julia/v0.4/YAML/src/scanner.jl:1292.
Use "[]" instead.

WARNING: deprecated syntax "{}" at /home/rzwitch/.julia/v0.4/YAML/src/scanner.jl:1323.
Use "[]" instead.

WARNING: deprecated syntax "{}" at /home/rzwitch/.julia/v0.4/YAML/src/scanner.jl:1352.
Use "[]" instead.

WARNING: deprecated syntax "{}" at /home/rzwitch/.julia/v0.4/YAML/src/scanner.jl:1361.
Use "[]" instead.

WARNING: deprecated syntax "{}" at /home/rzwitch/.julia/v0.4/YAML/src/scanner.jl:1412.
Use "[]" instead.

WARNING: deprecated syntax "{}" at /home/rzwitch/.julia/v0.4/YAML/src/scanner.jl:1427.
Use "[]" instead.

WARNING: deprecated syntax "{}" at /home/rzwitch/.julia/v0.4/YAML/src/scanner.jl:1430.
Use "[]" instead.

WARNING: deprecated syntax "{}" at /home/rzwitch/.julia/v0.4/YAML/src/scanner.jl:1439.
Use "[]" instead.

WARNING: deprecated syntax "{}" at /home/rzwitch/.julia/v0.4/YAML/src/scanner.jl:1487.
Use "[]" instead.

WARNING: deprecated syntax "{}" at /home/rzwitch/.julia/v0.4/YAML/src/scanner.jl:1519.
Use "[]" instead.

WARNING: deprecated syntax "[a=>b, ...]" at /home/rzwitch/.julia/v0.4/YAML/src/parser.jl:4.
Use "Dict(a=>b, ...)" instead.

WARNING: deprecated syntax "(String=>String)[a=>b, ...]" at /home/rzwitch/.julia/v0.4/YAML/src/parser.jl:4.
Use "Dict{String,String}(a=>b, ...)" instead.

WARNING: deprecated syntax "{}" at /home/rzwitch/.julia/v0.4/YAML/src/composer.jl:119.
Use "[]" instead.

WARNING: deprecated syntax "{}" at /home/rzwitch/.julia/v0.4/YAML/src/composer.jl:146.
Use "[]" instead.

WARNING: deprecated syntax "{}" at /home/rzwitch/.julia/v0.4/YAML/src/constructor.jl:116.
Use "[]" instead.

WARNING: deprecated syntax "[a=>b, ...]" at /home/rzwitch/.julia/v0.4/YAML/src/constructor.jl:350.
Use "Dict(a=>b, ...)" instead.

WARNING: deprecated syntax "(Union(String,Nothing)=>Function)[a=>b, ...]" at /home/rzwitch/.julia/v0.4/YAML/src/constructor.jl:363.
Use "Dict{Union(String,Nothing),Function}(a=>b, ...)" instead.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.