scanner: fix nested multiline comments (#10760)

pull/10772/head
yuyi 2021-07-12 12:17:38 +08:00 committed by GitHub
parent ba9b53cc4d
commit 719bf63f16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -983,7 +983,7 @@ fn (mut s Scanner) text_scan() token.Token {
s.pos++ s.pos++
return s.new_token(.div_assign, '', 2) return s.new_token(.div_assign, '', 2)
} }
if nextc == `/` { if nextc == `/` { // Single line comments
start := s.pos + 1 start := s.pos + 1
s.ignore_line() s.ignore_line()
mut comment_line_end := s.pos mut comment_line_end := s.pos
@ -1014,12 +1014,11 @@ fn (mut s Scanner) text_scan() token.Token {
// s.fgenln('// ${s.prev_tok.str()} "$s.line_comment"') // s.fgenln('// ${s.prev_tok.str()} "$s.line_comment"')
// Skip the comment (return the next token) // Skip the comment (return the next token)
continue continue
} } else if nextc == `*` { // Multiline comments
// Multiline comments
if nextc == `*` {
start := s.pos + 2 start := s.pos + 2
start_line := s.line_nr start_line := s.line_nr
mut nest_count := 1 mut nest_count := 1
s.pos++
// Skip comment // Skip comment
for nest_count > 0 && s.pos < s.text.len - 1 { for nest_count > 0 && s.pos < s.text.len - 1 {
s.pos++ s.pos++

View File

@ -0,0 +1,5 @@
fn test_nested_multiline_comments() {
/*//println(os.args)
*/
assert true
}