scanner: fix scanning empty inline comment
This commit is contained in:
parent
8d6affdd68
commit
983c721e83
@ -8358,12 +8358,11 @@ yyrule127: // ([/][*])|([/][*][*])
|
||||
if c == -1 {
|
||||
break // TODO: Unterminated comment starting line %d
|
||||
}
|
||||
p := c
|
||||
c = l.Next()
|
||||
if rune(p) == '*' && rune(c) == '/' {
|
||||
if l.Prev.Rune == '*' && l.Last.Rune == '/' {
|
||||
c = l.Next()
|
||||
break
|
||||
}
|
||||
c = l.Next()
|
||||
}
|
||||
lval.Token(l.newToken(l.Token()))
|
||||
if is_doc_comment {
|
||||
|
@ -307,13 +307,12 @@ NEW_LINE (\r|\n|\r\n)
|
||||
break; // TODO: Unterminated comment starting line %d
|
||||
}
|
||||
|
||||
p := c
|
||||
c = l.Next()
|
||||
|
||||
if rune(p) == '*' && rune(c) == '/' {
|
||||
if l.Prev.Rune == '*' && l.Last.Rune == '/' {
|
||||
c = l.Next()
|
||||
break;
|
||||
}
|
||||
|
||||
c = l.Next()
|
||||
}
|
||||
|
||||
lval.Token(l.newToken(l.Token()))
|
||||
|
@ -955,3 +955,57 @@ func TestCommentWithPhpEndTag(t *testing.T) {
|
||||
|
||||
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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user