comments yay
This commit is contained in:
15
README.md
15
README.md
@@ -30,6 +30,17 @@ const x int = 9;
|
|||||||
```
|
```
|
||||||
---
|
---
|
||||||
|
|
||||||
|
### Comments
|
||||||
|
|
||||||
|
Comments in One start with a # and end with another # or a newline
|
||||||
|
|
||||||
|
```
|
||||||
|
#this is a comment
|
||||||
|
let a #this is also a comment# int = 9;
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
### Scopes
|
### Scopes
|
||||||
|
|
||||||
Like in most languages, variables in One are only limited to their scope.
|
Like in most languages, variables in One are only limited to their scope.
|
||||||
@@ -62,7 +73,7 @@ let x int = 3
|
|||||||
let y real = 5.5;
|
let y real = 5.5;
|
||||||
print(y);
|
print(y);
|
||||||
}
|
}
|
||||||
print("y is now undefined again here");
|
#y is now undefined again here
|
||||||
{
|
{
|
||||||
let y real = 0.2;
|
let y real = 0.2;
|
||||||
print(y);
|
print(y);
|
||||||
@@ -223,7 +234,7 @@ The 'main' function must always return `int` and does not accept any arguments.
|
|||||||
|
|
||||||
```
|
```
|
||||||
fn main() int {
|
fn main() int {
|
||||||
print("my code here");
|
#my code here
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
13
lexer.v
13
lexer.v
@@ -116,8 +116,8 @@ fn toktype_from_kw(kw string) TokenType {
|
|||||||
|
|
||||||
fn is_delimiter(c u8, is_inside_number bool) bool {
|
fn is_delimiter(c u8, is_inside_number bool) bool {
|
||||||
valid_chars := match is_inside_number {
|
valid_chars := match is_inside_number {
|
||||||
true {" +-*/,;:%<>()[]{}=\n\""}
|
true {" #+-*/,;:%<>()[]{}=\n\""}
|
||||||
false {". +-*/,;:%<>()[]{}=\n\""}
|
false {". #+-*/,;:%<>()[]{}=\n\""}
|
||||||
}
|
}
|
||||||
return valid_chars.contains(c.ascii_str())
|
return valid_chars.contains(c.ascii_str())
|
||||||
}
|
}
|
||||||
@@ -150,8 +150,16 @@ fn lex(input string) ?[]Token {
|
|||||||
mut tokens := []Token{}
|
mut tokens := []Token{}
|
||||||
mut is_inside_number := false
|
mut is_inside_number := false
|
||||||
mut is_inside_string := false
|
mut is_inside_string := false
|
||||||
|
mut is_inside_comment := false
|
||||||
|
|
||||||
for (right < input.len && left <= right) {
|
for (right < input.len && left <= right) {
|
||||||
|
for is_inside_comment {
|
||||||
|
right++
|
||||||
|
if ['#', '\n'].contains(input[right].ascii_str()) {
|
||||||
|
is_inside_comment = false
|
||||||
|
}
|
||||||
|
left = right
|
||||||
|
}
|
||||||
for is_inside_string {
|
for is_inside_string {
|
||||||
right++
|
right++
|
||||||
if input[right].ascii_str() == '\"' {
|
if input[right].ascii_str() == '\"' {
|
||||||
@@ -174,6 +182,7 @@ fn lex(input string) ?[]Token {
|
|||||||
if is_delimiter(input[right], is_inside_number) && left == right {
|
if is_delimiter(input[right], is_inside_number) && left == right {
|
||||||
if !input[right].is_space() {
|
if !input[right].is_space() {
|
||||||
if input[right].ascii_str() == '\"' {is_inside_string = true; continue}
|
if input[right].ascii_str() == '\"' {is_inside_string = true; continue}
|
||||||
|
if input[right].ascii_str() == '#' {is_inside_comment = true; continue}
|
||||||
mut tok_str := input[right].ascii_str()
|
mut tok_str := input[right].ascii_str()
|
||||||
if right + 1 < input.len {
|
if right + 1 < input.len {
|
||||||
combined := input.substr(right, right + 2)
|
combined := input.substr(right, right + 2)
|
||||||
|
|||||||
Reference in New Issue
Block a user