Skip to content

Commit

Permalink
Move package expression -> expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
osteele committed Jul 14, 2017
1 parent bad5593 commit 6ff5721
Show file tree
Hide file tree
Showing 31 changed files with 57 additions and 54 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ clean: ## remove binary files
rm -f ${LIB} ${CMD}

deps: ## list dependencies
go list -f '{{join .Imports "\n"}}' ./... | grep -v ${PACKAGE} | grep '\.' | sort | uniq
go list -f '{{join .Deps "\n"}}' ./... | grep -v `go list -f '{{.ImportPath}}'` | grep '\.' | sort | uniq

imports: ## list imports
go list -f '{{join .Imports "\n"}}' ./... | grep -v `go list -f '{{.ImportPath}}'` | grep '\.' | sort | uniq

generate:
go generate ./...
Expand All @@ -26,7 +29,7 @@ setup: ## install dependencies and development tools
gometalinter --install

lint: ## lint the package
gometalinter ./... --deadline=5m --exclude expression/scanner.go --exclude y.go --exclude '.*_string.go' --disable=gotype
gometalinter ./... --deadline=5m --exclude expressions/scanner.go --exclude y.go --exclude '.*_string.go' --disable=gotype
@echo lint passed

test: ## test the package
Expand Down
2 changes: 1 addition & 1 deletion expression/builders.go → expressions/builders.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package expression
package expressions

