Skip to content

Commit 1ca757b

Browse files
committed
go: Rename Declartion to Decl
Rename Declartion to Decl for consistency with FuncDecl and the upcoming TypedDecl and InferredDecl.
1 parent 0e3dd6c commit 1ca757b

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

pkg/evaluator/evaluator.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ func (e *Evaluator) Eval(node parser.Node) Value {
6868
switch node := node.(type) {
6969
case *parser.Program:
7070
return e.evalProgram(node)
71-
case *parser.Declaration:
72-
return e.evalDeclaration(node)
71+
case *parser.Decl:
72+
return e.evalDecl(node)
7373
case *parser.AssignmentStmt:
7474
return e.evalAssignment(node)
7575
case *parser.Var:
@@ -170,7 +170,7 @@ func (e *Evaluator) evalBool(b *parser.Bool) Value {
170170
return &Bool{Val: b.Value}
171171
}
172172

173-
func (e *Evaluator) evalDeclaration(decl *parser.Declaration) Value {
173+
func (e *Evaluator) evalDecl(decl *parser.Decl) Value {
174174
val := e.Eval(decl.Value)
175175
if isError(val) {
176176
return val

pkg/evaluator/evaluator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestBasicEval(t *testing.T) {
2424
assert.Equal(t, want, got)
2525
}
2626

27-
func TestParseDeclaration(t *testing.T) {
27+
func TestParseDecl(t *testing.T) {
2828
tests := map[string]string{
2929
"a:=1": "1",
3030
`a:="abc"`: "abc",

pkg/parser/ast.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ type DotExpression struct {
6060
Key string // m := { age: 42}; m.age => key: "age"
6161
}
6262

63-
type Declaration struct {
63+
type Decl struct {
6464
Token *lexer.Token
6565
Var *Var
6666
Value Node // literal, expression, assignable, ...
@@ -249,14 +249,14 @@ func (d *DotExpression) Type() *Type {
249249
return d.T
250250
}
251251

252-
func (d *Declaration) String() string {
252+
func (d *Decl) String() string {
253253
if d.Value == nil {
254254
return d.Var.String()
255255
}
256256
return d.Var.String() + "=" + d.Value.String()
257257
}
258258

259-
func (d *Declaration) Type() *Type {
259+
func (d *Decl) Type() *Type {
260260
return d.Var.T
261261
}
262262

pkg/parser/parser.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,10 @@ func (p *Parser) parseTypedDeclStatement(scope *scope) Node {
407407

408408
// parseTypedDecl parses declarations like
409409
// `x:num` or `y:any[]{}`.
410-
func (p *Parser) parseTypedDecl() *Declaration {
410+
func (p *Parser) parseTypedDecl() *Decl {
411411
p.assertToken(lexer.IDENT)
412412
varName := p.cur.Literal
413-
decl := &Declaration{
413+
decl := &Decl{
414414
Token: p.cur,
415415
Var: &Var{Token: p.cur, Name: varName},
416416
}
@@ -448,7 +448,7 @@ func (p *Parser) validateVarDecl(scope *scope, v *Var, tok *lexer.Token, allowUn
448448
func (p *Parser) parseInferredDeclStatement(scope *scope) Node {
449449
p.assertToken(lexer.IDENT)
450450
varName := p.cur.Literal
451-
decl := &Declaration{
451+
decl := &Decl{
452452
Token: p.cur,
453453
Var: &Var{Token: p.cur, Name: varName},
454454
}

pkg/parser/parser_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"foxygo.at/evy/pkg/assert"
88
)
99

10-
func TestParseDeclaration(t *testing.T) {
10+
func TestParseDecl(t *testing.T) {
1111
tests := map[string][]string{
1212
"a := 1": {"a=1"},
1313
"a:bool": {"a=false"},
@@ -62,7 +62,7 @@ func TestEmptyProgram(t *testing.T) {
6262
}
6363
}
6464

65-
func TestParseDeclarationError(t *testing.T) {
65+
func TestParseDeclError(t *testing.T) {
6666
tests := map[string]string{
6767
"a :invalid": "line 1 column 1: invalid type declaration for 'a'",
6868
"a :": "line 1 column 1: invalid type declaration for 'a'",

0 commit comments

Comments
 (0)