diff options
author | ridiculousfish <corydoras@ridiculousfish.com> | 2014-09-29 11:29:50 -0700 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2014-09-29 11:30:21 -0700 |
commit | 27dd37ebb4c660ab122ece69bc187b36e390b25b (patch) | |
tree | 9e89fdd3c6e8692bba41f398ca3388673101a831 /fish_tests.cpp | |
parent | a186f04f15773b4595d0e359d1e27a903a68d3f7 (diff) |
Fix to indent comments in blocks properly (#1710)
This makes two changes to parse trees:
1. Unmaterialized nodes no longer have an invalid source location
For example, with the code `while false;end` there are no tokens
associated with the while loop's job_list, and therefore it is
unmaterialized. Previously it would have had a SOURCE_OFFSET_INVALID.
But now it has a zero source length, but an offset equal to the end of
the while loop (i.e. the semicolon), and a zero length. Correspondingly,
the has_source function now checks the length instead of the offset.
2. Special (comment and error) nodes have always been "disconnected,"
meaning they are not the child of any other node. However, they now have
their parent offsets set to whatever the top of the node stack was when
the node was encountered. This gives us a sense of which node the
comment is "in", e.g. if we are constructing a job list then the
comment's parent will be the job list. This lets us determine the
comment's indent.
Diffstat (limited to 'fish_tests.cpp')
-rw-r--r-- | fish_tests.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/fish_tests.cpp b/fish_tests.cpp index 7c2de13a..0ec8bf7b 100644 --- a/fish_tests.cpp +++ b/fish_tests.cpp @@ -896,9 +896,17 @@ static void test_indents() {NULL, -1} }; + const indent_component_t components12[] = + { + {L"while false", 0}, + {L"# comment", 1}, //comment indentation handling + {L"command", 1}, //comment indentation handling + {L"# comment2", 1}, //comment indentation handling + {NULL, -1} + }; - const indent_component_t *tests[] = {components1, components2, components3, components4, components5, components6, components7, components8, components9, components10, components11}; + const indent_component_t *tests[] = {components1, components2, components3, components4, components5, components6, components7, components8, components9, components10, components11, components12}; for (size_t which = 0; which < sizeof tests / sizeof *tests; which++) { const indent_component_t *components = tests[which]; |