(parser *yaml_parser_t, scan_mark yaml_mark_t)
| 2883 | } |
| 2884 | |
| 2885 | func yaml_parser_scan_comments(parser *yaml_parser_t, scan_mark yaml_mark_t) bool { |
| 2886 | token := parser.tokens[len(parser.tokens)-1] |
| 2887 | |
| 2888 | if token.typ == yaml_FLOW_ENTRY_TOKEN && len(parser.tokens) > 1 { |
| 2889 | token = parser.tokens[len(parser.tokens)-2] |
| 2890 | } |
| 2891 | |
| 2892 | var token_mark = token.start_mark |
| 2893 | var start_mark yaml_mark_t |
| 2894 | var next_indent = parser.indent |
| 2895 | if next_indent < 0 { |
| 2896 | next_indent = 0 |
| 2897 | } |
| 2898 | |
| 2899 | var recent_empty = false |
| 2900 | var first_empty = parser.newlines <= 1 |
| 2901 | |
| 2902 | var line = parser.mark.line |
| 2903 | var column = parser.mark.column |
| 2904 | |
| 2905 | var text []byte |
| 2906 | |
| 2907 | // The foot line is the place where a comment must start to |
| 2908 | // still be considered as a foot of the prior content. |
| 2909 | // If there's some content in the currently parsed line, then |
| 2910 | // the foot is the line below it. |
| 2911 | var foot_line = -1 |
| 2912 | if scan_mark.line > 0 { |
| 2913 | foot_line = parser.mark.line-parser.newlines+1 |
| 2914 | if parser.newlines == 0 && parser.mark.column > 1 { |
| 2915 | foot_line++ |
| 2916 | } |
| 2917 | } |
| 2918 | |
| 2919 | var peek = 0 |
| 2920 | for ; peek < 512; peek++ { |
| 2921 | if parser.unread < peek+1 && !yaml_parser_update_buffer(parser, peek+1) { |
| 2922 | break |
| 2923 | } |
| 2924 | column++ |
| 2925 | if is_blank(parser.buffer, parser.buffer_pos+peek) { |
| 2926 | continue |
| 2927 | } |
| 2928 | c := parser.buffer[parser.buffer_pos+peek] |
| 2929 | var close_flow = parser.flow_level > 0 && (c == ']' || c == '}') |
| 2930 | if close_flow || is_breakz(parser.buffer, parser.buffer_pos+peek) { |
| 2931 | // Got line break or terminator. |
| 2932 | if close_flow || !recent_empty { |
| 2933 | if close_flow || first_empty && (start_mark.line == foot_line && token.typ != yaml_VALUE_TOKEN || start_mark.column-1 < next_indent) { |
| 2934 | // This is the first empty line and there were no empty lines before, |
| 2935 | // so this initial part of the comment is a foot of the prior token |
| 2936 | // instead of being a head for the following one. Split it up. |
| 2937 | // Alternatively, this might also be the last comment inside a flow |
| 2938 | // scope, so it must be a footer. |
| 2939 | if len(text) > 0 { |
| 2940 | if start_mark.column-1 < next_indent { |
| 2941 | // If dedented it's unrelated to the prior token. |
| 2942 | token_mark = start_mark |
no test coverage detected