1
0
mirror of https://github.com/danog/liquid.git synced 2024-12-02 15:37:51 +01:00
liquid/expressions/statements.go

56 lines
1.2 KiB
Go
Raw Normal View History

2017-07-14 02:18:23 +02:00
package expressions
// These strings match lexer tokens.
const (
AssignStatementSelector = "%assign "
CycleStatementSelector = "{%cycle "
LoopStatementSelector = "%loop "
2017-07-13 17:59:11 +02:00
WhenStatementSelector = "{%when "
)
// A Statement is the result of parsing a string.
type Statement struct{ parseValue }
2017-07-13 16:08:17 +02:00
// Expression returns a statement's expression function.
2017-07-13 17:59:11 +02:00
// func (s *Statement) Expression() Expression { return &expression{s.val} }
// An Assignment is a parse of an {% assign %} statement
type Assignment struct {
2017-07-13 16:08:17 +02:00
Variable string
ValueFn Expression
}
// A Cycle is a parse of an {% assign %} statement
type Cycle struct {
2017-07-13 17:59:11 +02:00
Group string
Values []string
}
// A Loop is a parse of a {% loop %} statement
type Loop struct {
Variable string
2017-07-13 16:08:17 +02:00
Expr Expression
loopModifiers
}
type loopModifiers struct {
Limit *int
Offset int
Reversed bool
}
2017-07-13 17:59:11 +02:00
// A When is a parse of a {% when %} clause
type When struct {
Exprs []Expression
}
// ParseStatement parses an statement into an Expression that can evaluated to return a
// structure specific to the statement.
func ParseStatement(sel, source string) (*Statement, error) {
p, err := parse(sel + source)
if err != nil {
return nil, err
}
return &Statement{*p}, nil
}