Skip to content

Commit

Permalink
tokenizer: support comments
Browse files Browse the repository at this point in the history
  • Loading branch information
StunxFS committed Nov 25, 2024
1 parent 6df4050 commit 4160ae2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/compiler/tokenizer/mod.v
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,30 @@ fn (mut t Tokenizer) internal_next() token.Token {
}
}
match ch {
`/` {
if nextc == `/` {
t.ignore_line()
continue
} else if nextc == `*` {
start_pos := t.pos
t.pos++
for t.pos < t.text.len - 1 {
t.pos++
if t.current_char() == lf {
t.inc_line_number()
continue
} else if t.matches('*/', t.pos) {
t.pos++
break
}
}
if t.pos >= t.text.len {
t.pos = start_pos
report.error('comment not terminated', t.current_pos())
}
continue
}
}
`'` {
return token.Token{
lit: t.read_char()
Expand Down
File renamed without changes.
8 changes: 7 additions & 1 deletion test.ri
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ fn main 123 123.0 0x123abc 0b10101 0o1234

// Test file

fn main() {}
fn main() {}

/* multi-line comment
usb - pc - laptop
*/

fn set_current_dir(){}

0 comments on commit 4160ae2

Please sign in to comment.