summary refs log tree commit diff
path: root/src/libsyntax/ext/pipes/ast_builder.rs
blob: 1af6e7810a57714d415e097f354138bfcec2f511 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Functions for building ASTs, without having to fuss with spans.
//
// To start with, it will be use dummy spans, but it might someday do
// something smarter.

use ast::ident;
use ast;
use codemap::span;

use std::vec;

// Transitional reexports so qquote can find the paths it is looking for
mod syntax {
    pub use ext;
    pub use parse;
}

pub fn path(ids: ~[ident], span: span) -> @ast::Path {
    @ast::Path { span: span,
                 global: false,
                 idents: ids,
                 rp: None,
                 types: ~[] }
}

pub fn path_global(ids: ~[ident], span: span) -> @ast::Path {
    @ast::Path { span: span,
                 global: true,
                 idents: ids,
                 rp: None,
                 types: ~[] }
}

pub trait append_types {
    fn add_ty(&self, ty: @ast::Ty) -> @ast::Path;
    fn add_tys(&self, tys: ~[@ast::Ty]) -> @ast::Path;
}

impl append_types for @ast::Path {
    fn add_ty(&self, ty: @ast::Ty) -> @ast::Path {
        @ast::Path {
            types: vec::append_one(copy self.types, ty),
            .. copy **self
        }
    }

    fn add_tys(&self, tys: ~[@ast::Ty]) -> @ast::Path {
        @ast::Path {
            types: vec::append(copy self.types, tys),
            .. copy **self
        }
    }
}