Skip to content

Commit 597d3c4

Browse files
authoredJul 7, 2019
Added comments (#1)
Comments start with a `#` and continue until a new line or the end of the program is reached. The comment may be on its own line or at the end of a sentence.
1 parent 938d711 commit 597d3c4

File tree

5 files changed

+62
-2
lines changed

5 files changed

+62
-2
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/.idea
22
/bento
3+
/gh-md-toc

‎README.md

+29
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# 🍱 bento
22

3+
* [Example Use Case](#example-use-case)
4+
* [Language](#language)
5+
* [Sentences](#sentences)
6+
* [Comments](#comments)
7+
* [Examples](#examples)
8+
* [Hello, World!](#hello-world)
9+
310
bento is a
411
[forth-generation programming language](https://en.wikipedia.org/wiki/Fourth-generation_programming_language)
512
that is English-based. It is designed to separate orchestration from
@@ -77,6 +84,28 @@ Did you mean this instead?
7784
Hopefully, they will be able to adjust the script accordingly and resolve it
7885
immediately. Hooray!
7986

87+
# Language
88+
89+
## Sentences
90+
91+
A sentence contains a collection of words and values and it is terminated by a
92+
new line. For example:
93+
94+
```
95+
display "Hello"
96+
```
97+
98+
## Comments
99+
100+
Comments start with a `#` and continue until a new line or the end of the
101+
program is reached. The comment may be on its own line or at the end of a
102+
sentence.
103+
104+
```
105+
# A comment looks like this.
106+
display "Hello" # It can also be here
107+
```
108+
80109
# Examples
81110

82111
## Hello, World!

‎examples/hello-world.bento

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
# Comments start with a hash.
2+
13
display "Hello, World!"

‎token.go

+8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ func Tokenize(r io.Reader) (tokens []Token, err error) {
2828

2929
for i := 0; i < len(entire); i++ {
3030
switch entire[i] {
31+
case '#':
32+
tokens = appendEndline(tokens)
33+
for ; i < len(entire); i++ {
34+
if entire[i] == '\n' {
35+
break
36+
}
37+
}
38+
3139
case '\n':
3240
tokens = appendWord(tokens, &word)
3341
tokens = appendEndline(tokens)

‎token_test.go

+22-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func TestTokenize(t *testing.T) {
1313
expected []Token
1414
}{
1515
"Empty": {
16-
bento: "",
16+
bento: "",
1717
expected: nil,
1818
},
1919
"Word": {
@@ -99,7 +99,27 @@ func TestTokenize(t *testing.T) {
9999
{TokenKindEndline, ""},
100100
},
101101
},
102-
}{
102+
"Comment1": {
103+
bento: "# comment",
104+
expected: nil,
105+
},
106+
"Comment2": {
107+
bento: "# comment\ndisplay",
108+
expected: []Token{
109+
{TokenKindWord, "display"},
110+
{TokenKindEndline, ""},
111+
},
112+
},
113+
"Comment3": {
114+
bento: "display #comment\ndisplay",
115+
expected: []Token{
116+
{TokenKindWord, "display"},
117+
{TokenKindEndline, ""},
118+
{TokenKindWord, "display"},
119+
{TokenKindEndline, ""},
120+
},
121+
},
122+
} {
103123
t.Run(testName, func(t *testing.T) {
104124
actual, err := Tokenize(strings.NewReader(test.bento))
105125
require.NoError(t, err)

0 commit comments

Comments
 (0)
Please sign in to comment.