Repository navigation
Commit 6b5f079
authored
Render an emptied array of tables as an empty array (#567)
* Render an emptied array of tables as an empty array
_render_aot looped over the AoT body to emit [[key]] headers, so an array
of tables with no elements left rendered as nothing at all and the key was
dropped from the output.
Fall back to the inline `key = []` form, matching what an empty array built
through the API already renders as.
TOML only reads bare key/value pairs before the first table header, so these
keys are hoisted there; left in body order an emptied array of tables sitting
after a table would be parsed back as a key of that table. Non-empty arrays
of tables are unaffected and still render in place.
* Render an emptied nested array of tables with its bare key
The inline `key = []` fallback is a bare key/value pair emitted inside the
scope its `[[header]]` named, so applying the render prefix nested the key
under itself: an emptied `[[t.a]]` rendered as `[t]` / `t.a = []`, which
reads back as `t.t.a`. Drop the prefix for the fallback.
Bare pairs are also read into whichever table the closest preceding header
opened, so the existing root-level hoisting has to happen in every table
body, not just the document body. Factor it into `_hoist_empty_aots` and
apply it in `_render_table` and `_render_aot_table` too.
Five parametrized regressions assert `parse(doc.as_string()).unwrap() ==
doc.unwrap()` across nesting under a table, either side of a sibling
sub-table, two levels down, and inside an array-of-tables element.
* Render an emptied array of tables relative to its nearest header
An emptied array of tables falls back to the inline `key = []` form, which
is a bare key/value pair: TOML reads it into whichever table the closest
preceding header opened. The fallback was written with a bare key and left
in body order, so it only landed in the right table when its parent had an
explicit header of its own and nothing else came first.
Collect the fallbacks of a scope up front instead, walking through the
super tables that emit no header, and key each one relative to the scope
that will read it. `[[t.a]]` with no `[t]` now renders `t.a = []` rather
than moving the key to the root, and `[[t.u.a]]` under `[t]` renders
`u.a = []` rather than `t.u.a = []`, which reparsed as `t.t.u.a`.1 parent 229ee86 commit 6b5f079
2 files changed
Lines changed: 195 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1698 | 1698 | | |
1699 | 1699 | | |
1700 | 1700 | | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
| 1706 | + | |
| 1707 | + | |
| 1708 | + | |
| 1709 | + | |
| 1710 | + | |
| 1711 | + | |
| 1712 | + | |
| 1713 | + | |
| 1714 | + | |
| 1715 | + | |
| 1716 | + | |
| 1717 | + | |
| 1718 | + | |
| 1719 | + | |
| 1720 | + | |
| 1721 | + | |
| 1722 | + | |
| 1723 | + | |
| 1724 | + | |
| 1725 | + | |
| 1726 | + | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + | |
| 1730 | + | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
| 1763 | + | |
| 1764 | + | |
| 1765 | + | |
| 1766 | + | |
| 1767 | + | |
| 1768 | + | |
| 1769 | + | |
| 1770 | + | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
| 1779 | + | |
| 1780 | + | |
| 1781 | + | |
| 1782 | + | |
| 1783 | + | |
| 1784 | + | |
| 1785 | + | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
35 | 105 | | |
36 | 106 | | |
37 | 107 | | |
| |||
639 | 709 | | |
640 | 710 | | |
641 | 711 | | |
| 712 | + | |
| 713 | + | |
642 | 714 | | |
643 | 715 | | |
| 716 | + | |
| 717 | + | |
644 | 718 | | |
645 | 719 | | |
646 | 720 | | |
| |||
675 | 749 | | |
676 | 750 | | |
677 | 751 | | |
678 | | - | |
679 | | - | |
680 | | - | |
681 | | - | |
682 | | - | |
683 | | - | |
684 | | - | |
685 | | - | |
686 | | - | |
687 | | - | |
688 | | - | |
689 | | - | |
690 | | - | |
691 | | - | |
692 | | - | |
693 | | - | |
694 | | - | |
695 | | - | |
| 752 | + | |
| 753 | + | |
696 | 754 | | |
697 | 755 | | |
698 | 756 | | |
| |||
713 | 771 | | |
714 | 772 | | |
715 | 773 | | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
716 | 779 | | |
717 | | - | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
718 | 783 | | |
719 | 784 | | |
720 | 785 | | |
| |||
773 | 838 | | |
774 | 839 | | |
775 | 840 | | |
| 841 | + | |
| 842 | + | |
776 | 843 | | |
777 | | - | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
778 | 847 | | |
779 | 848 | | |
780 | 849 | | |
| |||
0 commit comments