Esempio n. 1
0
File: decls.go Progetto: 8l/leaf
func (p *Parser) parseVarValue(v *ast.Var) bool {
	if p.accept(tt.Lbrace) {
		p.extend("var-init-array")
		defer p.pop()
		for {
			if p.accept(tt.Rbrace) {
				break
			}

			if p.accept(tt.Int) || p.accept(tt.Char) || p.accept(tt.Float) {
				v.InitValues = append(v.InitValues, p.last())
			} else {
				p.expecting("init values")
				return false
			}

			if p.accept(tt.Comma) {
				continue
			}

			if !p.ahead(tt.Rbrace) {
				p.expecting("comma or right brace")
				return false
			}
		}
	} else if p.accept(tt.String) {
		p.extend("var-init-string")
		defer p.pop()
		v.InitValue = p.last()
	} else if p.accept(tt.Int) || p.accept(tt.Char) || p.accept(tt.Float) {
		p.extend("var-init-single")
		defer p.pop()
		v.InitValue = p.last()
	} else {
		p.expecting("init var value")
		return false
	}

	return true
}