当前位置: 首页>>代码示例>>Golang>>正文


Golang core.Parser类代码示例

本文整理汇总了Golang中github.com/karlseguin/liquid/core.Parser的典型用法代码示例。如果您正苦于以下问题:Golang Parser类的具体用法?Golang Parser怎么用?Golang Parser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Parser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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
}
开发者ID:phlipper,项目名称:liquid,代码行数:8,代码来源:case.go

示例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
}
开发者ID:phlipper,项目名称:liquid,代码行数:8,代码来源:case.go

示例3: 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
}
开发者ID:phlipper,项目名称:liquid,代码行数:8,代码来源:if.go

示例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
}
开发者ID:karlseguin,项目名称:liquid,代码行数:9,代码来源:unless.go

示例5: 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
}
开发者ID:phlipper,项目名称:liquid,代码行数:14,代码来源:if.go

示例6: 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
}
开发者ID:phlipper,项目名称:liquid,代码行数:14,代码来源:output.go

示例7: extractTokens

func extractTokens(parser *core.Parser, container core.Tag, config *core.Configuration) error {
	stack := make([]core.Tag, 0, 0)
	parentContainer := container
	for parser.HasMore() {
		pre, markupType := parser.ToMarkup()
		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)
				stack = append(stack, container)
				container = tag
				parentContainer = tag
			case core.EndTag:
				if tag.Name() != parentContainer.Name() {
					return parser.Error("unexpected end tag")
				}
				l := len(stack) - 1
				container = stack[l]
				parentContainer = nil
				stack = stack[0:l]
				parser.SkipPastTag()
			case core.SiblingTag:
				if err := parentContainer.AddSibling(tag); err != nil {
					return err
				}
				container = tag
			case core.StandaloneTag:
				container.AddCode(tag)
			}
		} else {
			break
		}
	}
	return nil
}
开发者ID:phlipper,项目名称:liquid,代码行数:50,代码来源:template.go

示例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
}
开发者ID:karlseguin,项目名称:liquid,代码行数:49,代码来源:template.go

示例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, config, NewCommon()}, nil
}
开发者ID:phlipper,项目名称:liquid,代码行数:9,代码来源:capture.go

示例10: 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, p.Error(fmt.Sprintf("unknown tag %q", name))
	}
	return factory(p, config)
}
开发者ID:phlipper,项目名称:liquid,代码行数:9,代码来源:tag.go

示例11: CommentFactory

// Special handling to just quickly skip over it all
func CommentFactory(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 == "comment" {
				openTags++
			} else if name == "endcomment" {
				openTags--
				if openTags == 0 {
					p.SkipPastTag()
					break
				}
			}
		} else if markupType == core.OutputMarkup {

			p.SkipPastTag()
		} else {
			break
		}
	}
	return comment, nil
}
开发者ID:karlseguin,项目名称:liquid,代码行数:25,代码来源:comment.go

示例12: 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
}
开发者ID:phlipper,项目名称:liquid,代码行数:12,代码来源:include.go

示例13: BreakFactory

// Creates a break tag
func BreakFactory(p *core.Parser, config *core.Configuration) (core.Tag, error) {
	p.SkipPastTag()
	return breakTag, nil
}
开发者ID:karlseguin,项目名称:liquid,代码行数:5,代码来源:break.go

示例14: RawFactory

// Special handling to just quickly skip over it all
func RawFactory(p *core.Parser, config *core.Configuration) (core.Tag, error) {
	p.SkipPastTag()
	start := p.Position
	end := start
	for {
		_, markupType := p.ToMarkup(false)
		if markupType == core.TagMarkup {
			//tentative end is before the start of the endraw tag
			end = p.Position
			p.ForwardBy(2) // skip {%
			if name := p.ReadName(); name == "endraw" {
				p.SkipPastTag()
				break
			}
		} else if markupType == core.OutputMarkup {
			p.ForwardBy(2) // skip it
		} else {
			break
		}
	}
	return &Raw{p.Data[start:end]}, nil
}
开发者ID:karlseguin,项目名称:liquid,代码行数:23,代码来源:raw.go

示例15: ElseFactory

func ElseFactory(p *core.Parser, config *core.Configuration) (core.Tag, error) {
	p.SkipPastTag()
	return &Else{NewCommon(), new(core.TrueCondition)}, nil
}
开发者ID:phlipper,项目名称:liquid,代码行数:4,代码来源:if.go


注:本文中的github.com/karlseguin/liquid/core.Parser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。