Skip to content

Commit

Permalink
[docgen] don't consider lines with only WS for common indent detection (
Browse files Browse the repository at this point in the history
#2131)

fixes #2130
  • Loading branch information
mfelsche authored and SeanTAllen committed Aug 4, 2017
1 parent dbd777a commit 9bbcaeb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/libponyc/ast/lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ static void normalise_string(lexer_t* lexer)
size_t ws = lexer->buflen;
size_t ws_this_line = 0;
bool in_leading_ws = true;
bool has_non_ws = false;

for(size_t i = 0; i < lexer->buflen; i++)
{
Expand All @@ -555,7 +556,10 @@ static void normalise_string(lexer_t* lexer)
}
else
{
if(ws_this_line < ws)
if(!isspace(c))
has_non_ws = true;

if(has_non_ws && (ws_this_line < ws))
ws = ws_this_line;

in_leading_ws = false;
Expand All @@ -565,6 +569,7 @@ static void normalise_string(lexer_t* lexer)
if(c == '\n')
{
ws_this_line = 0;
has_non_ws = false;
in_leading_ws = true;
}
}
Expand Down
9 changes: 9 additions & 0 deletions test/libponyc/lexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,15 @@ TEST_F(LexerTest, TripleStringWithLeadingEmptyLine)
DO(test(src));
}

TEST_F(LexerTest, TripleStringWithLeadingEmptyLineAndIndentedFirstLine)
{
const char* src = "\"\"\"\n Foo\n\n bar\"\"\"";

expect(1, 1, TK_STRING, "Foo\n\nbar");
expect(4, 9, TK_EOF, "EOF");
DO(test(src));
}


TEST_F(LexerTest, TripleStringWithNonLeadingEmptyLine)
{
Expand Down

0 comments on commit 9bbcaeb

Please sign in to comment.