-
Notifications
You must be signed in to change notification settings - Fork 56
/
statements.go
56 lines (47 loc) · 1.23 KB
/
statements.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package expressions
// These strings match lexer tokens.
const (
AssignStatementSelector = "%assign "
CycleStatementSelector = "{%cycle "
LoopStatementSelector = "%loop "
WhenStatementSelector = "{%when "
)
// A Statement is the result of parsing a string.
type Statement struct{ parseValue }
// Expression returns a statement's expression function.
// func (s *Statement) Expression() Expression { return &expression{s.val} }
// An Assignment is a parse of an {% assign %} statement
type Assignment struct {
Variable string
ValueFn Expression
}
// A Cycle is a parse of an {% assign %} statement
type Cycle struct {
Group string
Values []string
}
// A Loop is a parse of a {% loop %} statement
type Loop struct {
Variable string
Expr Expression
loopModifiers
}
type loopModifiers struct {
Limit *int
Offset int
Reversed bool
Cols int
}
// 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
}