Skip to content

Commit

Permalink
fix: allow closing flow seq/map at same indentation
Browse files Browse the repository at this point in the history
The commit as written does not include running tree-sitter generate.
Happy to run that if someone can point me to the documentation for how
that can be done for the current iteration of the repo.

Resolves: ikatyang#29
Relates-to: #2
  • Loading branch information
rliebz committed Mar 27, 2024
1 parent 9e59b9b commit 27ac51f
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 8 deletions.
12 changes: 6 additions & 6 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ module.exports = grammar({
$._r_blk_fld_bgn, $._br_blk_fld_bgn, // >
$._br_blk_str_ctn, // block scalar content
$._r_flw_seq_bgn, $._br_flw_seq_bgn, $._b_flw_seq_bgn, // [
$._r_flw_seq_end, $._br_flw_seq_end, // ]
$._r_flw_seq_end, $._br_flw_seq_end, $._b_flw_seq_end, // ]
$._r_flw_map_bgn, $._br_flw_map_bgn, $._b_flw_map_bgn, // {
$._r_flw_map_end, $._br_flw_map_end, // }
$._r_flw_map_end, $._br_flw_map_end, $._b_flw_map_end, // }
$._r_flw_sep_bgn, $._br_flw_sep_bgn, // ,
$._r_flw_key_bgn, $._br_flw_key_bgn, // ?
$._r_flw_jsv_bgn, $._br_flw_jsv_bgn, // : (json key)
Expand Down Expand Up @@ -298,7 +298,7 @@ module.exports = grammar({
_br_sgl_flw_seq: $ => seq($._br_flw_seq_bgn, $._sgl_flw_seq_tal),
_b_sgl_flw_seq: $ => seq($._b_flw_seq_bgn, $._sgl_flw_seq_tal),

_flw_seq_tal: $ => seq(optional(choice($._r_flw_seq_dat, $._br_flw_seq_dat)), choice($._r_flw_seq_end, $._br_flw_seq_end)),
_flw_seq_tal: $ => seq(optional(choice($._r_flw_seq_dat, $._br_flw_seq_dat)), choice($._r_flw_seq_end, $._br_flw_seq_end, $._b_flw_seq_end)),
_sgl_flw_seq_tal: $ => seq(optional($._r_sgl_flw_col_dat), $._r_flw_seq_end),

// flow mapping
Expand All @@ -317,7 +317,7 @@ module.exports = grammar({
_br_sgl_flw_map: $ => seq($._br_flw_map_bgn, $._sgl_flw_map_tal),
_b_sgl_flw_map: $ => seq($._b_flw_map_bgn, $._sgl_flw_map_tal),

_flw_map_tal: $ => seq(optional(choice($._r_flw_map_dat, $._br_flw_map_dat)), choice($._r_flw_map_end, $._br_flw_map_end)),
_flw_map_tal: $ => seq(optional(choice($._r_flw_map_dat, $._br_flw_map_dat)), choice($._r_flw_map_end, $._br_flw_map_end, $._b_flw_map_end)),
_sgl_flw_map_tal: $ => seq(optional($._r_sgl_flw_col_dat), $._r_flw_map_end),

// flow collection data
Expand Down Expand Up @@ -529,9 +529,9 @@ module.exports.grammar = global_alias(global_alias(module.exports.grammar, {
..._("|", "_r_blk_lit_bgn", "_br_blk_lit_bgn"),
..._(">", "_r_blk_fld_bgn", "_br_blk_fld_bgn"),
..._("[", "_r_flw_seq_bgn", "_br_flw_seq_bgn", "_b_flw_seq_bgn"),
..._("]", "_r_flw_seq_end", "_br_flw_seq_end"),
..._("]", "_r_flw_seq_end", "_br_flw_seq_end", "_b_flw_seq_end"),
..._("{", "_r_flw_map_bgn", "_br_flw_map_bgn", "_b_flw_map_bgn"),
..._("}", "_r_flw_map_end", "_br_flw_map_end"),
..._("}", "_r_flw_map_end", "_br_flw_map_end", "_b_flw_map_end"),
..._(",", "_r_flw_sep_bgn", "_br_flw_sep_bgn"),
..._("?", "_r_flw_key_bgn", "_br_flw_key_bgn"),
..._(":", "_r_flw_jsv_bgn", "_br_flw_jsv_bgn"),
Expand Down
14 changes: 12 additions & 2 deletions src/scanner.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 82 additions & 0 deletions test/corpus/spec.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1664,6 +1664,49 @@ Flow Mapping
(plain_scalar
(string_scalar))))))))

================================================================================
Flow Mapping Closed at Original Indentation
================================================================================
first: {
foo: you,
bar: far
}
second: 2

--------------------------------------------------------------------------------

(stream
(document
(block_node
(block_mapping
(block_mapping_pair
key: (flow_node
(plain_scalar
(string_scalar)))
value: (flow_node
(flow_mapping
(flow_pair
key: (flow_node
(plain_scalar
(string_scalar)))
value: (flow_node
(plain_scalar
(string_scalar))))
(flow_pair
key: (flow_node
(plain_scalar
(string_scalar)))
value: (flow_node
(plain_scalar
(string_scalar)))))))
(block_mapping_pair
key: (flow_node
(plain_scalar
(string_scalar)))
value: (flow_node
(plain_scalar
(integer_scalar))))))))

================================================================================
Flow mapping colon on line after key
================================================================================
Expand Down Expand Up @@ -1761,6 +1804,45 @@ Flow Sequence
(plain_scalar
(integer_scalar)))))))

================================================================================
Flow Sequence Closed at Original Indentation
================================================================================
first: [
foo,
b,
42
]
second: 2

--------------------------------------------------------------------------------

(stream
(document
(block_node
(block_mapping
(block_mapping_pair
key: (flow_node
(plain_scalar
(string_scalar)))
value: (flow_node
(flow_sequence
(flow_node
(plain_scalar
(string_scalar)))
(flow_node
(plain_scalar
(string_scalar)))
(flow_node
(plain_scalar
(integer_scalar))))))
(block_mapping_pair
key: (flow_node
(plain_scalar
(string_scalar)))
value: (flow_node
(plain_scalar
(integer_scalar))))))))

================================================================================
Flow Sequence in Block Mapping
================================================================================
Expand Down

0 comments on commit 27ac51f

Please sign in to comment.