本文整理匯總了Golang中github.com/get3w/get3w/engines/liquid/core.Parser類的典型用法代碼示例。如果您正苦於以下問題:Golang Parser類的具體用法?Golang Parser怎麽用?Golang Parser使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Parser類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ElseIfFactory
func ElseIfFactory(p *core.Parser, config *core.Configuration) (core.Tag, error) {
condition, err := p.ReadConditionGroup()
if err != nil {
return nil, err
}
p.SkipPastTag()
return &ElseIf{NewCommon(), condition}, nil
}
示例2: WhenFactory
func WhenFactory(p *core.Parser, config *core.Configuration) (core.Tag, error) {
condition, err := p.ReadPartialCondition()
if err != nil {
return nil, err
}
p.SkipPastTag()
return &When{NewCommon(), condition}, nil
}
示例3: CaseFactory
func CaseFactory(p *core.Parser, config *core.Configuration) (core.Tag, error) {
value, err := p.ReadValue()
if err != nil {
return nil, err
}
p.SkipPastTag()
return &Case{value, make([]CaseSibling, 0, 5)}, nil
}
示例4: UnlessFactory
func UnlessFactory(p *core.Parser, config *core.Configuration) (core.Tag, error) {
condition, err := p.ReadConditionGroup()
if err != nil {
return nil, err
}
p.SkipPastTag()
condition.Inverse()
return &Unless{NewCommon(), condition, nil}, nil
}
示例5: newTag
func newTag(p *core.Parser, config *core.Configuration) (core.Tag, error) {
p.ForwardBy(2) // skip the {%
name := p.ReadName()
factory, ok := Tags[name]
if ok == false {
return nil, nil
//return nil, p.Error(fmt.Sprintf("unknown tag %q", name))
}
return factory(p, config)
}
示例6: IfFactory
func IfFactory(p *core.Parser, config *core.Configuration) (core.Tag, error) {
condition, err := p.ReadConditionGroup()
if err != nil {
return nil, err
}
i := &If{
NewCommon(),
condition,
make([]IfSibling, 0, 3),
}
i.conditions = append(i.conditions, i)
p.SkipPastTag()
return i, nil
}
示例7: newOutput
func newOutput(p *core.Parser) (core.Code, error) {
p.ForwardBy(2) // skip the {{
value, err := p.ReadValue()
if err != nil || value == nil {
return nil, err
}
filters, err := p.ReadFilters()
if err != nil {
return nil, err
}
p.SkipPastOutput()
return &Output{value, filters}, nil
}
示例8: extractTokens
func extractTokens(parser *core.Parser, container core.Tag, config *core.Configuration) error {
stack := []core.Tag{container}
preserveWhiteSpace := config.GetPreserveWhitespace()
for parser.HasMore() {
pre, markupType := parser.ToMarkup(preserveWhiteSpace)
if len(pre) > 0 {
container.AddCode(newLiteral(pre))
}
if markupType == core.OutputMarkup {
code, err := newOutput(parser)
if err != nil {
return err
}
if code != nil {
container.AddCode(code)
}
} else if markupType == core.TagMarkup {
tag, err := newTag(parser, config)
if err != nil {
return err
}
switch tag.Type() {
case core.ContainerTag, core.LoopTag:
container.AddCode(tag)
container = tag
stack = append(stack, container)
case core.EndTag:
l := len(stack) - 1
container = stack[l]
if tag.Name() != container.Name() {
return parser.Error(fmt.Sprintf("end tag \"end%s\" cannot terminate %q", tag.Name(), container.Name()))
}
stack = stack[0:l]
container = stack[l-1]
parser.SkipPastTag()
case core.SiblingTag:
if err := stack[len(stack)-1].AddSibling(tag); err != nil {
return err
}
container = tag
case core.StandaloneTag:
container.AddCode(tag)
}
} else {
break
}
}
return nil
}
示例9: CaptureFactory
// Creates an assign tag
func CaptureFactory(p *core.Parser, config *core.Configuration) (core.Tag, error) {
name := p.ReadName()
if len(name) == 0 {
return nil, p.Error("Invalid assignment, variable not found. ")
}
p.SkipPastTag()
return &Capture{name, NewCommon()}, nil
}
示例10: HighlightFactory
// Special handling to just quickly skip over it all
func HighlightFactory(p *core.Parser, config *core.Configuration) (core.Tag, error) {
openTags := 1
for {
_, markupType := p.ToMarkup(false)
if markupType == core.TagMarkup {
p.ForwardBy(2) // skip {%
if name := p.ReadName(); name == "highlight" {
openTags++
} else if name == "endhighlight" {
openTags--
if openTags == 0 {
p.SkipPastTag()
break
}
}
} else if markupType == core.OutputMarkup {
p.SkipPastTag()
} else {
break
}
}
return highlight, nil
}
示例11: IncludeFactory
// Creates an include tag
func IncludeFactory(p *core.Parser, config *core.Configuration) (core.Tag, error) {
value, err := p.ReadValue()
if err != nil {
return nil, err
}
if value == nil {
return nil, p.Error("Invalid include value")
}
p.SkipPastTag()
return &Include{value, config.GetIncludeHandler()}, nil
}
示例12: ElseFactory
func ElseFactory(p *core.Parser, config *core.Configuration) (core.Tag, error) {
p.SkipPastTag()
return &Else{NewCommon(), new(core.TrueCondition)}, nil
}
示例13: AssignFactory
// Creates an assign tag
func AssignFactory(p *core.Parser, config *core.Configuration) (core.Tag, error) {
name := p.ReadName()
if len(name) == 0 {
return nil, p.Error("Invalid variable name in assign tag")
}
if p.SkipUntil('=') != '=' {
return nil, p.Error("Invalid assign, missing '=' ")
}
p.Forward()
value, err := p.ReadValue()
if err != nil {
return nil, err
}
filters, err := p.ReadFilters()
if err != nil {
return nil, err
}
p.SkipPastTag()
return &Assign{name, value, filters}, nil
}
示例14: BreakFactory
// Creates a break tag
func BreakFactory(p *core.Parser, config *core.Configuration) (core.Tag, error) {
p.SkipPastTag()
return breakTag, nil
}
示例15: ContinueFactory
// Creates a continue tag
func ContinueFactory(p *core.Parser, config *core.Configuration) (core.Tag, error) {
p.SkipPastTag()
return continueTag, nil
}