add a log note for multi-line comments

This commit is contained in:
Evan Wallace
2020-11-15 13:08:31 -08:00
parent be27144450
commit 3f918c65b2
6 changed files with 49 additions and 8 deletions

View File

@@ -195,7 +195,7 @@ func (lexer *lexer) next() {
switch lexer.codePoint {
case '*':
lexer.step()
lexer.consumeToEndOfMultiLineComment()
lexer.consumeToEndOfMultiLineComment(lexer.Token.Range)
continue
case '/':
lexer.step()
@@ -210,9 +210,10 @@ func (lexer *lexer) next() {
if isWhitespace(lexer.codePoint) {
lexer.step()
} else if lexer.codePoint == '/' && lexer.current < len(lexer.source.Contents) && lexer.source.Contents[lexer.current] == '*' {
startRange := logger.Range{Loc: logger.Loc{Start: lexer.Token.Range.End()}, Len: 2}
lexer.step()
lexer.step()
lexer.consumeToEndOfMultiLineComment()
lexer.consumeToEndOfMultiLineComment(startRange)
} else {
break
}
@@ -384,7 +385,7 @@ func (lexer *lexer) next() {
}
}
func (lexer *lexer) consumeToEndOfMultiLineComment() {
func (lexer *lexer) consumeToEndOfMultiLineComment(startRange logger.Range) {
for {
switch lexer.codePoint {
case '*':
@@ -395,7 +396,8 @@ func (lexer *lexer) consumeToEndOfMultiLineComment() {
}
case eof: // This indicates the end of the file
lexer.log.AddError(&lexer.source, logger.Loc{Start: lexer.Token.Range.End()}, "Expected \"*/\" to terminate multi-line comment")
lexer.log.AddErrorWithNotes(&lexer.source, logger.Loc{Start: lexer.Token.Range.End()}, "Expected \"*/\" to terminate multi-line comment",
[]logger.MsgData{logger.RangeData(&lexer.source, startRange, "The multi-line comment starts here")})
return
default:

View File

@@ -122,8 +122,8 @@ func TestURLParsing(t *testing.T) {
}
func TestComment(t *testing.T) {
test.AssertEqual(t, lexerError("/*"), "<stdin>: error: Expected \"*/\" to terminate multi-line comment\n")
test.AssertEqual(t, lexerError("/*/"), "<stdin>: error: Expected \"*/\" to terminate multi-line comment\n")
test.AssertEqual(t, lexerError("/*"), "<stdin>: error: Expected \"*/\" to terminate multi-line comment\n<stdin>: note: The multi-line comment starts here\n")
test.AssertEqual(t, lexerError("/*/"), "<stdin>: error: Expected \"*/\" to terminate multi-line comment\n<stdin>: note: The multi-line comment starts here\n")
test.AssertEqual(t, lexerError("/**/"), "")
test.AssertEqual(t, lexerError("//"), "<stdin>: warning: Comments in CSS use \"/* ... */\" instead of \"//\"\n")
}