Files
rust/src/libsyntax/ext/pipes/ast_builder.rs

64 lines
1.7 KiB
Rust
Raw Normal View History

// 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.
2013-03-31 19:27:51 -07:00
use ast::ident;
use ast;
use codemap::span;
2013-06-24 20:40:33 -04:00
use std::vec;
// Transitional reexports so qquote can find the paths it is looking for
mod syntax {
pub use ext;
pub use parse;
}
2013-07-05 22:15:21 +12:00
pub fn path(ids: ~[ident], span: span) -> ast::Path {
ast::Path { span: span,
2013-01-13 10:48:09 -08:00
global: false,
idents: ids,
rp: None,
types: ~[] }
}
2013-07-05 22:15:21 +12:00
pub fn path_global(ids: ~[ident], span: span) -> ast::Path {
ast::Path { span: span,
2013-01-13 10:48:09 -08:00
global: true,
idents: ids,
rp: None,
types: ~[] }
}
pub trait append_types {
2013-07-05 22:15:21 +12:00
fn add_ty(&self, ty: @ast::Ty) -> ast::Path;
fn add_tys(&self, tys: ~[@ast::Ty]) -> ast::Path;
}
2013-07-05 22:15:21 +12:00
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),
2013-07-05 22:15:21 +12:00
.. copy *self
}
}
2013-07-05 22:15:21 +12:00
fn add_tys(&self, tys: ~[@ast::Ty]) -> ast::Path {
ast::Path {
types: vec::append(copy self.types, tys),
2013-07-05 22:15:21 +12:00
.. copy *self
}
}
}