Beispiel #1
0
func (p *parser) parseDefineExpression(lparen token.Pos) *ast.DefineExpr {
	d := new(ast.DefineExpr)
	d.LParen = lparen
	d.Args = make([]string, 0)
	tmp := p.curScope
	d.Scope = ast.NewScope(p.curScope)
	p.curScope = d.Scope
	d.Nodes = make([]ast.Node, 0)
	p.next()
	switch p.tok {
	case token.LPAREN:
		e := p.parseIdentifierList()
		l := e.Nodes
		d.Name = l[0].(*ast.Identifier).Lit
		l = l[1:]
		for _, v := range l {
			d.Args = append(d.Args, v.(*ast.Identifier).Lit)
			d.Scope.Insert(v.(*ast.Identifier).Lit, nil)
			p.curScope.Insert(v.(*ast.Identifier).Lit, d)
		}
	case token.IDENT:
		d.Name = p.parseIdentifier().Lit
		p.next()
	default:
		p.addError("Expected identifier(s) but got: ", p.lit)
		return nil
	}
	tmp.Insert(d.Name, d)
	for p.tok != token.RPAREN {
		d.Nodes = append(d.Nodes, p.parseSubExpression2())
	}
	if len(d.Nodes) < 1 {
		p.addError("Expected list of expressions but got: ", p.lit)
		d = nil // don't exit without reverting scope
	}
	if p.tok != token.RPAREN {
		p.addError("Expected closing paren but got: ", p.lit)
		d = nil // don't exit without reverting scope
	}
	p.curScope = tmp
	return d
}
Beispiel #2
0
/* Scope */
func (t *translator) openScope() {
	t.scope = ast.NewScope(t.scope)
}
Beispiel #3
0
/* Scope */
func (e *evaluator) openScope() {
	e.scope = ast.NewScope(e.scope)
}