コード例 #1
0
ファイル: template.go プロジェクト: get3w/get3w
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
}
コード例 #2
0
ファイル: for.go プロジェクト: get3w/get3w
func (f *For) AddSibling(tag core.Tag) error {
	return errors.New(fmt.Sprintf("%q does not belong inside of a for", tag.Name()))
}
コード例 #3
0
ファイル: capture.go プロジェクト: get3w/get3w
func (c *Capture) AddSibling(tag core.Tag) error {
	return errors.New(fmt.Sprintf("%q tag does not belong directly within a capture", tag.Name()))
}