示例#1
0
文件: if.go 项目: xet7/gerb
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
}
示例#2
0
文件: if.go 项目: xet7/gerb
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
}
示例#3
0
文件: for.go 项目: xet7/gerb
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
}