From 9c0a725640f2d2c0f3cee834ed5d0f9ead4d724b Mon Sep 17 00:00:00 2001 From: Adrian Utrilla Date: Wed, 26 Oct 2016 21:15:36 +0200 Subject: [PATCH] Updated vendored deps --- Godeps/Godeps.json | 8 +- .../yaml.v2}/.travis.yml | 0 .../yaml => mozilla-services/yaml.v2}/LICENSE | 0 .../yaml.v2}/LICENSE.libyaml | 0 .../yaml.v2}/README.md | 2 +- .../yaml => mozilla-services/yaml.v2}/apic.go | 0 .../yaml.v2}/decode.go | 127 +++++++++++++----- .../yaml.v2}/emitterc.go | 20 +++ .../yaml.v2}/encode.go | 40 ++++-- .../yaml.v2}/parserc.go | 55 +++++++- .../yaml.v2}/readerc.go | 0 .../yaml.v2}/resolve.go | 0 .../yaml.v2}/scannerc.go | 47 +++++-- .../yaml.v2}/sorter.go | 0 .../yaml.v2}/writerc.go | 0 .../yaml => mozilla-services/yaml.v2}/yaml.go | 39 ++++++ .../yaml.v2}/yamlh.go | 84 ++++++++++++ .../yaml.v2}/yamlprivateh.go | 0 18 files changed, 356 insertions(+), 66 deletions(-) rename vendor/github.com/{autrilla/yaml => mozilla-services/yaml.v2}/.travis.yml (100%) rename vendor/github.com/{autrilla/yaml => mozilla-services/yaml.v2}/LICENSE (100%) rename vendor/github.com/{autrilla/yaml => mozilla-services/yaml.v2}/LICENSE.libyaml (100%) rename vendor/github.com/{autrilla/yaml => mozilla-services/yaml.v2}/README.md (94%) rename vendor/github.com/{autrilla/yaml => mozilla-services/yaml.v2}/apic.go (100%) rename vendor/github.com/{autrilla/yaml => mozilla-services/yaml.v2}/decode.go (88%) rename vendor/github.com/{autrilla/yaml => mozilla-services/yaml.v2}/emitterc.go (98%) rename vendor/github.com/{autrilla/yaml => mozilla-services/yaml.v2}/encode.go (91%) rename vendor/github.com/{autrilla/yaml => mozilla-services/yaml.v2}/parserc.go (95%) rename vendor/github.com/{autrilla/yaml => mozilla-services/yaml.v2}/readerc.go (100%) rename vendor/github.com/{autrilla/yaml => mozilla-services/yaml.v2}/resolve.go (100%) rename vendor/github.com/{autrilla/yaml => mozilla-services/yaml.v2}/scannerc.go (98%) rename vendor/github.com/{autrilla/yaml => mozilla-services/yaml.v2}/sorter.go (100%) rename vendor/github.com/{autrilla/yaml => mozilla-services/yaml.v2}/writerc.go (100%) rename vendor/github.com/{autrilla/yaml => mozilla-services/yaml.v2}/yaml.go (92%) rename vendor/github.com/{autrilla/yaml => mozilla-services/yaml.v2}/yamlh.go (90%) rename vendor/github.com/{autrilla/yaml => mozilla-services/yaml.v2}/yamlprivateh.go (100%) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 3cede8b6f..2521fc037 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -6,10 +6,6 @@ "./..." ], "Deps": [ - { - "ImportPath": "github.com/autrilla/yaml", - "Rev": "8ac3c7b2b592354bed79f33de3e3c83e573b9129" - }, { "ImportPath": "github.com/aws/aws-sdk-go/aws", "Comment": "v1.3.0-1-g00e2bf9", @@ -159,6 +155,10 @@ "Comment": "0.2.2-14-gbd40a43", "Rev": "bd40a432e4c76585ef6b72d3fd96fb9b6dc7b68d" }, + { + "ImportPath": "github.com/mozilla-services/yaml.v2", + "Rev": "2e2d479b8b66e65ce5a8f49afd77931628fd8f8f" + }, { "ImportPath": "github.com/pmezard/go-difflib/difflib", "Comment": "v1.0.0", diff --git a/vendor/github.com/autrilla/yaml/.travis.yml b/vendor/github.com/mozilla-services/yaml.v2/.travis.yml similarity index 100% rename from vendor/github.com/autrilla/yaml/.travis.yml rename to vendor/github.com/mozilla-services/yaml.v2/.travis.yml diff --git a/vendor/github.com/autrilla/yaml/LICENSE b/vendor/github.com/mozilla-services/yaml.v2/LICENSE similarity index 100% rename from vendor/github.com/autrilla/yaml/LICENSE rename to vendor/github.com/mozilla-services/yaml.v2/LICENSE diff --git a/vendor/github.com/autrilla/yaml/LICENSE.libyaml b/vendor/github.com/mozilla-services/yaml.v2/LICENSE.libyaml similarity index 100% rename from vendor/github.com/autrilla/yaml/LICENSE.libyaml rename to vendor/github.com/mozilla-services/yaml.v2/LICENSE.libyaml diff --git a/vendor/github.com/autrilla/yaml/README.md b/vendor/github.com/mozilla-services/yaml.v2/README.md similarity index 94% rename from vendor/github.com/autrilla/yaml/README.md rename to vendor/github.com/mozilla-services/yaml.v2/README.md index 7b8bd8670..1884de6a7 100644 --- a/vendor/github.com/autrilla/yaml/README.md +++ b/vendor/github.com/mozilla-services/yaml.v2/README.md @@ -42,7 +42,7 @@ The package API for yaml v2 will remain stable as described in [gopkg.in](https: License ------- -The yaml package is licensed under the LGPL with an exception that allows it to be linked statically. Please see the LICENSE file for details. +The yaml package is licensed under the Apache License 2.0. Please see the LICENSE file for details. Example diff --git a/vendor/github.com/autrilla/yaml/apic.go b/vendor/github.com/mozilla-services/yaml.v2/apic.go similarity index 100% rename from vendor/github.com/autrilla/yaml/apic.go rename to vendor/github.com/mozilla-services/yaml.v2/apic.go diff --git a/vendor/github.com/autrilla/yaml/decode.go b/vendor/github.com/mozilla-services/yaml.v2/decode.go similarity index 88% rename from vendor/github.com/autrilla/yaml/decode.go rename to vendor/github.com/mozilla-services/yaml.v2/decode.go index 085cddc44..c8469bfb7 100644 --- a/vendor/github.com/autrilla/yaml/decode.go +++ b/vendor/github.com/mozilla-services/yaml.v2/decode.go @@ -16,6 +16,7 @@ const ( sequenceNode scalarNode aliasNode + commentNode ) type node struct { @@ -117,6 +118,8 @@ func (p *parser) parse() *node { case yaml_STREAM_END_EVENT: // Happens when attempting to decode an empty buffer. return nil + case yaml_COMMENT_EVENT: + return p.comment() default: panic("attempted to parse unknown event: " + strconv.Itoa(int(p.event.typ))) } @@ -161,6 +164,13 @@ func (p *parser) scalar() *node { return n } +func (p *parser) comment() *node { + n := p.node(commentNode) + n.value = string(p.event.value) + p.skip() + return n +} + func (p *parser) sequence() *node { n := p.node(sequenceNode) p.anchor(n, p.event.anchor) @@ -177,7 +187,7 @@ func (p *parser) mapping() *node { p.anchor(n, p.event.anchor) p.skip() for p.event.typ != yaml_MAPPING_END_EVENT { - n.children = append(n.children, p.parse(), p.parse()) + n.children = append(n.children, p.parse()) } p.skip() return n @@ -251,7 +261,7 @@ func (d *decoder) callUnmarshaler(n *node, u Unmarshaler) (good bool) { // // If n holds a null value, prepare returns before doing anything. func (d *decoder) prepare(n *node, out reflect.Value) (newout reflect.Value, unmarshaled, good bool) { - if n.tag == yaml_NULL_TAG || n.kind == scalarNode && n.tag == "" && (n.value == "null" || n.value == "") { + if n.tag == yaml_NULL_TAG || n.kind == scalarNode && n.tag == "" && (n.value == "null" || n.value == "" && n.implicit) { return out, false, false } again := true @@ -288,6 +298,8 @@ func (d *decoder) unmarshal(n *node, out reflect.Value) (good bool) { switch n.kind { case scalarNode: good = d.scalar(n, out) + case commentNode: + good = d.comment(n, out) case mappingNode: good = d.mapping(n, out) case sequenceNode: @@ -329,6 +341,20 @@ func resetMap(out reflect.Value) { } } +type Comment struct { + Value string +} + +func (d *decoder) comment(n *node, out reflect.Value) (good bool) { + switch out.Kind() { + case reflect.Interface: + out.Set(reflect.ValueOf(Comment{ + Value: n.value, + })) + } + return true +} + func (d *decoder) scalar(n *node, out reflect.Value) (good bool) { var tag string var resolved interface{} @@ -491,7 +517,6 @@ func (d *decoder) sequence(n *node, out reflect.Value) (good bool) { return false } et := out.Type().Elem() - j := 0 for i := 0; i < l; i++ { e := reflect.New(et).Elem() @@ -544,24 +569,41 @@ func (d *decoder) mapping(n *node, out reflect.Value) (good bool) { if out.IsNil() { out.Set(reflect.MakeMap(outt)) } - l := len(n.children) - for i := 0; i < l; i += 2 { - if isMerge(n.children[i]) { - d.merge(n.children[i+1], out) - continue - } - k := reflect.New(kt).Elem() - if d.unmarshal(n.children[i], k) { - kkind := k.Kind() - if kkind == reflect.Interface { - kkind = k.Elem().Kind() - } - if kkind == reflect.Map || kkind == reflect.Slice { - failf("invalid map key: %#v", k.Interface()) - } - e := reflect.New(et).Elem() - if d.unmarshal(n.children[i+1], e) { - out.SetMapIndex(k, e) + var key *node + var value *node + var keySet bool + for _, child := range n.children { + if child.kind == commentNode { + out.SetMapIndex( + reflect.ValueOf(Comment{ + Value: child.value, + }), + reflect.Zero(kt)) + } else { + if !keySet { + keySet = true + key = child + } else { + keySet = false + value = child + if isMerge(key) { + d.merge(value, out) + continue + } + k := reflect.New(kt).Elem() + if d.unmarshal(key, k) { + kkind := k.Kind() + if kkind == reflect.Interface { + kkind = k.Elem().Kind() + } + if kkind == reflect.Map || kkind == reflect.Slice { + failf("invalid map key: %#v", k.Interface()) + } + e := reflect.New(et).Elem() + if d.unmarshal(value, e) { + out.SetMapIndex(k, e) + } + } } } } @@ -580,18 +622,37 @@ func (d *decoder) mappingSlice(n *node, out reflect.Value) (good bool) { d.mapType = outt var slice []MapItem - var l = len(n.children) - for i := 0; i < l; i += 2 { - if isMerge(n.children[i]) { - d.merge(n.children[i+1], out) - continue - } - item := MapItem{} - k := reflect.ValueOf(&item.Key).Elem() - if d.unmarshal(n.children[i], k) { - v := reflect.ValueOf(&item.Value).Elem() - if d.unmarshal(n.children[i+1], v) { - slice = append(slice, item) + + var key *node + var value *node + var keySet bool + for _, child := range n.children { + if child.kind == commentNode { + slice = append(slice, MapItem{ + Key: Comment{ + Value: child.value, + }, + Value: nil, + }) + } else { + if !keySet { + keySet = true + key = child + } else { + keySet = false + value = child + if isMerge(key) { + d.merge(value, out) + continue + } + item := MapItem{} + k := reflect.ValueOf(&item.Key).Elem() + if d.unmarshal(key, k) { + v := reflect.ValueOf(&item.Value).Elem() + if d.unmarshal(value, v) { + slice = append(slice, item) + } + } } } } diff --git a/vendor/github.com/autrilla/yaml/emitterc.go b/vendor/github.com/mozilla-services/yaml.v2/emitterc.go similarity index 98% rename from vendor/github.com/autrilla/yaml/emitterc.go rename to vendor/github.com/mozilla-services/yaml.v2/emitterc.go index 2befd553e..48e92114b 100644 --- a/vendor/github.com/autrilla/yaml/emitterc.go +++ b/vendor/github.com/mozilla-services/yaml.v2/emitterc.go @@ -588,6 +588,9 @@ func yaml_emitter_emit_block_sequence_item(emitter *yaml_emitter_t, event *yaml_ emitter.states = emitter.states[:len(emitter.states)-1] return true } + if event.typ == yaml_COMMENT_EVENT { + return yaml_emitter_emit_comment(emitter, event) + } if !yaml_emitter_write_indent(emitter) { return false } @@ -600,11 +603,15 @@ func yaml_emitter_emit_block_sequence_item(emitter *yaml_emitter_t, event *yaml_ // Expect a block key node. func yaml_emitter_emit_block_mapping_key(emitter *yaml_emitter_t, event *yaml_event_t, first bool) bool { + if event.typ == yaml_COMMENT_EVENT { + return yaml_emitter_emit_comment(emitter, event) + } if first { if !yaml_emitter_increase_indent(emitter, false, false) { return false } } + if event.typ == yaml_MAPPING_END_EVENT { emitter.indent = emitter.indents[len(emitter.indents)-1] emitter.indents = emitter.indents[:len(emitter.indents)-1] @@ -612,6 +619,7 @@ func yaml_emitter_emit_block_mapping_key(emitter *yaml_emitter_t, event *yaml_ev emitter.states = emitter.states[:len(emitter.states)-1] return true } + if !yaml_emitter_write_indent(emitter) { return false } @@ -628,6 +636,7 @@ func yaml_emitter_emit_block_mapping_key(emitter *yaml_emitter_t, event *yaml_ev // Expect a block value node. func yaml_emitter_emit_block_mapping_value(emitter *yaml_emitter_t, event *yaml_event_t, simple bool) bool { + if simple { if !yaml_emitter_write_indicator(emitter, []byte{':'}, false, false, false) { return false @@ -662,6 +671,8 @@ func yaml_emitter_emit_node(emitter *yaml_emitter_t, event *yaml_event_t, return yaml_emitter_emit_sequence_start(emitter, event) case yaml_MAPPING_START_EVENT: return yaml_emitter_emit_mapping_start(emitter, event) + case yaml_COMMENT_EVENT: + return yaml_emitter_emit_comment(emitter, event) default: return yaml_emitter_set_emitter_error(emitter, "expected SCALAR, SEQUENCE-START, MAPPING-START, or ALIAS") @@ -679,6 +690,15 @@ func yaml_emitter_emit_alias(emitter *yaml_emitter_t, event *yaml_event_t) bool return true } +func yaml_emitter_emit_comment(emitter *yaml_emitter_t, event *yaml_event_t) bool { + if !yaml_emitter_write_indent(emitter) { + return false + } + out := []byte{'#'} + out = append(out, event.value...) + return write_all(emitter, out) +} + // Expect SCALAR. func yaml_emitter_emit_scalar(emitter *yaml_emitter_t, event *yaml_event_t) bool { if !yaml_emitter_select_scalar_style(emitter, event) { diff --git a/vendor/github.com/autrilla/yaml/encode.go b/vendor/github.com/mozilla-services/yaml.v2/encode.go similarity index 91% rename from vendor/github.com/autrilla/yaml/encode.go rename to vendor/github.com/mozilla-services/yaml.v2/encode.go index 4f8418f25..731593ddc 100644 --- a/vendor/github.com/autrilla/yaml/encode.go +++ b/vendor/github.com/mozilla-services/yaml.v2/encode.go @@ -30,6 +30,12 @@ func newEncoder() (e *encoder) { return e } +func newEncoderWithIndent(indent int) (e *encoder) { + e = newEncoder() + e.emitter.best_indent = indent + return e +} + func (e *encoder) finish() { e.must(yaml_document_end_event_initialize(&e.event, true)) e.emit() @@ -75,8 +81,8 @@ func (e *encoder) marshal(tag string, in reflect.Value) { return } in = reflect.ValueOf(v) - } else if t, ok := iface.(time.Time); ok { - e.timev(tag, t) + } else if _, ok := iface.(time.Time); ok { + e.timev(tag, in) return } else if m, ok := iface.(encoding.TextMarshaler); ok { text, err := m.MarshalText() @@ -101,7 +107,11 @@ func (e *encoder) marshal(tag string, in reflect.Value) { e.marshal(tag, in.Elem()) } case reflect.Struct: - e.structv(tag, in) + if comment, ok := iface.(Comment); ok { + e.commentv([]byte(comment.Value)) + } else { + e.structv(tag, in) + } case reflect.Slice: if in.Type().Elem() == mapItemType { e.itemsv(tag, in) @@ -142,8 +152,12 @@ func (e *encoder) itemsv(tag string, in reflect.Value) { e.mappingv(tag, func() { slice := in.Convert(reflect.TypeOf([]MapItem{})).Interface().([]MapItem) for _, item := range slice { - e.marshal("", reflect.ValueOf(item.Key)) - e.marshal("", reflect.ValueOf(item.Value)) + if comment, ok := item.Key.(Comment); ok { + e.marshal("", reflect.ValueOf(comment)) + } else { + e.marshal("", reflect.ValueOf(item.Key)) + e.marshal("", reflect.ValueOf(item.Value)) + } } }) } @@ -247,11 +261,9 @@ var base60float = regexp.MustCompile(`^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+(?:\.[0 // From http://yaml.org/type/timestamp.html var date = regexp.MustCompile(`[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]|[0-9][0-9][0-9][0-9]-[0-9][0-9]?-[0-9][0-9]?([Tt]|[ \t]+)[0-9][0-9]?:[0-9][0-9]:[0-9][0-9](\.[0-9]*)?(([ \t]*)Z|[-+][0-9][0-9]?(:[0-9][0-9])?)?`) -func (e *encoder) timev(tag string, in time.Time) { - s, err := in.MarshalText() - if err != nil { - failf("could not marshal text from input time %s: %s", in, err) - } +func (e *encoder) timev(tag string, in reflect.Value) { + m := in.Interface().(encoding.TextMarshaler) + s, _ := m.MarshalText() e.emitScalar(string(s), "", tag, yaml_PLAIN_SCALAR_STYLE) } @@ -319,6 +331,14 @@ func (e *encoder) nilv() { e.emitScalar("null", "", "", yaml_PLAIN_SCALAR_STYLE) } +func (e *encoder) commentv(value []byte) { + e.event = yaml_event_t{ + typ: yaml_COMMENT_EVENT, + value: value, + } + e.emit() +} + func (e *encoder) emitScalar(value, anchor, tag string, style yaml_scalar_style_t) { implicit := tag == "" e.must(yaml_scalar_event_initialize(&e.event, []byte(anchor), []byte(tag), []byte(value), implicit, implicit, style)) diff --git a/vendor/github.com/autrilla/yaml/parserc.go b/vendor/github.com/mozilla-services/yaml.v2/parserc.go similarity index 95% rename from vendor/github.com/autrilla/yaml/parserc.go rename to vendor/github.com/mozilla-services/yaml.v2/parserc.go index 0a7037ad1..b81adc94c 100644 --- a/vendor/github.com/autrilla/yaml/parserc.go +++ b/vendor/github.com/mozilla-services/yaml.v2/parserc.go @@ -92,7 +92,6 @@ func yaml_parser_set_parser_error_context(parser *yaml_parser_t, context string, // State dispatcher. func yaml_parser_state_machine(parser *yaml_parser_t, event *yaml_event_t) bool { //trace("yaml_parser_state_machine", "state:", parser.state.String()) - switch parser.state { case yaml_PARSE_STREAM_START_STATE: return yaml_parser_parse_stream_start(parser, event) @@ -197,7 +196,6 @@ func yaml_parser_parse_stream_start(parser *yaml_parser_t, event *yaml_event_t) // explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END* // ************************* func yaml_parser_parse_document_start(parser *yaml_parser_t, event *yaml_event_t, implicit bool) bool { - token := peek_token(parser) if token == nil { return false @@ -547,6 +545,16 @@ func yaml_parser_parse_node(parser *yaml_parser_t, event *yaml_event_t, block, i } return true } + if token.typ == yaml_COMMENT_TOKEN { + *event = yaml_event_t{ + typ: yaml_COMMENT_EVENT, + value: token.value, + start_mark: token.start_mark, + end_mark: token.end_mark, + } + skip_token(parser) + return true + } if len(anchor) > 0 || len(tag) > 0 { parser.state = parser.states[len(parser.states)-1] parser.states = parser.states[:len(parser.states)-1] @@ -615,6 +623,15 @@ func yaml_parser_parse_block_sequence_entry(parser *yaml_parser_t, event *yaml_e end_mark: token.end_mark, } + skip_token(parser) + return true + } else if token.typ == yaml_COMMENT_TOKEN { + *event = yaml_event_t{ + typ: yaml_COMMENT_EVENT, + value: token.value, + start_mark: token.start_mark, + end_mark: token.end_mark, + } skip_token(parser) return true } @@ -634,7 +651,16 @@ func yaml_parser_parse_indentless_sequence_entry(parser *yaml_parser_t, event *y if token == nil { return false } - + if token.typ == yaml_COMMENT_TOKEN { + *event = yaml_event_t{ + typ: yaml_COMMENT_EVENT, + value: token.value, + start_mark: token.start_mark, + end_mark: token.end_mark, + } + skip_token(parser) + return true + } if token.typ == yaml_BLOCK_ENTRY_TOKEN { mark := token.end_mark skip_token(parser) @@ -712,8 +738,16 @@ func yaml_parser_parse_block_mapping_key(parser *yaml_parser_t, event *yaml_even } skip_token(parser) return true + } else if token.typ == yaml_COMMENT_TOKEN { + *event = yaml_event_t{ + typ: yaml_COMMENT_EVENT, + value: token.value, + start_mark: token.start_mark, + end_mark: token.end_mark, + } + skip_token(parser) + return true } - context_mark := parser.marks[len(parser.marks)-1] parser.marks = parser.marks[:len(parser.marks)-1] return yaml_parser_set_parser_error_context(parser, @@ -739,10 +773,22 @@ func yaml_parser_parse_block_mapping_value(parser *yaml_parser_t, event *yaml_ev if token.typ == yaml_VALUE_TOKEN { mark := token.end_mark skip_token(parser) + oldToken := token token = peek_token(parser) if token == nil { return false } + if token.typ == yaml_COMMENT_TOKEN { + *event = yaml_event_t{ + typ: yaml_COMMENT_EVENT, + value: token.value, + start_mark: token.start_mark, + end_mark: token.end_mark, + } + // Reset the current token to the value token. After this, this function is going to be called again, and we need the first token in the queue to be a VALUE token. A COMMENT token is not a real value, so we essentially "skip" it. + parser.tokens[parser.tokens_head] = *oldToken + return true + } if token.typ != yaml_KEY_TOKEN && token.typ != yaml_VALUE_TOKEN && token.typ != yaml_BLOCK_END_TOKEN { @@ -752,6 +798,7 @@ func yaml_parser_parse_block_mapping_value(parser *yaml_parser_t, event *yaml_ev parser.state = yaml_PARSE_BLOCK_MAPPING_KEY_STATE return yaml_parser_process_empty_scalar(parser, event, mark) } + parser.state = yaml_PARSE_BLOCK_MAPPING_KEY_STATE return yaml_parser_process_empty_scalar(parser, event, token.start_mark) } diff --git a/vendor/github.com/autrilla/yaml/readerc.go b/vendor/github.com/mozilla-services/yaml.v2/readerc.go similarity index 100% rename from vendor/github.com/autrilla/yaml/readerc.go rename to vendor/github.com/mozilla-services/yaml.v2/readerc.go diff --git a/vendor/github.com/autrilla/yaml/resolve.go b/vendor/github.com/mozilla-services/yaml.v2/resolve.go similarity index 100% rename from vendor/github.com/autrilla/yaml/resolve.go rename to vendor/github.com/mozilla-services/yaml.v2/resolve.go diff --git a/vendor/github.com/autrilla/yaml/scannerc.go b/vendor/github.com/mozilla-services/yaml.v2/scannerc.go similarity index 98% rename from vendor/github.com/autrilla/yaml/scannerc.go rename to vendor/github.com/mozilla-services/yaml.v2/scannerc.go index 25808000f..4100698f6 100644 --- a/vendor/github.com/autrilla/yaml/scannerc.go +++ b/vendor/github.com/mozilla-services/yaml.v2/scannerc.go @@ -683,9 +683,11 @@ func yaml_parser_fetch_next_token(parser *yaml_parser_t) bool { return false } - // Check the indentation level against the current column. - if !yaml_parser_unroll_indent(parser, parser.mark.column) { - return false + // Check the indentation level against the current column, only if the current token is not a comment + if parser.buffer[parser.buffer_pos] != '#' { + if !yaml_parser_unroll_indent(parser, parser.mark.column) { + return false + } } // Ensure that the buffer contains at least 4 characters. 4 is the length @@ -794,6 +796,11 @@ func yaml_parser_fetch_next_token(parser *yaml_parser_t) bool { return yaml_parser_fetch_flow_scalar(parser, false) } + // Is it a comment? + if parser.buffer[parser.buffer_pos] == '#' { + return yaml_parser_fetch_comment(parser) + } + // Is it a plain scalar? // // A plain scalar may start with any non-blank characters except @@ -968,7 +975,6 @@ func yaml_parser_unroll_indent(parser *yaml_parser_t, column int) bool { if parser.flow_level > 0 { return true } - // Loop through the indentation levels in the stack. for parser.indent > column { // Create a token and append it to the queue. @@ -1430,6 +1436,29 @@ func yaml_parser_fetch_plain_scalar(parser *yaml_parser_t) bool { return true } +func yaml_parser_fetch_comment(parser *yaml_parser_t) bool { + start_mark := parser.mark + var comment []byte + skip(parser) + for !is_breakz(parser.buffer, parser.buffer_pos) { + comment = read(parser, comment) + if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { + return false + } + } + token := yaml_token_t{ + typ: yaml_COMMENT_TOKEN, + start_mark: start_mark, + end_mark: parser.mark, + value: comment, + style: yaml_PLAIN_SCALAR_STYLE, + } + if parser.parse_comments { + yaml_insert_token(parser, -1, &token) + } + return true +} + // Eat whitespaces and comments until the next token is found. func yaml_parser_scan_to_next_token(parser *yaml_parser_t) bool { @@ -1459,16 +1488,6 @@ func yaml_parser_scan_to_next_token(parser *yaml_parser_t) bool { } } - // Eat a comment until a line break. - if parser.buffer[parser.buffer_pos] == '#' { - for !is_breakz(parser.buffer, parser.buffer_pos) { - skip(parser) - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - } - // If it is a line break, eat it. if is_break(parser.buffer, parser.buffer_pos) { if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { diff --git a/vendor/github.com/autrilla/yaml/sorter.go b/vendor/github.com/mozilla-services/yaml.v2/sorter.go similarity index 100% rename from vendor/github.com/autrilla/yaml/sorter.go rename to vendor/github.com/mozilla-services/yaml.v2/sorter.go diff --git a/vendor/github.com/autrilla/yaml/writerc.go b/vendor/github.com/mozilla-services/yaml.v2/writerc.go similarity index 100% rename from vendor/github.com/autrilla/yaml/writerc.go rename to vendor/github.com/mozilla-services/yaml.v2/writerc.go diff --git a/vendor/github.com/autrilla/yaml/yaml.go b/vendor/github.com/mozilla-services/yaml.v2/yaml.go similarity index 92% rename from vendor/github.com/autrilla/yaml/yaml.go rename to vendor/github.com/mozilla-services/yaml.v2/yaml.go index 36d6b883a..f7ae9340f 100644 --- a/vendor/github.com/autrilla/yaml/yaml.go +++ b/vendor/github.com/mozilla-services/yaml.v2/yaml.go @@ -42,6 +42,28 @@ type Marshaler interface { MarshalYAML() (interface{}, error) } +type CommentUnmarshaler struct{} + +func (u CommentUnmarshaler) Unmarshal(in []byte, out interface{}) (err error) { + defer handleErr(&err) + d := newDecoder() + p := newParser(in) + p.parser.parse_comments = true + defer p.destroy() + node := p.parse() + if node != nil { + v := reflect.ValueOf(out) + if v.Kind() == reflect.Ptr && !v.IsNil() { + v = v.Elem() + } + d.unmarshal(node, v) + } + if len(d.terrors) > 0 { + return &TypeError{d.terrors} + } + return nil +} + // Unmarshal decodes the first document found within the in byte slice // and assigns decoded values into the out value. // @@ -95,6 +117,23 @@ func Unmarshal(in []byte, out interface{}) (err error) { return nil } +type YAMLMarshaler struct { + Indent int +} + +func (m *YAMLMarshaler) Marshal(in interface{}) (out []byte, err error) { + defer handleErr(&err) + if m.Indent == 0 { + m.Indent = 2 + } + e := newEncoderWithIndent(m.Indent) + defer e.destroy() + e.marshal("", reflect.ValueOf(in)) + e.finish() + out = e.out + return +} + // Marshal serializes the value provided into a YAML document. The structure // of the generated document will reflect the structure of the value itself. // Maps and pointers (to struct, string, int, etc) are accepted as the in value. diff --git a/vendor/github.com/autrilla/yaml/yamlh.go b/vendor/github.com/mozilla-services/yaml.v2/yamlh.go similarity index 90% rename from vendor/github.com/autrilla/yaml/yamlh.go rename to vendor/github.com/mozilla-services/yaml.v2/yamlh.go index d60a6b6b0..29410ec31 100644 --- a/vendor/github.com/autrilla/yaml/yamlh.go +++ b/vendor/github.com/mozilla-services/yaml.v2/yamlh.go @@ -1,6 +1,7 @@ package yaml import ( + "fmt" "io" ) @@ -138,6 +139,7 @@ const ( yaml_ANCHOR_TOKEN // An ANCHOR token. yaml_TAG_TOKEN // A TAG token. yaml_SCALAR_TOKEN // A SCALAR token. + yaml_COMMENT_TOKEN ) func (tt yaml_token_type_t) String() string { @@ -186,6 +188,8 @@ func (tt yaml_token_type_t) String() string { return "yaml_TAG_TOKEN" case yaml_SCALAR_TOKEN: return "yaml_SCALAR_TOKEN" + case yaml_COMMENT_TOKEN: + return "yaml_COMMENT_TOKEN" } return "" } @@ -218,6 +222,10 @@ type yaml_token_t struct { major, minor int8 } +func (t *yaml_token_t) String() string { + return fmt.Sprintf("Token(typ=%s, value=%s)", t.typ.String(), string(t.value)) +} + // Events type yaml_event_type_t int8 @@ -237,8 +245,39 @@ const ( yaml_SEQUENCE_END_EVENT // A SEQUENCE-END event. yaml_MAPPING_START_EVENT // A MAPPING-START event. yaml_MAPPING_END_EVENT // A MAPPING-END event. + + yaml_COMMENT_EVENT ) +func (typ yaml_event_type_t) String() string { + switch typ { + case yaml_NO_EVENT: + return "yaml_NO_EVENT" + case yaml_STREAM_END_EVENT: + return "yaml_STREAM_END_EVENT" + case yaml_DOCUMENT_START_EVENT: + return "yaml_DOCUMENT_START_EVENT" + case yaml_DOCUMENT_END_EVENT: + return "yaml_DOCUMENT_END_EVENT" + case yaml_ALIAS_EVENT: + return "yaml_ALIAS_EVENT" + case yaml_SCALAR_EVENT: + return "yaml_SCALAR_EVENT" + case yaml_SEQUENCE_START_EVENT: + return "yaml_SEQUENCE_START_EVENT" + case yaml_SEQUENCE_END_EVENT: + return "yaml_SEQUENCE_END_EVENT" + case yaml_MAPPING_START_EVENT: + return "yaml_MAPPING_START_EVENT" + case yaml_MAPPING_END_EVENT: + return "yaml_MAPPING_END_EVENT" + case yaml_COMMENT_EVENT: + return "yaml_COMMENT_EVENT" + default: + return "UNKNOWN EVENT TYPE" + } +} + // The event structure. type yaml_event_t struct { @@ -570,6 +609,8 @@ type yaml_parser_t struct { aliases []yaml_alias_data_t // The alias data. document *yaml_document_t // The currently parsed document. + + parse_comments bool // Whether to parse comments or not } // Emitter Definitions @@ -616,6 +657,49 @@ const ( yaml_EMIT_END_STATE // Expect nothing. ) +func (state yaml_emitter_state_t) String() string { + switch state { + case yaml_EMIT_STREAM_START_STATE: + return "yaml_EMIT_STREAM_START_STATE" + case yaml_EMIT_FIRST_DOCUMENT_START_STATE: + return "yaml_EMIT_FIRST_DOCUMENT_START_STATE" + case yaml_EMIT_DOCUMENT_START_STATE: + return "yaml_EMIT_DOCUMENT_START_STATE" + case yaml_EMIT_DOCUMENT_CONTENT_STATE: + return "yaml_EMIT_DOCUMENT_CONTENT_STATE" + case yaml_EMIT_DOCUMENT_END_STATE: + return "yaml_EMIT_DOCUMENT_END_STATE" + case yaml_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE: + return "yaml_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE" + case yaml_EMIT_FLOW_SEQUENCE_ITEM_STATE: + return "yaml_EMIT_FLOW_SEQUENCE_ITEM_STATE" + case yaml_EMIT_FLOW_MAPPING_FIRST_KEY_STATE: + return "yaml_EMIT_FLOW_MAPPING_FIRST_KEY_STATE" + case yaml_EMIT_FLOW_MAPPING_KEY_STATE: + return "yaml_EMIT_FLOW_MAPPING_KEY_STATE" + case yaml_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE: + return "yaml_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE" + case yaml_EMIT_FLOW_MAPPING_VALUE_STATE: + return "yaml_EMIT_FLOW_MAPPING_VALUE_STATE" + case yaml_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE: + return "yaml_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE" + case yaml_EMIT_BLOCK_SEQUENCE_ITEM_STATE: + return "yaml_EMIT_BLOCK_SEQUENCE_ITEM_STATE" + case yaml_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE: + return "yaml_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE" + case yaml_EMIT_BLOCK_MAPPING_KEY_STATE: + return "yaml_EMIT_BLOCK_MAPPING_KEY_STATE" + case yaml_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE: + return "yaml_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE" + case yaml_EMIT_BLOCK_MAPPING_VALUE_STATE: + return "yaml_EMIT_BLOCK_MAPPING_VALUE_STATE" + case yaml_EMIT_END_STATE: + return "yaml_EMIT_END_STATE" + default: + return "UNKNOWN_STATE" + } +} + // The emitter structure. // // All members are internal. Manage the structure using the @c yaml_emitter_ diff --git a/vendor/github.com/autrilla/yaml/yamlprivateh.go b/vendor/github.com/mozilla-services/yaml.v2/yamlprivateh.go similarity index 100% rename from vendor/github.com/autrilla/yaml/yamlprivateh.go rename to vendor/github.com/mozilla-services/yaml.v2/yamlprivateh.go