Skip to content

Commit 8503ad2

Browse files
committed
Fixed typo when looping over dicts
Additional typo fixes
1 parent 905c351 commit 8503ad2

File tree

10 files changed

+31
-52
lines changed

10 files changed

+31
-52
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ tests_random
5151
parser/tracingZeAnnoyingParser.go
5252
testTracing.go
5353
Notes.md
54-
54+
nuru

ast/ast_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func TestString(t *testing.T) {
1010
program := &Program{
1111
Statements: []Statement{
1212
&LetStatement{
13-
Token: token.Token{Type: token.LET, Literal: "acha"},
13+
Token: token.Token{Type: token.LET, Literal: "fanya"},
1414
Name: &Identifier{
1515
Token: token.Token{Type: token.IDENT, Literal: "myVar"},
1616
Value: "myVar",
@@ -23,7 +23,7 @@ func TestString(t *testing.T) {
2323
},
2424
}
2525

26-
if program.String() != "acha myVar = anotherVar;" {
26+
if program.String() != "fanya myVar = anotherVar;" {
2727
t.Errorf("program.String() wrong. got=%q", program.String())
2828
}
2929
}

evaluator/builtins.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -114,27 +114,6 @@ var builtins = map[string]*object.Builtin{
114114
}
115115

116116
return &object.String{Value: string(args[0].Type())}
117-
// switch args[0].(type) {
118-
// case *object.String:
119-
// return &object.String{Value: "NENO (STRING)"}
120-
// case *object.Boolean:
121-
// return &object.String{Value: "BOOLEAN (KWELI AU SIKWELI)"}
122-
// case *object.Builtin:
123-
// return &object.String{Value: "YA_NDANI (Builtin Function)"}
124-
// case *object.Array:
125-
// return &object.String{Value: "ORODHA (Array)"}
126-
// case *object.Function:
127-
// return &object.String{Value: "UNDO (Function)"}
128-
// case *object.Integer:
129-
// return &object.String{Value: "NAMBA (Integer)"}
130-
// case *object.Float:
131-
// return &object.String{Value: "DESIMALI (Float)"}
132-
// case *object.Dict:
133-
// return &object.String{Value: "KAMUSI (Dict)"}
134-
// default:
135-
// return newError("argument to `type` not supported, got=%s",
136-
// args[0].Type())
137-
// }
138117
},
139118
},
140119
}

evaluator/evaluator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ func evalPostfixExpression(env *object.Environment, operator string, node *ast.P
494494
v := arg.Value + 1
495495
return env.Set(node.Token.Literal, &object.Float{Value: v})
496496
default:
497-
return newError("%s sio kitambulishi cha namba. Tumia '++' na kitambulishi cha namba au desimali.\nMfano:\tacha i = 2; i++", node.Token.Literal)
497+
return newError("Mstari %d: %s sio kitambulishi cha namba. Tumia '++' na kitambulishi cha namba au desimali.\nMfano:\tfanya i = 2; i++", node.Token.Line, node.Token.Literal)
498498

499499
}
500500
case "--":
@@ -506,7 +506,7 @@ func evalPostfixExpression(env *object.Environment, operator string, node *ast.P
506506
v := arg.Value - 1
507507
return env.Set(node.Token.Literal, &object.Float{Value: v})
508508
default:
509-
return newError("%s sio kitambulishi cha namba. Tumia '--' na kitambulishi cha namba au desimali.\nMfano:\tacha i = 2; i++", node.Token.Literal)
509+
return newError("Mstari %d: %s sio kitambulishi cha namba. Tumia '--' na kitambulishi cha namba au desimali.\nMfano:\tfanya i = 2; i++", node.Token.Line, node.Token.Literal)
510510
}
511511
default:
512512
return newError("Haifahamiki: %s", operator)

examples/example.nr

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
andika("Testing basic types...");
22
andika(2 + 2);
33
andika(4 * 4);
4-
acha a = 10;
5-
acha b = 20;
4+
fanya a = 10;
5+
fanya b = 20;
66

77
andika(a + b);
88

@@ -15,23 +15,23 @@ andika("Mambo vipi");
1515

1616
andika("Testing Functions... ");
1717

18-
acha jumlisha = fn(x, y) {x + y};
18+
fanya jumlisha = unda(x, y) {x + y};
1919

2020
andika(jumlisha(20,30));
2121
andika(jumlisha(100,1000));
2222

23-
acha zidisha = fn(x, y) {x * y};
23+
fanya zidisha = unda(x, y) {x * y};
2424

2525
andika(zidisha(100,1000));
2626
andika(zidisha(200, 20));
2727

2828
// lists can hold any value
2929
andika("Testing lists...");
30-
acha list = [1, "a", kweli, sikweli];
30+
fanya list = [1, "a", kweli, sikweli];
3131

3232
// a few builtins
3333

34-
acha list = sukuma(list, jumlisha(4,5));
34+
fanya list = sukuma(list, jumlisha(4,5));
3535

3636
andika(list);
3737
andika(list[2]);
@@ -57,7 +57,7 @@ kama (idadi("Habari") == 6) {
5757
// fibonacci example
5858
andika("Testing fibonacci...");
5959

60-
acha fibo = fn(x) {
60+
fanya fibo = unda(x) {
6161
kama (x == 0) {
6262
rudisha 0;
6363
} au kama (x == 1) {
@@ -72,8 +72,8 @@ andika(fibo(10));
7272

7373
// testing input
7474
andika("Testing input from user...");
75-
acha salamu = fn() {
76-
acha jina = jaza("Unaitwa nani rafiki? ");
75+
fanya salamu = unda() {
76+
fanya jina = jaza("Unaitwa nani rafiki? ");
7777
rudisha "Mambo vipi " + jina;
7878
}
7979

@@ -87,7 +87,7 @@ Multiline comment
8787

8888
andika("Testing dictionaries...")
8989

90-
acha watu = [{"jina": "Mojo", "kabila": "Mnyakusa"}, {"jina": "Avi", "kabila": "Mwarabu wa dubai"}]
90+
fanya watu = [{"jina": "Mojo", "kabila": "Mnyakusa"}, {"jina": "Avi", "kabila": "Mwarabu wa dubai"}]
9191

9292
andika(watu, watu[0], watu[0]["jina"], watu[0]["kabila"])
9393

@@ -99,7 +99,7 @@ andika({"a":1} + {"b": 2})
9999

100100
andika("Testing while loop...");
101101

102-
acha i = 10;
102+
fanya i = 10;
103103

104104
wakati (i > 0) {
105105
andika(i);

lexer/lexer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import (
55
)
66

77
type Lexer struct {
8-
input string // string or runes. Runes should be better.
8+
input string
99
position int
1010
readPosition int
11-
ch byte // make this a rune too
11+
ch byte
1212
line int
1313
}
1414

lexer/lexer_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import (
99
func TestNextToken(t *testing.T) {
1010
input := `
1111
// Testing kama lex luther iko sawa
12-
acha tano = 5;
13-
acha kumi = 10;
12+
fanya tano = 5;
13+
fanya kumi = 10;
1414
15-
acha jumla = fn(x, y){
15+
fanya jumla = unda(x, y){
1616
x + y;
1717
};
1818
19-
acha jibu = jumla(tano, kumi);
19+
fanya jibu = jumla(tano, kumi);
2020
2121
!-/5;
2222
5 < 10 > 5;
@@ -46,20 +46,20 @@ func TestNextToken(t *testing.T) {
4646
expectedType token.TokenType
4747
expectedLiteral string
4848
}{
49-
{token.LET, "acha"},
49+
{token.LET, "fanya"},
5050
{token.IDENT, "tano"},
5151
{token.ASSIGN, "="},
5252
{token.INT, "5"},
5353
{token.SEMICOLON, ";"},
54-
{token.LET, "acha"},
54+
{token.LET, "fanya"},
5555
{token.IDENT, "kumi"},
5656
{token.ASSIGN, "="},
5757
{token.INT, "10"},
5858
{token.SEMICOLON, ";"},
59-
{token.LET, "acha"},
59+
{token.LET, "fanya"},
6060
{token.IDENT, "jumla"},
6161
{token.ASSIGN, "="},
62-
{token.FUNCTION, "fn"},
62+
{token.FUNCTION, "unda"},
6363
{token.LPAREN, "("},
6464
{token.IDENT, "x"},
6565
{token.COMMA, ","},
@@ -72,7 +72,7 @@ func TestNextToken(t *testing.T) {
7272
{token.SEMICOLON, ";"},
7373
{token.RBRACE, "}"},
7474
{token.SEMICOLON, ";"},
75-
{token.LET, "acha"},
75+
{token.LET, "fanya"},
7676
{token.IDENT, "jibu"},
7777
{token.ASSIGN, "="},
7878
{token.IDENT, "jumla"},

object/object.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func (f *Function) Inspect() string {
9898
params = append(params, p.String())
9999
}
100100

101-
out.WriteString("fn")
101+
out.WriteString("unda")
102102
out.WriteString("(")
103103
out.WriteString(strings.Join(params, ", "))
104104
out.WriteString(") {\n")
@@ -252,7 +252,7 @@ func (d *Dict) Next() (Object, Object) {
252252
return nil, nil
253253
}
254254

255-
func (d *Dict) Resest() {
255+
func (d *Dict) Reset() {
256256
d.offset = 0
257257
}
258258

parser/parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func (p *Parser) parseAssignmentExpression(exp ast.Expression) ast.Expression {
198198
switch node := exp.(type) {
199199
case *ast.Identifier, *ast.IndexExpression:
200200
default:
201-
msg := fmt.Sprintf("Tulitegemea kupata kitambulishi au array, badala yake tumepata: %T %#v", node, exp)
201+
msg := fmt.Sprintf("Mstari %d:Tulitegemea kupata kitambulishi au array, badala yake tumepata: %s %s", p.curToken.Line, p.prevToken.Type, node.TokenLiteral())
202202
p.errors = append(p.errors, msg)
203203
return nil
204204
}

token/token.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const (
5656

5757
// Keywords
5858
FUNCTION = "FUNCTION"
59-
LET = "ACHA"
59+
LET = "FANYA"
6060
TRUE = "KWELI"
6161
FALSE = "SIKWELI"
6262
IF = "KAMA"

0 commit comments

Comments
 (0)