Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multiline comment support #31

Merged
merged 2 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions 1_lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ package main
import (
"bufio"
"io"
"log"
"strings"
"unicode"
)
Expand Down Expand Up @@ -255,6 +256,26 @@ func (l *lexer) lex() {
l.lex()
}

func (l *lexer) lexMultiLineComment() {
for {
str, err := l.reader.ReadString('*')
_ = str
if err != nil {
log.Fatal(err)
return
}
nextChar, _, err := l.reader.ReadRune()
if err != nil {
log.Fatal(err)
return
}
if nextChar == '/' {
break
}
l.reader.UnreadRune()
}
}

/*
این متد وظیفه ساخت یک توکن با نوع و مقدار مورد نظر و اضافه کردن به چنل توکن ها را به عهده دارد
*/
Expand Down Expand Up @@ -382,6 +403,10 @@ func (l *lexer) lexSymbol(r rune) {
l.reader.ReadLine()
return
}
if doubleCharSymbol == "/*" {
l.lexMultiLineComment()
return
}
if t, ok := symobls[singleCharSymbol]; ok {
l.reader.UnreadRune()
l.emit(t, singleCharSymbol)
Expand Down
10 changes: 10 additions & 0 deletions docs/en_readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,21 @@ $ go build

## Comments

### Single line comment:
Like most of languages, you can use // to define your comments, they won't get interpreted:
```rust
// This is my first program in Kahroba programming language, Let's Rock!
```

### Multiline comment:
You can also have multiline comments in your code, codes within multiline comment block won't get interpreted:
```rust
/*
This is my first program in Kahroba programming language,
Let's Rock!
*/
```

## Strings
You can define string using double quotation:
```rust
Expand Down