Skip to content

Commit

Permalink
Merge pull request #26 from gobuffalo/line-numbers
Browse files Browse the repository at this point in the history
added support for line numbers in errors fixes #3
  • Loading branch information
markbates authored Dec 22, 2017
2 parents f03aba1 + c2c634d commit 0bf6abd
Show file tree
Hide file tree
Showing 25 changed files with 148 additions and 252 deletions.
11 changes: 2 additions & 9 deletions ast/array_literal.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,14 @@ package ast
import (
"bytes"
"strings"

"github.com/gobuffalo/plush/token"
)

type ArrayLiteral struct {
Token token.Token
TokenAble
Elements []Expression
}

func (al *ArrayLiteral) expressionNode() {
}

func (al *ArrayLiteral) TokenLiteral() string {
return al.Token.Literal
}
func (al *ArrayLiteral) expressionNode() {}

func (al *ArrayLiteral) String() string {
var out bytes.Buffer
Expand Down
15 changes: 15 additions & 0 deletions ast/ast.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
package ast

import "github.com/gobuffalo/plush/token"

type TokenAble struct {
token.Token
}

func (t TokenAble) T() token.Token {
return t.Token
}

func (t TokenAble) TokenLiteral() string {
return t.Token.Literal
}

type Printable interface {
Printable() bool
}

// The base Node interface
type Node interface {
T() token.Token
TokenLiteral() string
String() string
}
Expand Down
10 changes: 5 additions & 5 deletions ast/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ func Test_Program_String(t *testing.T) {
program := &Program{
Statements: []Statement{
&LetStatement{
Token: token.Token{Type: token.LET, Literal: "let"},
TokenAble: TokenAble{token.Token{Type: token.LET, Literal: "let"}},
Name: &Identifier{
Token: token.Token{Type: token.IDENT, Literal: "myVar"},
Value: "myVar",
TokenAble: TokenAble{token.Token{Type: token.IDENT, Literal: "myVar"}},
Value: "myVar",
},
Value: &Identifier{
Token: token.Token{Type: token.IDENT, Literal: "anotherVar"},
Value: "anotherVar",
TokenAble: TokenAble{token.Token{Type: token.IDENT, Literal: "anotherVar"}},
Value: "anotherVar",
},
},
},
Expand Down
11 changes: 2 additions & 9 deletions ast/block_statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,14 @@ package ast

import (
"bytes"

"github.com/gobuffalo/plush/token"
)

type BlockStatement struct {
Token token.Token
TokenAble
Statements []Statement
}

func (bs *BlockStatement) statementNode() {
}

func (bs *BlockStatement) TokenLiteral() string {
return bs.Token.Literal
}
func (bs *BlockStatement) statementNode() {}

func (bs *BlockStatement) String() string {
var out bytes.Buffer
Expand Down
11 changes: 2 additions & 9 deletions ast/boolean.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
package ast

import "github.com/gobuffalo/plush/token"

type Boolean struct {
Token token.Token
TokenAble
Value bool
}

func (b *Boolean) expressionNode() {
}

func (b *Boolean) TokenLiteral() string {
return b.Token.Literal
}
func (b *Boolean) expressionNode() {}

func (b *Boolean) String() string {
return b.Token.Literal
Expand Down
11 changes: 2 additions & 9 deletions ast/call_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,18 @@ package ast
import (
"bytes"
"strings"

"github.com/gobuffalo/plush/token"
)

type CallExpression struct {
Token token.Token
TokenAble
Callee Expression
Function Expression
Arguments []Expression
Block *BlockStatement
ElseBlock *BlockStatement
}

func (ce *CallExpression) expressionNode() {
}

func (ce *CallExpression) TokenLiteral() string {
return ce.Token.Literal
}
func (ce *CallExpression) expressionNode() {}

func (ce *CallExpression) String() string {
var out bytes.Buffer
Expand Down
11 changes: 2 additions & 9 deletions ast/expression_statement.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
package ast

import "github.com/gobuffalo/plush/token"

type ExpressionStatement struct {
Token token.Token
TokenAble
Expression Expression
}

func (es *ExpressionStatement) statementNode() {
}

func (es *ExpressionStatement) TokenLiteral() string {
return es.Token.Literal
}
func (es *ExpressionStatement) statementNode() {}

func (es *ExpressionStatement) String() string {
if es.Expression != nil {
Expand Down
11 changes: 2 additions & 9 deletions ast/float_literal.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
package ast

import "github.com/gobuffalo/plush/token"

type FloatLiteral struct {
Token token.Token
TokenAble
Value float64
}

func (il *FloatLiteral) expressionNode() {
}

func (il *FloatLiteral) TokenLiteral() string {
return il.Token.Literal
}
func (il *FloatLiteral) expressionNode() {}

func (il *FloatLiteral) String() string {
return il.Token.Literal
Expand Down
11 changes: 2 additions & 9 deletions ast/for_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,17 @@ package ast

import (
"bytes"

"github.com/gobuffalo/plush/token"
)

type ForExpression struct {
Token token.Token
TokenAble
KeyName string
ValueName string
Block *BlockStatement
Iterable Expression
}

func (fe *ForExpression) expressionNode() {
}

func (fe *ForExpression) TokenLiteral() string {
return fe.Token.Literal
}
func (fe *ForExpression) expressionNode() {}

func (fe *ForExpression) String() string {
var out bytes.Buffer
Expand Down
10 changes: 2 additions & 8 deletions ast/function_literal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,16 @@ package ast

import (
"bytes"
"github.com/gobuffalo/plush/token"
"strings"
)

type FunctionLiteral struct {
Token token.Token
TokenAble
Parameters []*Identifier
Block *BlockStatement
}

func (fl *FunctionLiteral) expressionNode() {
}

func (fl *FunctionLiteral) TokenLiteral() string {
return fl.Token.Literal
}
func (fl *FunctionLiteral) expressionNode() {}

func (fl *FunctionLiteral) String() string {
var out bytes.Buffer
Expand Down
10 changes: 2 additions & 8 deletions ast/hash_literal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@ package ast

import (
"bytes"
"github.com/gobuffalo/plush/token"
"strings"
)

type HashLiteral struct {
Token token.Token
TokenAble
Pairs map[Expression]Expression
}

func (hl *HashLiteral) expressionNode() {
}

func (hl *HashLiteral) TokenLiteral() string {
return hl.Token.Literal
}
func (hl *HashLiteral) expressionNode() {}

func (hl *HashLiteral) String() string {
var out bytes.Buffer
Expand Down
11 changes: 2 additions & 9 deletions ast/html_literal.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
package ast

import "github.com/gobuffalo/plush/token"

type HTMLLiteral struct {
Token token.Token
TokenAble
Value string
}

func (hl *HTMLLiteral) Printable() bool {
return true
}

func (hl *HTMLLiteral) expressionNode() {
}

func (hl *HTMLLiteral) TokenLiteral() string {
return hl.Token.Literal
}
func (hl *HTMLLiteral) expressionNode() {}

func (hl *HTMLLiteral) String() string {
return hl.Token.Literal
Expand Down
11 changes: 2 additions & 9 deletions ast/identifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,15 @@ package ast

import (
"bytes"

"github.com/gobuffalo/plush/token"
)

type Identifier struct {
Token token.Token
TokenAble
Callee *Identifier
Value string
}

func (i *Identifier) expressionNode() {
}

func (i *Identifier) TokenLiteral() string {
return i.Token.Literal
}
func (i *Identifier) expressionNode() {}

func (i *Identifier) String() string {
out := &bytes.Buffer{}
Expand Down
10 changes: 2 additions & 8 deletions ast/if_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,16 @@ package ast

import (
"bytes"
"github.com/gobuffalo/plush/token"
)

type IfExpression struct {
Token token.Token
TokenAble
Condition Expression
Block *BlockStatement
ElseBlock *BlockStatement
}

func (ie *IfExpression) expressionNode() {
}

func (ie *IfExpression) TokenLiteral() string {
return ie.Token.Literal
}
func (ie *IfExpression) expressionNode() {}

func (ie *IfExpression) String() string {
var out bytes.Buffer
Expand Down
10 changes: 2 additions & 8 deletions ast/index_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@ package ast

import (
"bytes"
"github.com/gobuffalo/plush/token"
)

type IndexExpression struct {
Token token.Token
TokenAble
Left Expression
Index Expression
}

func (ie *IndexExpression) expressionNode() {
}

func (ie *IndexExpression) TokenLiteral() string {
return ie.Token.Literal
}
func (ie *IndexExpression) expressionNode() {}

func (ie *IndexExpression) String() string {
var out bytes.Buffer
Expand Down
11 changes: 2 additions & 9 deletions ast/infix_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,16 @@ package ast

import (
"bytes"

"github.com/gobuffalo/plush/token"
)

type InfixExpression struct {
Token token.Token
TokenAble
Left Expression
Operator string
Right Expression
}

func (oe *InfixExpression) expressionNode() {
}

func (oe *InfixExpression) TokenLiteral() string {
return oe.Token.Literal
}
func (oe *InfixExpression) expressionNode() {}

func (oe *InfixExpression) String() string {
var out bytes.Buffer
Expand Down
Loading

0 comments on commit 0bf6abd

Please sign in to comment.