Skip to content

Commit 3b590ff

Browse files
Chris Manghaneianlancetaylor
authored andcommitted
compiler: Handle newlines in general comments.
On comments, the specification says (http://golang.org/ref/spec#Comments): General comments start with the character sequence /* and continue through the character sequence */. A general comment containing one or more newlines acts like a newline, otherwise it acts like a space. Fixes golang/go#11528. Change-Id: I8a44c68e5b0d41964191c9599493c40d1a1ce500 Reviewed-on: https://go-review.googlesource.com/13064 Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 3bd90ea commit 3b590ff

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

go/lex.cc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,8 +600,14 @@ Lex::next_token()
600600
{
601601
this->lineoff_ = p + 2 - this->linebuf_;
602602
Location location = this->location();
603-
if (!this->skip_c_comment())
603+
bool found_newline = false;
604+
if (!this->skip_c_comment(&found_newline))
604605
return Token::make_invalid_token(location);
606+
if (found_newline && this->add_semi_at_eol_)
607+
{
608+
this->add_semi_at_eol_ = false;
609+
return this->make_operator(OPERATOR_SEMICOLON, 1);
610+
}
605611
p = this->linebuf_ + this->lineoff_;
606612
pend = this->linebuf_ + this->linesize_;
607613
}
@@ -1621,7 +1627,7 @@ Lex::one_character_operator(char c)
16211627
// Skip a C-style comment.
16221628

16231629
bool
1624-
Lex::skip_c_comment()
1630+
Lex::skip_c_comment(bool* found_newline)
16251631
{
16261632
while (true)
16271633
{
@@ -1642,6 +1648,9 @@ Lex::skip_c_comment()
16421648
return true;
16431649
}
16441650

1651+
if (p[0] == '\n')
1652+
*found_newline = true;
1653+
16451654
this->lineoff_ = p - this->linebuf_;
16461655
unsigned int c;
16471656
bool issued_error;

go/lex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ class Lex
469469
one_character_operator(char);
470470

471471
bool
472-
skip_c_comment();
472+
skip_c_comment(bool* found_newline);
473473

474474
void
475475
skip_cpp_comment();

0 commit comments

Comments
 (0)