//
// Copyright (c) 2011-2019 Canonical Ltd
// Copyright (c) 2006-2010 Kirill Simonov
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
package yaml
import (
"bytes"
)
// The parser implements the following grammar:
//
// stream ::= STREAM-START implicit_document? explicit_document* STREAM-END
// implicit_document ::= block_node DOCUMENT-END*
// explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END*
// block_node_or_indentless_sequence ::=
// ALIAS
// | properties (block_content | indentless_block_sequence)?
// | block_content
// | indentless_block_sequence
// block_node ::= ALIAS
// | properties block_content?
// | block_content
// flow_node ::= ALIAS
// | properties flow_content?
// | flow_content
// properties ::= TAG ANCHOR? | ANCHOR TAG?
// block_content ::= block_collection | flow_collection | SCALAR
// flow_content ::= flow_collection | SCALAR
// block_collection ::= block_sequence | block_mapping
// flow_collection ::= flow_sequence | flow_mapping
// block_sequence ::= BLOCK-SEQUENCE-START (BLOCK-ENTRY block_node?)* BLOCK-END
// indentless_sequence ::= (BLOCK-ENTRY block_node?)+
// block_mapping ::= BLOCK-MAPPING_START
// ((KEY block_node_or_indentless_sequence?)?
// (VALUE block_node_or_indentless_sequence?)?)*
// BLOCK-END
// flow_sequence ::= FLOW-SEQUENCE-START
// (flow_sequence_entry FLOW-ENTRY)*
// flow_sequence_entry?
// FLOW-SEQUENCE-END
// flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)?
// flow_mapping ::= FLOW-MAPPING-START
// (flow_mapping_entry FLOW-ENTRY)*
// flow_mapping_entry?
// FLOW-MAPPING-END
// flow_mapping_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)?
// Peek the next token in the token queue.
func peek_token(parser *yaml_parser_t) *yaml_token_t {
if parser.token_available || yaml_parser_fetch_more_tokens(parser) {
token := &parser.tokens[parser.tokens_head]
yaml_parser_unfold_comments(parser, token)
return token
}
return nil
}
// yaml_parser_unfold_comments walks through the comments queue and joins all
// comments behind the position of the provided token into the respective
// top-level comment slices in the parser.
func yaml_parser_unfold_comments(parser *yaml_parser_t, token *yaml_token_t) {
for parser.comments_head < len(