當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Parser.SkipSpaces方法代碼示例

本文整理匯總了Golang中github.com/karlseguin/gerb/core.Parser.SkipSpaces方法的典型用法代碼示例。如果您正苦於以下問題:Golang Parser.SkipSpaces方法的具體用法?Golang Parser.SkipSpaces怎麽用?Golang Parser.SkipSpaces使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/karlseguin/gerb/core.Parser的用法示例。


在下文中一共展示了Parser.SkipSpaces方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: IfFactory

func IfFactory(p *core.Parser) (core.Code, error) {
	code := &IfCode{
		NormalContainer: new(core.NormalContainer),
		assignments:     make([]*core.Assignment, 0, 3),
		verifiables:     make([]core.Verifiable, 0, 3),
		codes:           make([]core.Code, 0, 3),
	}
	if p.TagContains(';') {
		assignment, err := p.ReadAssignment()
		if err != nil {
			return nil, err
		}
		code.assignments = append(code.assignments, assignment)
		if p.SkipSpaces() != ';' {
			return nil, p.Error("If assignment should be followed by a semicolon")
		}
		p.Next()
	} else {
		code.assignments = append(code.assignments, nil)
	}
	verifiable, err := p.ReadConditionGroup(false)
	if err != nil {
		return nil, err
	}
	code.verifiables = append(code.verifiables, verifiable)
	code.codes = append(code.codes, code)
	if p.SkipSpaces() != '{' {
		return nil, p.Error("Missing openening brace for if statement")
	}
	p.Next()
	return code, nil
}
開發者ID:xet7,項目名稱:gerb,代碼行數:32,代碼來源:if.go

示例2: ForFactory

func ForFactory(p *core.Parser) (core.Code, error) {
	if p.TagContains(';') {
		return ExplicitForFactory(p)
	}
	if p.SkipSpaces() == '{' {
		p.Next()
		return &ForCode{NormalContainer: new(core.NormalContainer)}, nil
	}
	return RangedForFactory(p)
}
開發者ID:xet7,項目名稱:gerb,代碼行數:10,代碼來源:for.go

示例3: ContentFactory

func ContentFactory(p *core.Parser) (core.Code, error) {
	value, err := p.ReadValue()
	if err != nil {
		return nil, err
	}
	if p.SkipSpaces() != '{' {
		return nil, p.Error("Missing openening brace for content statement")
	}
	p.Next()
	return &ContentCode{new(core.NormalContainer), value}, nil
}
開發者ID:xet7,項目名稱:gerb,代碼行數:11,代碼來源:content.go

示例4: ElseFactory

func ElseFactory(p *core.Parser) (core.Code, error) {
	code := &ElseCode{NormalContainer: new(core.NormalContainer)}
	if p.SkipSpaces() == 'i' && p.ConsumeIf([]byte("if")) {
		if p.TagContains(';') {
			assignment, err := p.ReadAssignment()
			if err != nil {
				return nil, err
			}
			code.assignment = assignment
			if p.SkipSpaces() != ';' {
				return nil, p.Error("else if assignment should be followed by a semicolon")
			}
			p.Next()
		}
		verifiable, err := p.ReadConditionGroup(false)
		if err != nil {
			return nil, err
		}
		code.verifiable = verifiable
		if p.SkipSpaces() != '{' {
			return nil, p.Error("Missing openening brace for else if statement")
		}
	} else {
		code.verifiable = core.TrueCondition //else case
		if p.SkipSpaces() != '{' {
			return nil, p.Error("Missing openening brace for else statement")
		}
	}
	p.Next()
	return code, nil
}
開發者ID:xet7,項目名稱:gerb,代碼行數:31,代碼來源:if.go

示例5: createCodeTag

func createCodeTag(p *core.Parser) (*core.Codes, error) {
	codes := make([]core.Code, 0, 1)
	for {
		token, err := p.ReadToken()
		if err != nil {
			return nil, err
		}
		length := len(token)
		if length == 0 {
			if err := p.ReadCloseTag(); err != nil {
				return nil, err
			}
			return nil, nil
		}

		var code core.Code
		if token == "}" {
			if p.SkipSpaces() == 'e' && p.ConsumeIf(elseBytes) {
				code, err = ElseFactory(p)
			} else {
				code = endScope
			}
		} else if factory, ok := CodeFactories[token]; ok {
			code, err = factory(p)
		} else {
			p.Backwards(length)
			code, err = p.ReadAssignment()
		}
		if err != nil {
			return nil, err
		}
		codes = append(codes, code)
		if p.SkipSpaces() == '%' {
			if p.ConsumeIf(trimCloseBytes) {
				return &core.Codes{true, codes}, nil
			}
			if p.ConsumeIf(closeBytes) {
				return &core.Codes{false, codes}, nil
			}
		}
	}
}
開發者ID:xet7,項目名稱:gerb,代碼行數:42,代碼來源:code.go

示例6: ExplicitForFactory

func ExplicitForFactory(p *core.Parser) (core.Code, error) {
	code := &ForCode{NormalContainer: new(core.NormalContainer)}
	if p.SkipSpaces() != ';' {
		assignment, err := p.ReadAssignment()
		if err != nil {
			return nil, err
		}
		code.init = assignment
	}

	if p.SkipSpaces() != ';' {
		return nil, p.Error("Invalid for loop, expecting INIT; CONDITION; STEP (1)")
	}
	p.Next()

	verifiable, err := p.ReadConditionGroup(false)
	if err != nil {
		return nil, err
	}

	code.verifiable = verifiable

	if p.SkipSpaces() != ';' {
		return nil, p.Error("Invalid for loop, expecting INIT; CONDITION; STEP (1)")
	}
	p.Next()

	if p.SkipSpaces() != '{' {
		value, err := p.ReadAssignment()
		if err != nil {
			return nil, err
		}
		code.step = value
	}
	if p.SkipSpaces() != '{' {
		return nil, p.Error("Missing openening brace for for statement")
	}
	p.Next()
	return code, nil
}
開發者ID:xet7,項目名稱:gerb,代碼行數:40,代碼來源:for.go

示例7: RangedForFactory

func RangedForFactory(p *core.Parser) (core.Code, error) {
	code := &RangedForCode{NormalContainer: new(core.NormalContainer)}
	tokens, err := p.ReadTokenList()
	if err != nil {
		return nil, err
	}
	if len(tokens) != 2 {
		return nil, p.Error("Invalid for loop, ranged loop should have two variables")
	}
	code.tokens = tokens
	c := p.SkipSpaces()
	if c == ':' {
		c = p.Next()
	}
	if c != '=' {
		return nil, p.Error("Invalid for loop, ranged loop expecting assignment operator")
	}
	p.Next()

	if p.SkipSpaces() != 'r' || p.ConsumeIf([]byte("range")) == false {
		return nil, p.Error("invalid for loop, expected 'range' keyword")
	}

	value, err := p.ReadValue()
	if err != nil {
		return nil, err
	}
	code.value = value
	if p.SkipSpaces() != '{' {
		return nil, p.Error("Missing openening brace for if statement")
	}
	p.Next()

	return code, nil

}
開發者ID:xet7,項目名稱:gerb,代碼行數:36,代碼來源:for.go


注:本文中的github.com/karlseguin/gerb/core.Parser.SkipSpaces方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。