| 3 | | -- These are copied directly from the spec, with the addition of the occasional |
| 4 | | -- decision point and commitment. |
| 5 | | |
| 6 | | c_printable = '\x9' |
| 7 | | / '\xA' |
| 8 | | / '\xD' |
| 9 | | / ('\x20', '\x7E') |
| 10 | | / '\x85' |
| 11 | | / ('\xA0', '\xD7FF') |
| 12 | | / ('\xE000', '\xFFFD') |
| 13 | | / ('\x10000', '\x10FFFF') |
| 14 | | |
| 15 | | c_byte_order_mark = '\xFEFF' & detect_utf_encoding |
| 16 | | |
| 17 | | -- Indicators: |
| 18 | | |
| 19 | | c_sequence_entry = indicator '-' |
| 20 | | c_mapping_key = indicator '?' |
| 21 | | c_mapping_value = indicator ':' |
| 22 | | c_collect_entry = indicator ',' |
| 23 | | c_sequence_start = indicator '[' |
| 24 | | c_sequence_end = indicator ']' |
| 25 | | c_mapping_start = indicator '{' |
| 26 | | c_mapping_end = indicator '}' |
| 27 | | c_comment = indicator '#' |
| 28 | | c_anchor = indicator '&' |
| 29 | | c_alias = indicator '*' |
| 30 | | c_tag = indicator '!' |
| 31 | | c_literal = indicator '|' |
| 32 | | c_folded = indicator '>' |
| 33 | | c_single_quote = indicator '\'' |
| 34 | | c_double_quote = indicator '"' |
| 35 | | c_directive = indicator '%' |
| 36 | | c_reserved = indicator ( '@' / '`' ) |
| 37 | | |
| 38 | | c_indicator = c_sequence_entry |
| 39 | | / c_mapping_key |
| 40 | | / c_mapping_value |
| 41 | | / c_collect_entry |
| 42 | | / c_sequence_start |
| 43 | | / c_sequence_end |
| 44 | | / c_mapping_start |
| 45 | | / c_mapping_end |
| 46 | | / c_comment |
| 47 | | / c_anchor |
| 48 | | / c_alias |
| 49 | | / c_tag |
| 50 | | / c_literal |
| 51 | | / c_folded |
| 52 | | / c_single_quote |
| 53 | | / c_double_quote |
| 54 | | / c_directive |
| 55 | | / c_reserved |
| 56 | | |
| 57 | | c_flow_indicator = c_collect_entry |
| 58 | | / c_sequence_start / c_sequence_end |
| 59 | | / c_mapping_start / c_mapping_end |
| 60 | | |
| 61 | | -- Line breaks: |
| 62 | | |
| 63 | | b_line_feed = '\xA' |
| 64 | | b_carriage_return = '\xD' |
| 65 | | b_next_line = '\x85' |
| 66 | | b_line_separator = '\x2028' |
| 67 | | b_paragraph_separator = '\x2029' |
| 68 | | |
| 69 | | b_char = b_line_feed |
| 70 | | / b_carriage_return |
| 71 | | / b_next_line |
| 72 | | / b_line_separator |
| 73 | | / b_paragraph_separator |
| 74 | | |
| 75 | | b_specific = ( b_line_separator / b_paragraph_separator ) |
| 76 | | & nextLine |
| 77 | | |
| 78 | | b_generic = ( b_carriage_return & b_line_feed |
| 79 | | / b_carriage_return |
| 80 | | / b_line_feed |
| 81 | | / b_next_line ) |
| 82 | | & nextLine |
| 83 | | |
| 84 | | b_as_line_feed = token LineFeed b_generic |
| 85 | | b_normalized = b_as_line_feed / token Break b_specific |
| 86 | | b_ignored_generic = token Continue b_generic |
| 87 | | b_ignored_any = b_ignored_generic / token Continue b_specific |
| 88 | | |
| 89 | | -- Chars: |
| 90 | | |
| 91 | | nb_char = c_printable - b_char |
| 92 | | s_space = '\x20' |
| 93 | | s_tab = '\x9' |
| 94 | | s_white = s_space / s_tab |
| 95 | | ns_char = nb_char - s_white |
| 96 | | |
| 97 | | ns_dec_digit = ('\x30', '\x39') |
| 98 | | ns_hex_digit = ns_dec_digit / ('\x41', '\x46') / ('\x61', '\x66') |
| 99 | | ns_ascii_letter = ('\x41', '\x5A') / ('\x61', '\x7A') |
| 100 | | ns_word_char = ns_dec_digit / ns_ascii_letter / '-' |
| 101 | | |
| 102 | | ns_uri_char = "escape" |
| 103 | | ^ ( ns_word_char |
| 104 | | / '%' ! "escape" & ns_hex_digit & ns_hex_digit |
| 105 | | / ';' / '/' / '?' / ':' / '@' / '&' / '=' / '+' / '$' / ',' |
| 106 | | / '_' / '.' / '!' / '~' / '*' / '\'' / '(' / ')' / '[' / ']' ) |
| 107 | | ns_tag_char = ns_uri_char - c_tag |
| 108 | | |
| 109 | | -- Escape: |
| 110 | | |
| 111 | | c_escape = indicator '\\' |
| 112 | | |
| 113 | | ns_esc_null = meta '0' |
| 114 | | ns_esc_bell = meta 'a' |
| 115 | | ns_esc_backspace = meta 'b' |
| 116 | | ns_esc_horizontal_tab = meta ( 't' / '\x9' ) |
| 117 | | ns_esc_line_feed = meta 'n' |
| 118 | | ns_esc_vertical_tab = meta 'v' |
| 119 | | ns_esc_form_feed = meta 'f' |
| 120 | | ns_esc_carriage_return = meta 'r' |
| 121 | | ns_esc_escape = meta 'e' |
| 122 | | ns_esc_space = meta '\x20' |
| 123 | | ns_esc_double_quote = meta '"' |
| 124 | | ns_esc_backslash = meta '\\' |
| 125 | | ns_esc_next_line = meta 'N' |
| 126 | | ns_esc_non_breaking_space = meta '_' |
| 127 | | ns_esc_line_separator = meta 'L' |
| 128 | | ns_esc_paragraph_separator = meta 'P' |
| 129 | | ns_esc_8_bit = indicator 'x' ! "escaped" & meta ( ns_hex_digit % 2 ) |
| 130 | | ns_esc_16_bit = indicator 'u' ! "escaped" & meta ( ns_hex_digit % 4 ) |
| 131 | | ns_esc_32_bit = indicator 'U' ! "escaped" & meta ( ns_hex_digit % 8 ) |
| 132 | | |
| 133 | | ns_esc_char = nest BeginEscape |
| 134 | | & c_escape ! "escape" |
| 135 | | & "escaped" |
| 136 | | ^ ( ns_esc_null |
| 137 | | / ns_esc_bell |
| 138 | | / ns_esc_backspace |
| 139 | | / ns_esc_horizontal_tab |
| 140 | | / ns_esc_line_feed |
| 141 | | / ns_esc_vertical_tab |
| 142 | | / ns_esc_form_feed |
| 143 | | / ns_esc_carriage_return |
| 144 | | / ns_esc_escape |
| 145 | | / ns_esc_space |
| 146 | | / ns_esc_double_quote |
| 147 | | / ns_esc_backslash |
| 148 | | / ns_esc_next_line |
| 149 | | / ns_esc_non_breaking_space |
| 150 | | / ns_esc_line_separator |
| 151 | | / ns_esc_paragraph_separator |
| 152 | | / ns_esc_8_bit |
| 153 | | / ns_esc_16_bit |
| 154 | | / ns_esc_32_bit ) |
| 155 | | & nest EndEscape |
| 156 | | |
| 157 | | -- Spaces: |
| 158 | | |
| 159 | | s_indent n = token Indent ( s_space % n ) |
| 160 | | s_indent_lt n = token Indent ( s_space <% n ) |
| 161 | | s_indent_le n = token Indent ( s_space <% (n .+ 1) ) |
| 162 | | s_separate_in_line = token White ( s_white +) / sol |
| 163 | | |
| 164 | | -- Empty lines |
| 165 | | |
| 166 | | s_ignored_prefix n s = case s of |
| 167 | | Plain -> s_ignored_prefix_flow n |
| 168 | | Double -> s_ignored_prefix_flow n |
| 169 | | Single -> s_ignored_prefix_flow n |
| 170 | | Literal -> s_ignored_prefix_block n |
| 171 | | Folded -> s_ignored_prefix_block n |
| 172 | | |
| 173 | | s_ignored_prefix_flow n = s_indent n & ( s_separate_in_line ?) |
| 174 | | s_ignored_prefix_block n = s_indent n |
| 175 | | |
| 176 | | l_empty n s = ( s_ignored_prefix n s / s_indent_lt n ) & b_normalized |
| 177 | | |
| 178 | | -- Comments: |
| 179 | | |
| 180 | | c_nb_comment_text = nest BeginComment |
| 181 | | & c_comment & meta ( nb_char *) |
| 182 | | & nest EndComment |
| 183 | | |
| 184 | | s_b_comment = ( s_separate_in_line & ( c_nb_comment_text ?) ?) & b_ignored_any |
| 185 | | s_l_comments = ( s_b_comment / sol ) & ( l_comment *) |
| 186 | | l_comment = s_separate_in_line & ( c_nb_comment_text ?) & b_ignored_any |
| 187 | | |
| 188 | | -- Separation: |
| 189 | | |
| 190 | | s_separate n c = case c of |
| 191 | | BlockIn -> s_separate_in_line |
| 192 | | BlockOut -> s_separate_in_line |
| 193 | | FlowOut -> s_separate_lines n |
| 194 | | FlowIn -> s_separate_lines n |
| 195 | | FlowKey -> s_separate_in_line |
| 196 | | |
| 197 | | s_separate_lines n = s_l_comments & s_ignored_prefix_flow n |
| 198 | | / s_separate_in_line |
| 199 | | |
| 200 | | -- Folding: |
| 201 | | |
| 202 | | b_l_folded_specific n s = token Break b_specific & ( l_empty n s *) |
| 203 | | b_l_folded_as_space = token LineFold b_generic |
| 204 | | b_l_folded_trimmed n s = b_ignored_generic & ( l_empty n s +) |
| 205 | | b_l_folded_any n s = b_l_folded_specific n s / b_l_folded_trimmed n s / b_l_folded_as_space |
| 206 | | s_l_flow_folded n = ( s_separate_in_line ?) & b_l_folded_any n Plain |
| 207 | | |
| 208 | | -- Directives: |
| 209 | | |
| 210 | | l_directive = nest BeginDirective |
| 211 | | & c_directive |
| 212 | | & "directive" ^ ( ns_yaml_directive / ns_tag_directive / ns_reserved_directive ) |
| 213 | | & nest EndDirective |
| 214 | | & s_l_comments |
| 215 | | |
| 216 | | ns_reserved_directive = ns_directive_name & ( s_separate_in_line & ns_directive_parameter *) |
| 217 | | ns_directive_name = meta ( ns_char +) |
| 218 | | ns_directive_parameter = meta ( ns_char +) |
| 219 | | |
| 220 | | -- Yaml directive: |
| 221 | | |
| 222 | | ns_yaml_directive = meta [ 'Y', 'A', 'M', 'L' ] ! "directive" |
| 223 | | & s_separate_in_line & ns_yaml_version |
| 224 | | ns_yaml_version = meta ( ( ns_dec_digit +) & '.' & ( ns_dec_digit +) ) |
| 225 | | |
| 226 | | -- Tag directive: |
| 227 | | |
| 228 | | ns_tag_directive = meta [ 'T', 'A', 'G' ] ! "directive" |
| 229 | | & s_separate_in_line & c_tag_handle |
| 230 | | & s_separate_in_line & ns_tag_prefix |
| 231 | | |
| 232 | | c_tag_handle = c_named_tag_handle |
| 233 | | / c_secondary_tag_handle |
| 234 | | / c_primary_tag_handle |
| 235 | | |
| 236 | | c_primary_tag_handle = nest BeginHandle |
| 237 | | & c_tag |
| 238 | | & nest EndHandle |
| 239 | | c_secondary_tag_handle = nest BeginHandle |
| 240 | | & c_tag & c_tag |
| 241 | | & nest EndHandle |
| 242 | | c_named_tag_handle = nest BeginHandle |
| 243 | | & c_tag & meta ( ns_word_char +) & c_tag |
| 244 | | & nest EndHandle |
| 245 | | |
| 246 | | ns_tag_prefix = nest BeginTag |
| 247 | | & ( c_ns_local_tag_prefix / ns_global_tag_prefix ) |
| 248 | | & nest EndTag |
| 249 | | |
| 250 | | c_ns_local_tag_prefix = c_tag & meta ( ns_uri_char *) |
| 251 | | ns_global_tag_prefix = meta ( ns_tag_char & ( ns_uri_char *) ) |
| 252 | | |
| 253 | | -- Properties: |
| 254 | | |
| 255 | | c_ns_properties n c = nest BeginProperties |
| 256 | | & ( ( c_ns_anchor_property & ( s_separate n c & c_ns_tag_property ?) ) |
| 257 | | / ( c_ns_tag_property & ( s_separate n c & c_ns_anchor_property ?) ) ) |
| 258 | | & nest EndProperties |
| 259 | | c_ns_property = c_ns_anchor_property / c_ns_tag_property |
| 260 | | |
| 261 | | -- Tag: |
| 262 | | |
| 263 | | c_ns_tag_property = nest BeginTag |
| 264 | | & ( c_verbatim_tag / c_ns_shorthand_tag / c_non_specific_tag ) |
| 265 | | & nest EndTag |
| 266 | | |
| 267 | | c_verbatim_tag = c_tag & indicator '<' & meta ( ns_uri_char +) & indicator '>' |
| 268 | | c_ns_shorthand_tag = c_named_tag_handle & meta ( ns_uri_char +) |
| 269 | | / c_secondary_tag_handle & meta ( ns_uri_char +) |
| 270 | | / c_primary_tag_handle & meta ( ns_tag_char +) |
| 271 | | c_non_specific_tag = c_tag |
| 272 | | |
| 273 | | -- Anchor: |
| 274 | | |
| 275 | | c_ns_anchor_property = nest BeginAnchor |
| 276 | | & c_anchor & ns_anchor_name |
| 277 | | & nest EndAnchor |
| 278 | | |
| 279 | | ns_anchor_char = ns_char - c_flow_indicator |
| 280 | | ns_anchor_name = meta ( ns_anchor_char +) |
| 281 | | |
| 282 | | -- Double: |
| 283 | | |
| 284 | | nb_double_char = "escape" ^ ( ns_esc_char / nb_char - c_escape - c_double_quote ) |
| 285 | | ns_double_char = nb_double_char - s_white |
| 286 | | |
| 287 | | c_double_quoted n c = nest BeginScalar |
| 288 | | & c_double_quote ! "node" & text ( nb_double_text n c ) & c_double_quote |
| 289 | | & nest EndScalar |
| 290 | | |
| 291 | | nb_double_text n c = case c of |
| 292 | | FlowOut -> s_double_multi n |
| 293 | | FlowIn -> s_double_multi n |
| 294 | | FlowKey -> ( nb_double_char *) |
| 295 | | |
| 296 | | s_double_multi n = ( s_ns_double_chars *) |
| 297 | | & ( s_ns_double_next n *) |
| 298 | | & ( s_white *) |
| 299 | | s_ns_double_chars = ( s_white *) & ns_double_char |
| 300 | | s_ns_double_next n = s_l_double_any n |
| 301 | | & s_ignored_prefix n Double |
| 302 | | & ( ns_double_char & ( s_ns_double_chars *) ?) |
| 303 | | s_l_double_any n = "escape" ^ ( s_b_double_escaped / s_l_flow_folded n ) |
| 304 | | s_b_double_escaped = ( s_white *) |
| 305 | | & nest BeginEscape |
| 306 | | & c_escape ! "escape" |
| 307 | | & b_ignored_any |
| 308 | | & nest EndEscape |
| 309 | | |
| 310 | | -- Single: |
| 311 | | |
| 312 | | c_quoted_quote = nest BeginEscape |
| 313 | | & c_single_quote ! "escape" & meta '\'' |
| 314 | | & nest EndEscape |
| 315 | | nb_single_char = "escape" ^ ( c_quoted_quote / nb_char - c_single_quote ) |
| 316 | | ns_single_char = nb_single_char - s_white |
| 317 | | |
| 318 | | c_single_quoted n c = nest BeginScalar |
| 319 | | & c_single_quote & text ( nb_single_text n c ) & c_single_quote |
| 320 | | & nest EndScalar |
| 321 | | |
| 322 | | nb_single_text n c = case c of |
| 323 | | FlowOut -> s_single_multi n |
| 324 | | FlowIn -> s_single_multi n |
| 325 | | FlowKey -> ( nb_single_char *) |
| 326 | | |
| 327 | | s_ns_single_chars = ( s_white *) & ns_single_char |
| 328 | | s_single_multi n = ( s_ns_single_chars *) |
| 329 | | & ( s_ns_single_next n *) |
| 330 | | & ( s_white *) |
| 331 | | s_ns_single_next n = s_l_flow_folded n |
| 332 | | & s_ignored_prefix n Double |
| 333 | | & ( ns_single_char & ( s_ns_single_chars *) ?) |
| 334 | | |
| 335 | | -- Plain: |
| 336 | | |
| 337 | | ns_plain_safe c = case c of |
| 338 | | FlowOut -> ns_plain_safe_out |
| 339 | | FlowIn -> ns_plain_safe_in |
| 340 | | FlowKey -> ns_plain_safe_in |
| 341 | | |
| 342 | | ns_plain_safe_out = ns_char - c_mapping_value - c_comment |
| 343 | | ns_plain_safe_in = ns_plain_safe_out - c_flow_indicator |
| 344 | | ns_plain_char c = ( ':' +) & ( '#' / ns_plain_safe c ) & ( '#' *) |
| 345 | | / ns_plain_safe c & ( '#' *) |
| 346 | | nb_plain_char c = s_white / ns_plain_char c |
| 347 | | ns_plain_first c = ( '-' / '?' / ':' ) & ( ( '#' +) / ns_plain_char c ) |
| 348 | | / ns_plain_char c - c_indicator |
| 349 | | |
| 350 | | ns_plain n c = nest BeginScalar |
| 351 | | & text (case c of |
| 352 | | FlowOut -> ns_plain_multi n c |
| 353 | | FlowIn -> ns_plain_multi n c |
| 354 | | FlowKey -> ns_plain_single c) |
| 355 | | & nest EndScalar |
| 356 | | |
| 357 | | ns_plain_single c = ns_plain_first c ! "node" & ( s_ns_plain_chars c *) |
| 358 | | s_ns_plain_chars c = ( s_white *) & ns_plain_char c |
| 359 | | ns_plain_multi n c = ns_plain_single c & ( s_ns_plain_next n c *) |
| 360 | | s_ns_plain_next n c = s_l_flow_folded n |
| 361 | | & s_ignored_prefix n Plain |
| 362 | | & ns_plain_char c |
| 363 | | & ( s_ns_plain_chars c *) |
| 364 | | |
| 365 | | -- Flow collection: |
| 366 | | |
| 367 | | in_flow c = case c of |
| 368 | | FlowOut -> FlowIn |
| 369 | | FlowIn -> FlowIn |
| 370 | | FlowKey -> FlowKey |
| 371 | | |
| 372 | | -- Flow sequence: |
| 373 | | |
| 374 | | c_flow_sequence n c = nest BeginSequence |
| 375 | | & c_sequence_start ! "node" |
| 376 | | & ( s_separate n c ?) |
| 377 | | & ( ns_s_flow_seq_entries n (in_flow c) ?) |
| 378 | | & c_sequence_end |
| 379 | | & nest EndSequence |
| 380 | | |
| 381 | | ns_s_flow_seq_entries n c = ns_flow_seq_entry n c |
| 382 | | & ( s_separate n c ?) |
| 383 | | & ( c_collect_entry |
| 384 | | & ( s_separate n c ?) |
| 385 | | & ( ns_s_flow_seq_entries n c ?) ?) |
| 386 | | |
| 387 | | ns_flow_seq_entry n c = "pair" ^ ( ns_flow_pair n c / "node" ^ ns_flow_node n c ) |
| 388 | | |
| 389 | | -- Flow mapping: |
| 390 | | |
| 391 | | c_flow_mapping n c = nest BeginMapping |
| 392 | | & c_mapping_start ! "node" |
| 393 | | & ( s_separate n c ?) |
| 394 | | & ( ns_s_flow_map_entries n (in_flow c) ?) |
| 395 | | & c_mapping_end |
| 396 | | & nest EndMapping |
| 397 | | |
| 398 | | ns_s_flow_map_entries n c = ns_flow_map_entry n c |
| 399 | | & ( s_separate n c ?) |
| 400 | | & ( c_collect_entry |
| 401 | | & ( s_separate n c ?) |
| 402 | | & ( ns_s_flow_map_entries n c ?) ?) |
| 403 | | ns_flow_map_entry n c = nest BeginPair |
| 404 | | & "key" |
| 405 | | ^ ( c_mapping_key ! "key" & s_separate n c & ns_flow_map_explicit_entry n c |
| 406 | | / ns_flow_map_implicit_entry n c ) |
| 407 | | & nest EndPair |
| 408 | | |
| 409 | | ns_flow_map_explicit_entry n c = ns_flow_map_implicit_entry n c |
| 410 | | / e_node & e_node |
| 411 | | ns_flow_map_implicit_entry n c = "pair" |
| 412 | | ^ ( c_ns_flow_map_json_key_entry n c |
| 413 | | / ns_flow_map_yaml_key_entry n c |
| 414 | | / ns_flow_map_empty_key_entry n c ) |
| 415 | | |
| 416 | | c_ns_flow_map_json_key_entry n c = ( "node" ^ c_flow_json_node n c ) ! "pair" |
| 417 | | & ( ( s_separate n c ?) & c_ns_flow_map_adjacent_value n c |
| 418 | | / e_node ) |
| 419 | | ns_flow_map_yaml_key_entry n c = ( "node" ^ ns_flow_yaml_node n c ) ! "pair" |
| 420 | | & ( ( s_separate n c ?) & c_ns_flow_map_separate_value n c |
| 421 | | / e_node ) |
| 422 | | ns_flow_map_empty_key_entry n c = e_node & c_ns_flow_map_separate_value n c |
| 423 | | |
| 424 | | c_ns_flow_map_separate_value n c = c_mapping_value ! "pair" |
| 425 | | & ( s_separate n c & ns_flow_node n c |
| 426 | | / e_node ) |
| 427 | | c_ns_flow_map_adjacent_value n c = c_mapping_value ! "pair" |
| 428 | | & ( ( s_separate n c ?) & ns_flow_node n c |
| 429 | | / e_node ) |
| 430 | | |
| 431 | | ns_flow_pair n c = nest BeginMapping |
| 432 | | & nest BeginPair |
| 433 | | & ( c_mapping_key ! "pair" & s_separate n c & ns_flow_map_explicit_entry n c |
| 434 | | / ns_flow_pair_entry n c ) |
| 435 | | & nest EndPair |
| 436 | | & nest EndMapping |
| 437 | | ns_flow_pair_entry n c = "entry" |
| 438 | | ^ ( c_ns_flow_pair_json_key_entry n c |
| 439 | | / ns_flow_pair_yaml_key_entry n c |
| 440 | | / ns_flow_map_empty_key_entry n c ) |
| 441 | | c_ns_flow_pair_json_key_entry n c = c_s_implicit_json_key & c_ns_flow_map_adjacent_value n c |
| 442 | | ns_flow_pair_yaml_key_entry n c = ns_s_implicit_yaml_key & c_ns_flow_map_separate_value n c |
| 443 | | |
| 444 | | c_s_implicit_json_key = ( "node" ^ ( c_flow_json_node na FlowKey ) & ( s_separate_in_line ?) ) `limitedTo` 1024 |
| 445 | | ns_s_implicit_yaml_key = ( "node" ^ ( ns_flow_yaml_node na FlowKey ) & ( s_separate_in_line ?) ) `limitedTo` 1024 |
| 446 | | |
| 447 | | -- Alias: |
| 448 | | |
| 449 | | c_ns_alias = nest BeginAlias |
| 450 | | & c_alias ! "node" & ns_anchor_name |
| 451 | | & nest EndAlias |
| 452 | | |
| 453 | | -- Empty: |
| 454 | | |
| 455 | | e_scalar = nest BeginScalar & nest EndScalar |
| 456 | | e_node = nest BeginNode & e_scalar & nest EndNode |
| 457 | | |
| 458 | | -- Flow node: |
| 459 | | |
| 460 | | ns_flow_content n c = c_flow_json_content n c |
| 461 | | / ns_flow_yaml_content n c |
| 462 | | c_flow_json_content n c = c_flow_sequence n c |
| 463 | | / c_flow_mapping n c |
| 464 | | / c_single_quoted n c |
| 465 | | / c_double_quoted n c |
| 466 | | ns_flow_yaml_content n c = ns_plain n c |
| 467 | | |
| 468 | | c_flow_json_node n c = nest BeginNode |
| 469 | | & ( c_ns_properties n c & s_separate n c ?) |
| 470 | | & c_flow_json_content n c |
| 471 | | & nest EndNode |
| 472 | | ns_flow_yaml_node n c = nest BeginNode |
| 473 | | & ( c_ns_alias |
| 474 | | / ( c_ns_properties n c |
| 475 | | & ( s_separate n c & ns_flow_yaml_content n c |
| 476 | | / e_scalar ) ) |
| 477 | | / ns_flow_yaml_content n c ) |
| 478 | | & nest EndNode |
| 479 | | ns_flow_node n c = nest BeginNode |
| 480 | | & ( c_ns_alias |
| 481 | | / ( c_ns_properties n c |
| 482 | | & ( s_separate n c & ns_flow_content n c |
| 483 | | / e_scalar ) ) |
| 484 | | / ns_flow_content n c ) |
| 485 | | & nest EndNode |
| 486 | | |
| 487 | | -- Block scalar: |
| 488 | | |
| 489 | | c_indentation_indicator n = indicator ( ns_dec_digit - '0' ) & asInteger |
| 490 | | / detect_scalar_indentation n |
| | 3 | -- These are copied directly from the spec, with the sprinkling of |
| | 4 | -- additional token and decision point directives. |
| | 5 | |
| | 6 | -- 5.1 Character Set |
| | 7 | |
| | 8 | c_printable {- 1 -} = '\x9' / '\xA' / '\xD' / ('\x20', '\x7E') |
| | 9 | / '\x85' / ('\xA0', '\xD7FF') / ('\xE000', '\xFFFD') |
| | 10 | / ('\x10000', '\x10FFFF') |
| | 11 | |
| | 12 | -- 5.2 Character Encodings |
| | 13 | |
| | 14 | c_byte_order_mark {- 2 -} = '\xFEFF' & detect_utf_encoding |
| | 15 | |
| | 16 | -- 5.3 Indicator Characters |
| | 17 | |
| | 18 | c_sequence_entry {- 3 -} = indicator '-' |
| | 19 | c_mapping_key {- 4 -} = indicator '?' |
| | 20 | c_mapping_value {- 5 -} = indicator ':' |
| | 21 | |
| | 22 | c_collect_entry {- 6 -} = indicator ',' |
| | 23 | c_sequence_start {- 7 -} = indicator '[' |
| | 24 | c_sequence_end {- 8 -} = indicator ']' |
| | 25 | c_mapping_start {- 9 -} = indicator '{' |
| | 26 | c_mapping_end {- 10 -} = indicator '}' |
| | 27 | |
| | 28 | c_comment {- 11 -} = indicator '#' |
| | 29 | |
| | 30 | c_anchor {- 12 -} = indicator '&' |
| | 31 | c_alias {- 13 -} = indicator '*' |
| | 32 | c_tag {- 14 -} = indicator '!' |
| | 33 | |
| | 34 | c_literal {- 15 -} = indicator '|' |
| | 35 | c_folded {- 16 -} = indicator '>' |
| | 36 | |
| | 37 | c_single_quote {- 17 -} = indicator '\'' |
| | 38 | c_double_quote {- 18 -} = indicator '"' |
| | 39 | |
| | 40 | c_directive {- 19 -} = indicator '%' |
| | 41 | |
| | 42 | c_reserved {- 20 -} = indicator ( '@' / '`' ) |
| | 43 | |
| | 44 | c_indicator {- 21 -} = c_sequence_entry / c_mapping_key / c_mapping_value / c_collect_entry |
| | 45 | / c_sequence_start / c_sequence_end / c_mapping_start / c_mapping_end |
| | 46 | / c_comment / c_anchor / c_alias / c_tag |
| | 47 | / c_literal / c_folded / c_single_quote / c_double_quote |
| | 48 | / c_directive / c_reserved |
| | 49 | |
| | 50 | -- 5.4 Line Break Characters |
| | 51 | |
| | 52 | b_line_feed {- 22 -} = '\xA' |
| | 53 | b_carriage_return {- 23 -} = '\xD' |
| | 54 | b_next_line {- 24 -} = '\x85' |
| | 55 | b_line_separator {- 25 -} = '\x2028' |
| | 56 | b_paragraph_separator {- 26 -} = '\x2029' |
| | 57 | |
| | 58 | b_char {- 27 -} = b_line_feed / b_carriage_return / b_next_line |
| | 59 | / b_line_separator / b_paragraph_separator |
| | 60 | |
| | 61 | nb_char {- 28 -} = c_printable - b_char |
| | 62 | |
| | 63 | b_specific {- 29 -} = ( b_line_separator / b_paragraph_separator ) |
| | 64 | & nextLine |
| | 65 | |
| | 66 | b_generic {- 30 -} = ( b_carriage_return & b_line_feed |
| | 67 | / b_carriage_return |
| | 68 | / b_line_feed |
| | 69 | / b_next_line ) |
| | 70 | & nextLine |
| | 71 | |
| | 72 | b_as_line_feed {- 31 -} = token LineFeed b_generic |
| | 73 | b_normalized {- 32 -} = b_as_line_feed / token Break b_specific |
| | 74 | |
| | 75 | b_non_content_generic {- 33 -} = token Continue b_generic |
| | 76 | |
| | 77 | b_non_content_any {- 34 -} = b_non_content_generic / token Continue b_specific |
| | 78 | |
| | 79 | -- 5.5 White Space Characters |
| | 80 | |
| | 81 | s_space {- 35 -} = '\x20' |
| | 82 | s_tab {- 36 -} = '\x9' |
| | 83 | s_white {- 37 -} = s_space / s_tab |
| | 84 | |
| | 85 | ns_char {- 38 -} = nb_char - s_white |
| | 86 | |
| | 87 | -- 5.6 Miscellaneous Characters |
| | 88 | |
| | 89 | ns_dec_digit {- 39 -} = ('\x30', '\x39') |
| | 90 | |
| | 91 | ns_hex_digit {- 40 -} = ns_dec_digit |
| | 92 | / ('\x41', '\x46') / ('\x61', '\x66') |
| | 93 | |
| | 94 | ns_ascii_letter {- 41 -} = ('\x41', '\x5A') / ('\x61', '\x7A') |
| | 95 | |
| | 96 | ns_word_char {- 42 -} = ns_dec_digit / ns_ascii_letter / '-' |
| | 97 | |
| | 98 | ns_uri_char {- 43 -} = "escape" |
| | 99 | ^ ( ns_word_char |
| | 100 | / '%' ! "escape" & ns_hex_digit & ns_hex_digit |
| | 101 | / ';' / '/' / '?' / ':' / '@' / '&' / '=' / '+' / '$' / ',' |
| | 102 | / '_' / '.' / '!' / '~' / '*' / '\'' / '(' / ')' / '[' / ']' ) |
| | 103 | |
| | 104 | ns_tag_char {- 44 -} = ns_uri_char - c_tag |
| | 105 | |
| | 106 | -- 5.7 Escaped Characters |
| | 107 | |
| | 108 | c_escape {- 45 -} = indicator '\\' |
| | 109 | |
| | 110 | ns_esc_null {- 46 -} = meta '0' |
| | 111 | ns_esc_bell {- 47 -} = meta 'a' |
| | 112 | ns_esc_backspace {- 48 -} = meta 'b' |
| | 113 | ns_esc_horizontal_tab {- 49 -} = meta ( 't' / '\x9' ) |
| | 114 | ns_esc_line_feed {- 50 -} = meta 'n' |
| | 115 | ns_esc_vertical_tab {- 51 -} = meta 'v' |
| | 116 | ns_esc_form_feed {- 52 -} = meta 'f' |
| | 117 | ns_esc_carriage_return {- 53 -} = meta 'r' |
| | 118 | ns_esc_escape {- 54 -} = meta 'e' |
| | 119 | ns_esc_space {- 55 -} = meta '\x20' |
| | 120 | ns_esc_double_quote {- 56 -} = meta '"' |
| | 121 | ns_esc_backslash {- 57 -} = meta '\\' |
| | 122 | ns_esc_next_line {- 58 -} = meta 'N' |
| | 123 | ns_esc_non_breaking_space {- 59 -} = meta '_' |
| | 124 | ns_esc_line_separator {- 60 -} = meta 'L' |
| | 125 | ns_esc_paragraph_separator {- 61 -} = meta 'P' |
| | 126 | ns_esc_8_bit {- 62 -} = indicator 'x' ! "escaped" & meta ( ns_hex_digit % 2 ) |
| | 127 | ns_esc_16_bit {- 63 -} = indicator 'u' ! "escaped" & meta ( ns_hex_digit % 4 ) |
| | 128 | ns_esc_32_bit {- 64 -} = indicator 'U' ! "escaped" & meta ( ns_hex_digit % 8 ) |
| | 129 | |
| | 130 | c_ns_esc_char {- 65 -} = nest BeginEscape |
| | 131 | & c_escape ! "escape" |
| | 132 | & "escaped" |
| | 133 | ^ ( ns_esc_null |
| | 134 | / ns_esc_bell |
| | 135 | / ns_esc_backspace |
| | 136 | / ns_esc_horizontal_tab |
| | 137 | / ns_esc_line_feed |
| | 138 | / ns_esc_vertical_tab |
| | 139 | / ns_esc_form_feed |
| | 140 | / ns_esc_carriage_return |
| | 141 | / ns_esc_escape |
| | 142 | / ns_esc_space |
| | 143 | / ns_esc_double_quote |
| | 144 | / ns_esc_backslash |
| | 145 | / ns_esc_next_line |
| | 146 | / ns_esc_non_breaking_space |
| | 147 | / ns_esc_line_separator |
| | 148 | / ns_esc_paragraph_separator |
| | 149 | / ns_esc_8_bit |
| | 150 | / ns_esc_16_bit |
| | 151 | / ns_esc_32_bit ) |
| | 152 | & nest EndEscape |
| | 153 | |
| | 154 | -- 6.1 Indentation Spaces |
| | 155 | |
| | 156 | s_indent n {- 66 -} = token Indent ( s_space % n ) |
| | 157 | |
| | 158 | s_indent_lt n {- 67 -} = token Indent ( s_space <% n ) |
| | 159 | s_indent_le n {- 68 -} = token Indent ( s_space <% (n .+ 1) ) |
| | 160 | |
| | 161 | -- 6.2 Separation Spaces |
| | 162 | |
| | 163 | s_separate_in_line {- 69 -} = token White ( s_white +) / sol |
| | 164 | |
| | 165 | -- 6.3 Line Prefixes |
| | 166 | |
| | 167 | s_line_prefix n c {- 70 -} = case c of |
| | 168 | BlockOut -> s_block_line_prefix n |
| | 169 | BlockIn -> s_block_line_prefix n |
| | 170 | FlowOut -> s_flow_line_prefix n |
| | 171 | FlowIn -> s_flow_line_prefix n |
| | 172 | |
| | 173 | s_block_line_prefix n {- 71 -} = s_indent n |
| | 174 | s_flow_line_prefix n {- 72 -} = s_indent n & ( s_separate_in_line ?) |
| | 175 | |
| | 176 | -- 6.4 Empty Lines |
| | 177 | |
| | 178 | l_empty n c {- 73 -} = ( s_line_prefix n c / s_indent_lt n ) |
| | 179 | & b_normalized |
| | 180 | |
| | 181 | -- 6.5 Comments |
| | 182 | |
| | 183 | c_nb_comment_text {- 74 -} = nest BeginComment |
| | 184 | & c_comment & meta ( nb_char *) |
| | 185 | & nest EndComment |
| | 186 | |
| | 187 | s_b_comment {- 75 -} = ( s_separate_in_line & ( c_nb_comment_text ?) ?) |
| | 188 | & b_non_content_any |
| | 189 | |
| | 190 | l_comment {- 76 -} = s_separate_in_line & ( c_nb_comment_text ?) & b_non_content_any |
| | 191 | |
| | 192 | s_l_comments {- 77 -} = ( s_b_comment / sol ) |
| | 193 | & ( l_comment *) |
| | 194 | |
| | 195 | -- 6.6 Separation Lines |
| | 196 | |
| | 197 | s_separate n c {- 78 -} = case c of |
| | 198 | BlockOut -> s_separate_lines n |
| | 199 | BlockIn -> s_separate_lines n |
| | 200 | FlowOut -> s_separate_lines n |
| | 201 | FlowIn -> s_separate_lines n |
| | 202 | FlowKey -> s_separate_in_line |
| | 203 | s_separate_lines n {- 79 -} = s_l_comments & s_flow_line_prefix n |
| | 204 | / s_separate_in_line |
| | 205 | |
| | 206 | -- 6.7 Line Folding |
| | 207 | |
| | 208 | b_l_folded_specific n c {- 80 -} = token Break b_specific & ( l_empty n c *) |
| | 209 | |
| | 210 | b_l_folded_trimmed n c {- 81 -} = b_non_content_generic & ( l_empty n c +) |
| | 211 | |
| | 212 | b_l_folded_as_space {- 82 -} = token LineFold b_generic |
| | 213 | |
| | 214 | b_l_folded_any n c {- 83 -} = b_l_folded_specific n c |
| | 215 | / b_l_folded_trimmed n c |
| | 216 | / b_l_folded_as_space |
| | 217 | |
| | 218 | s_l_flow_folded n {- 84 -} = ( s_separate_in_line ?) & b_l_folded_any n FlowIn |
| | 219 | |
| | 220 | -- 6.8 Directives |
| | 221 | |
| | 222 | l_directive {- 85 -} = nest BeginDirective |