import (
"fmt"
Expand Down
4 changes: 2 additions & 2 deletions expression/config.go → expressions/config.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package expression
package expressions

// Config holds configuration information for expression interpretation.
type Config struct {
filters map[string]interface{}
}

// NewConfig creates a new Settings.
// NewConfig creates a new Config.
func NewConfig() Config {
return Config{}
}
2 changes: 1 addition & 1 deletion expression/context.go → expressions/context.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package expression
package expressions

// Context is the expression evaluation context. It maps variables names to values.
type Context interface {
Expand Down
2 changes: 1 addition & 1 deletion expression/drops.go → expressions/drops.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package expression
package expressions

type drop interface {
ToLiquid() interface{}
Expand Down
4 changes: 2 additions & 2 deletions expression/expressions.go → expressions/expressions.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Package expression parses and evaluates the expression language.
// Package expressions parses and evaluates the expression language.
//
// This is the language that is used inside Liquid object and tags; e.g. "a.b[c]" in {{ a.b[c] }}, and "pages = site.pages | reverse" in {% assign pages = site.pages | reverse %}.
package expression
package expressions

import (
"github.com/osteele/liquid/evaluator"
Expand Down
2 changes: 1 addition & 1 deletion expression/expressions.y → expressions/expressions.y
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
%{
package expression
package expressions
import (
"fmt"
"github.com/osteele/liquid/evaluator"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package expression
package expressions

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion expression/filters.go → expressions/filters.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package expression
package expressions

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion expression/filters_test.go → expressions/filters_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package expression
package expressions

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion expression/functional.go → expressions/functional.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package expression
package expressions

type expressionWrapper struct {
fn func(ctx Context) (interface{}, error)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package expression
package expressions

import (
"testing"
Expand Down
2 changes: 1 addition & 1 deletion expression/parser.go → expressions/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//go:generate gofmt -w scanner.go
//go:generate goyacc expressions.y

package expression
package expressions

import "fmt"

Expand Down
2 changes: 1 addition & 1 deletion expression/parser_test.go → expressions/parser_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package expression
package expressions

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion expression/scanner.go → expressions/scanner.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//line scanner.rl:1
package expression
package expressions

import "strconv"

Expand Down
2 changes: 1 addition & 1 deletion expression/scanner.rl → expressions/scanner.rl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package expression
package expressions

import "strconv"

Expand Down
2 changes: 1 addition & 1 deletion expression/scanner_test.go → expressions/scanner_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package expression
package expressions

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion expression/statements.go → expressions/statements.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package expression
package expressions

// These strings match lexer tokens.
const (
Expand Down
2 changes: 1 addition & 1 deletion expression/y.go → expressions/y.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//line expressions.y:2
package expression
package expressions

import __yyfmt__ "fmt"

Expand Down
8 changes: 4 additions & 4 deletions filters/standard_filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"
"time"

"github.com/osteele/liquid/expression"
"github.com/osteele/liquid/expressions"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -203,13 +203,13 @@ func TestFilters(t *testing.T) {
)
filterTestBindings["dup_maps"] = []interface{}{m1, m2, m1, m3}

settings := expression.NewConfig()
settings := expressions.NewConfig()
AddStandardFilters(&settings)
context := expression.NewContext(filterTestBindings, settings)
context := expressions.NewContext(filterTestBindings, settings)

for i, test := range filterTests {
t.Run(fmt.Sprintf("%02d", i+1), func(t *testing.T) {
actual, err := expression.EvaluateString(test.in, context)
actual, err := expressions.EvaluateString(test.in, context)
require.NoErrorf(t, err, test.in)
expected := test.expected
switch v := actual.(type) {
Expand Down
6 changes: 3 additions & 3 deletions liquid.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package liquid

import (
"github.com/osteele/liquid/evaluator"
"github.com/osteele/liquid/expression"
"github.com/osteele/liquid/expressions"
"github.com/osteele/liquid/parser"
"github.com/osteele/liquid/render"
)
Expand Down Expand Up @@ -43,9 +43,9 @@ func IsTemplateError(err error) bool {
// now that interface calls return SourceError
case evaluator.TypeError:
return true
case expression.InterpreterError:
case expressions.InterpreterError:
return true
case expression.ParseError:
case expressions.ParseError:
return true
case parser.Error:
return true
Expand Down
4 changes: 2 additions & 2 deletions parser/ast.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package parser

import (
"github.com/osteele/liquid/expression"
"github.com/osteele/liquid/expressions"
)

// ASTNode is a node of an AST.
Expand Down Expand Up @@ -37,7 +37,7 @@ type ASTText struct {
// ASTObject is an {{ object }} object.
type ASTObject struct {
Token
Expr expression.Expression
Expr expressions.Expression
}

// ASTSeq is a sequence of nodes.
Expand Down
4 changes: 2 additions & 2 deletions parser/config.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package parser

import "github.com/osteele/liquid/expression"
import "github.com/osteele/liquid/expressions"

// A Config holds configuration information for parsing and rendering.
type Config struct {
expression.Config
expressions.Config
Grammar Grammar
SourcePath string
LineNo int
Expand Down
4 changes: 2 additions & 2 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"strings"

"github.com/osteele/liquid/expression"
"github.com/osteele/liquid/expressions"
)

// Parse parses a source template. It returns an AST root, that can be compiled and evaluated.
Expand Down Expand Up @@ -49,7 +49,7 @@ func (c Config) parseTokens(tokens []Token) (ASTNode, Error) { // nolint: gocycl
rawTag.Slices = append(rawTag.Slices, tok.Source)
}
case tok.Type == ObjTokenType:
expr, err := expression.Parse(tok.Args)
expr, err := expressions.Parse(tok.Args)
if err != nil {
return nil, WrapError(err, tok)
}
Expand Down
2 changes: 1 addition & 1 deletion parser/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Token struct {
// TokenType is the type of a Chunk
type TokenType int

//go:generate stringer -type=TokenType
////go:generate stringer -type=TokenType

const (
// TextTokenType is the type of a text Chunk
Expand Down
10 changes: 5 additions & 5 deletions render/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"io/ioutil"
"strings"

"github.com/osteele/liquid/expression"
"github.com/osteele/liquid/expressions"
)

// Context provides the rendering context for a tag renderer.
Expand All @@ -20,7 +20,7 @@ type Context interface {
// Use this to distinguish template errors from implementation errors.
Errorf(format string, a ...interface{}) Error
// Evaluate evaluates an expression within the template context.
Evaluate(expr expression.Expression) (interface{}, error)
Evaluate(expr expressions.Expression) (interface{}, error)
// Evaluate compiles and interprets an expression, such as “x”, “x < 10", or “a.b | split | first | default: 10”, within the current lexical context.
EvaluateString(source string) (interface{}, error)
// ExpandTagArg renders the current tag argument string as a Liquid template.
Expand Down Expand Up @@ -60,7 +60,7 @@ func (c rendererContext) WrapError(err error) Error {
return wrapRenderError(err, c.node)
}

func (c rendererContext) Evaluate(expr expression.Expression) (out interface{}, err error) {
func (c rendererContext) Evaluate(expr expressions.Expression) (out interface{}, err error) {
return c.ctx.Evaluate(expr)
}

Expand All @@ -69,15 +69,15 @@ func (c rendererContext) EvaluateString(source string) (out interface{}, err err
defer func() {
if r := recover(); r != nil {
switch e := r.(type) {
case expression.InterpreterError:
case expressions.InterpreterError:
err = e
default:
// fmt.Println(string(debug.Stack()))
panic(fmt.Errorf("%s during evaluation of %s", e, source))
}
}
}()
return expression.EvaluateString(source, expression.NewContext(c.ctx.bindings, c.ctx.config.Config.Config))
return expressions.EvaluateString(source, expressions.NewContext(c.ctx.bindings, c.ctx.config.Config.Config))
}

// Get gets a variable value within an evaluation context.
Expand Down
8 changes: 4 additions & 4 deletions render/node_context.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package render

import (
"github.com/osteele/liquid/expression"
"github.com/osteele/liquid/expressions"
)

// nodeContext provides the evaluation context for rendering the AST.
Expand Down Expand Up @@ -34,17 +34,17 @@ func (c nodeContext) Clone() nodeContext {
}

// Evaluate evaluates an expression within the template context.
func (c nodeContext) Evaluate(expr expression.Expression) (out interface{}, err error) {
func (c nodeContext) Evaluate(expr expressions.Expression) (out interface{}, err error) {
defer func() {
if r := recover(); r != nil {
switch e := r.(type) {
case expression.InterpreterError:
case expressions.InterpreterError:
err = e
default:
// fmt.Println(string(debug.Stack()))
panic(e)
}
}
}()
return expr.Evaluate(expression.NewContext(c.bindings, c.config.Config.Config))
return expr.Evaluate(expressions.NewContext(c.bindings, c.config.Config.Config))
}
4 changes: 2 additions & 2 deletions render/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package render
import (
"io"

"github.com/osteele/liquid/expression"
"github.com/osteele/liquid/expressions"
"github.com/osteele/liquid/parser"
)

Expand Down Expand Up @@ -41,7 +41,7 @@ type TextNode struct {
// ObjectNode is an {{ object }} object.
type ObjectNode struct {
parser.Token
expr expression.Expression
expr expressions.Expression
}

// SeqNode is a sequence of nodes.
Expand Down
2 changes: 1 addition & 1 deletion tags/control_flow_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"io"

"github.com/osteele/liquid/evaluator"
e "github.com/osteele/liquid/expression"
e "github.com/osteele/liquid/expressions"
"github.com/osteele/liquid/render"
)

Expand Down
8 changes: 4 additions & 4 deletions tags/iteration_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"reflect"
"regexp"

"github.com/osteele/liquid/expression"
"github.com/osteele/liquid/expressions"
"github.com/osteele/liquid/render"
)

Expand All @@ -33,7 +33,7 @@ func continueTag(string) (func(io.Writer, render.Context) error, error) {
}

func cycleTag(args string) (func(io.Writer, render.Context) error, error) {
stmt, err := expression.ParseStatement(expression.CycleStatementSelector, args)
stmt, err := expressions.ParseStatement(expressions.CycleStatementSelector, args)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -64,7 +64,7 @@ func loopTagParser(node render.BlockNode) (func(io.Writer, render.Context) error
if m := loopRepairMatcher.FindStringSubmatch(src); m != nil {
src = m[1] + " .. " + m[2]
}
stmt, err := expression.ParseStatement(expression.LoopStatementSelector, src)
stmt, err := expressions.ParseStatement(expressions.LoopStatementSelector, src)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -114,7 +114,7 @@ func loopTagParser(node render.BlockNode) (func(io.Writer, render.Context) error
}, nil
}

func applyLoopModifiers(loop expression.Loop, iter iterable) iterable {
func applyLoopModifiers(loop expressions.Loop, iter iterable) iterable {
if loop.Reversed {
iter = reverseWrapper{iter}
}
Expand Down
Loading

0 comments on commit 6ff5721

Please sign in to comment.