Exemple #1
0
func (f *auto_complete_file) cursor_in_if_stmt(s *ast.IfStmt) bool {
	if f.cursor > f.offset(s.If) {
		// magic -10 comes from auto_complete_file.offset method, see
		// len() expr in there
		if f.offset(s.End()) == -10 || f.cursor < f.offset(s.End()) {
			return true
		}
	}
	return false
}
Exemple #2
0
func (p *parser) parseIfStmt(n *parse.Node) ast.Stmt {
	p.openScope()
	ifStmt := ast.IfStmt{
		If: token.Pos(n.Child(0).Pos()),
	}
	ifStmt.Init, ifStmt.Cond = p.parseInitCond(n.Child(1))
	if blockElse := n.Child(2).Child(0); blockElse.Is(block) {
		ifStmt.Body = p.parseBlock(blockElse, p.topScope)
	} else {
		ifStmt.Body = p.parseBlock(blockElse.Child(1).Child(0), p.topScope)
		ifStmt.Else = p.parseElse(blockElse.Child(1).Child(2))
	}
	p.closeScope()
	return &ifStmt
}