-
-
Notifications
You must be signed in to change notification settings - Fork 256
/
calltemplateparser.go
41 lines (31 loc) · 934 Bytes
/
calltemplateparser.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
package parser
import (
"io"
"github.com/a-h/lexical/parse"
)
var callTemplateExpression callTemplateExpressionParser
var callTemplateExpressionStartParser = parse.Or(parse.String("{! "), parse.String("{!"))
type callTemplateExpressionParser struct{}
func (p callTemplateExpressionParser) Parse(pi parse.Input) parse.Result {
var r CallTemplateExpression
// Check the prefix first.
prefixResult := callTemplateExpressionStartParser(pi)
if !prefixResult.Success {
return prefixResult
}
// Once we have a prefix, we must have an expression that returns a template.
from := NewPositionFromInput(pi)
pr := exp.Parse(pi)
if pr.Error != nil && pr.Error != io.EOF {
return pr
}
if !pr.Success {
return pr
}
r.Expression = NewExpression(pr.Item.(string), from, NewPositionFromInput(pi))
// Eat the final brace.
if pr, ok := chompBrace(pi); !ok {
return pr
}
return parse.Success("callTemplate", r, nil)
}