scanner: fix scanning empty inline comment

This commit is contained in:
z7zmey 2018-04-11 00:58:57 +03:00
parent 8d6affdd68
commit 983c721e83
3 changed files with 59 additions and 7 deletions

View File

@ -8358,12 +8358,11 @@ yyrule127: // ([/][*])|([/][*][*])
if c == -1 { if c == -1 {
break // TODO: Unterminated comment starting line %d break // TODO: Unterminated comment starting line %d
} }
p := c if l.Prev.Rune == '*' && l.Last.Rune == '/' {
c = l.Next()
if rune(p) == '*' && rune(c) == '/' {
c = l.Next() c = l.Next()
break break
} }
c = l.Next()
} }
lval.Token(l.newToken(l.Token())) lval.Token(l.newToken(l.Token()))
if is_doc_comment { if is_doc_comment {

View File

@ -307,13 +307,12 @@ NEW_LINE (\r|\n|\r\n)
break; // TODO: Unterminated comment starting line %d break; // TODO: Unterminated comment starting line %d
} }
p := c if l.Prev.Rune == '*' && l.Last.Rune == '/' {
c = l.Next()
if rune(p) == '*' && rune(c) == '/' {
c = l.Next() c = l.Next()
break; break;
} }
c = l.Next()
} }
lval.Token(l.newToken(l.Token())) lval.Token(l.newToken(l.Token()))

View File

@ -955,3 +955,57 @@ func TestCommentWithPhpEndTag(t *testing.T) {
assertEqual(t, expected, actual) assertEqual(t, expected, actual)
} }
func TestInlineComment(t *testing.T) {
src := `<?php
/*test*/`
expected := []comment.Comment{
comment.NewPlainComment("/*test*/"),
}
lexer := scanner.NewLexer(bytes.NewBufferString(src), "test.php")
lv := &lval{}
lexer.Lex(lv)
actual := lexer.Comments
assertEqual(t, expected, actual)
}
func TestEmptyInlineComment(t *testing.T) {
src := `<?php
/**/`
expected := []comment.Comment{
comment.NewDocComment("/**/"),
}
lexer := scanner.NewLexer(bytes.NewBufferString(src), "test.php")
lv := &lval{}
lexer.Lex(lv)
actual := lexer.Comments
assertEqual(t, expected, actual)
}
func TestEmptyInlineComment2(t *testing.T) {
src := `<?php
/***/`
expected := []comment.Comment{
comment.NewDocComment("/***/"),
}
lexer := scanner.NewLexer(bytes.NewBufferString(src), "test.php")
lv := &lval{}
lexer.Lex(lv)
actual := lexer.Comments
assertEqual(t, expected, actual)
}