Skip to content

Commit

Permalink
Merge pull request #31 from RezaKargar/feat/multiline-comment
Browse files Browse the repository at this point in the history
Add multiline comment support
  • Loading branch information
kahroba-lang2 authored Feb 4, 2024
2 parents 5959354 + 5bdf323 commit 808fde3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
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 @@ -391,6 +412,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

0 comments on commit 808fde3

Please sign in to comment.