mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 03:38:29 +00:00
libsyntax: Change all uses of &fn
to ||
.
This commit is contained in:
parent
18a30aff45
commit
492677ec1e
@ -84,7 +84,7 @@ static AbiDatas: &'static [AbiData] = &[
|
|||||||
AbiData {abi: RustIntrinsic, name: "rust-intrinsic", abi_arch: RustArch},
|
AbiData {abi: RustIntrinsic, name: "rust-intrinsic", abi_arch: RustArch},
|
||||||
];
|
];
|
||||||
|
|
||||||
fn each_abi(op: &fn(abi: Abi) -> bool) -> bool {
|
fn each_abi(op: |abi: Abi| -> bool) -> bool {
|
||||||
/*!
|
/*!
|
||||||
*
|
*
|
||||||
* Iterates through each of the defined ABIs.
|
* Iterates through each of the defined ABIs.
|
||||||
@ -201,7 +201,7 @@ impl AbiSet {
|
|||||||
self.bits |= (1 << abi.index());
|
self.bits |= (1 << abi.index());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn each(&self, op: &fn(abi: Abi) -> bool) -> bool {
|
pub fn each(&self, op: |abi: Abi| -> bool) -> bool {
|
||||||
each_abi(|abi| !self.contains(abi) || op(abi))
|
each_abi(|abi| !self.contains(abi) || op(abi))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ pub enum ast_node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ast_node {
|
impl ast_node {
|
||||||
pub fn with_attrs<T>(&self, f: &fn(Option<&[Attribute]>) -> T) -> T {
|
pub fn with_attrs<T>(&self, f: |Option<&[Attribute]>| -> T) -> T {
|
||||||
let attrs = match *self {
|
let attrs = match *self {
|
||||||
node_item(i, _) => Some(i.attrs.as_slice()),
|
node_item(i, _) => Some(i.attrs.as_slice()),
|
||||||
node_foreign_item(fi, _, _, _) => Some(fi.attrs.as_slice()),
|
node_foreign_item(fi, _, _, _) => Some(fi.attrs.as_slice()),
|
||||||
@ -480,9 +480,8 @@ pub fn node_id_to_str(map: map, id: NodeId, itr: @ident_interner) -> ~str {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn node_item_query<Result>(items: map, id: NodeId,
|
pub fn node_item_query<Result>(items: map, id: NodeId, query: |@item| -> Result, error_msg: ~str)
|
||||||
query: &fn(@item) -> Result,
|
-> Result {
|
||||||
error_msg: ~str) -> Result {
|
|
||||||
match items.find(&id) {
|
match items.find(&id) {
|
||||||
Some(&node_item(it, _)) => query(it),
|
Some(&node_item(it, _)) => query(it),
|
||||||
_ => fail!("{}", error_msg)
|
_ => fail!("{}", error_msg)
|
||||||
|
@ -636,7 +636,7 @@ pub fn is_item_impl(item: @ast::item) -> bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_pat(pat: @Pat, it: &fn(@Pat) -> bool) -> bool {
|
pub fn walk_pat(pat: @Pat, it: |@Pat| -> bool) -> bool {
|
||||||
if !it(pat) {
|
if !it(pat) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -665,7 +665,7 @@ pub fn walk_pat(pat: @Pat, it: &fn(@Pat) -> bool) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub trait EachViewItem {
|
pub trait EachViewItem {
|
||||||
fn each_view_item(&self, f: &fn(&ast::view_item) -> bool) -> bool;
|
fn each_view_item(&self, f: |&ast::view_item| -> bool) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct EachViewItemData<'self> {
|
struct EachViewItemData<'self> {
|
||||||
@ -679,7 +679,7 @@ impl<'self> Visitor<()> for EachViewItemData<'self> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl EachViewItem for ast::Crate {
|
impl EachViewItem for ast::Crate {
|
||||||
fn each_view_item(&self, f: &fn(&ast::view_item) -> bool) -> bool {
|
fn each_view_item(&self, f: |&ast::view_item| -> bool) -> bool {
|
||||||
let mut visit = EachViewItemData {
|
let mut visit = EachViewItemData {
|
||||||
callback: f,
|
callback: f,
|
||||||
};
|
};
|
||||||
|
@ -347,9 +347,11 @@ fn print_macro_backtrace(cm: @codemap::CodeMap, sp: Span) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn expect<T:Clone>(diag: @mut span_handler,
|
pub fn expect<T:Clone>(
|
||||||
|
diag: @mut span_handler,
|
||||||
opt: Option<T>,
|
opt: Option<T>,
|
||||||
msg: &fn() -> ~str) -> T {
|
msg: || -> ~str)
|
||||||
|
-> T {
|
||||||
match opt {
|
match opt {
|
||||||
Some(ref t) => (*t).clone(),
|
Some(ref t) => (*t).clone(),
|
||||||
None => diag.handler().bug(msg()),
|
None => diag.handler().bug(msg()),
|
||||||
|
@ -559,11 +559,11 @@ impl <K: Eq + Hash + IterBytes + 'static, V: 'static> MapChain<K,V>{
|
|||||||
// should each_key and each_value operate on shadowed
|
// should each_key and each_value operate on shadowed
|
||||||
// names? I think not.
|
// names? I think not.
|
||||||
// delaying implementing this....
|
// delaying implementing this....
|
||||||
pub fn each_key (&self, _f: &fn (&K)->bool) {
|
pub fn each_key (&self, _f: |&K| -> bool) {
|
||||||
fail!("unimplemented 2013-02-15T10:01");
|
fail!("unimplemented 2013-02-15T10:01");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn each_value (&self, _f: &fn (&V) -> bool) {
|
pub fn each_value (&self, _f: |&V| -> bool) {
|
||||||
fail!("unimplemented 2013-02-15T10:02");
|
fail!("unimplemented 2013-02-15T10:02");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -601,7 +601,11 @@ impl <K: Eq + Hash + IterBytes + 'static, V: 'static> MapChain<K,V>{
|
|||||||
// ... there are definitely some opportunities for abstraction
|
// ... there are definitely some opportunities for abstraction
|
||||||
// here that I'm ignoring. (e.g., manufacturing a predicate on
|
// here that I'm ignoring. (e.g., manufacturing a predicate on
|
||||||
// the maps in the chain, and using an abstract "find".
|
// the maps in the chain, and using an abstract "find".
|
||||||
pub fn insert_into_frame(&mut self, key: K, ext: @V, n: K, pred: &fn(&@V)->bool) {
|
pub fn insert_into_frame(&mut self,
|
||||||
|
key: K,
|
||||||
|
ext: @V,
|
||||||
|
n: K,
|
||||||
|
pred: |&@V| -> bool) {
|
||||||
match *self {
|
match *self {
|
||||||
BaseMapChain (~ref mut map) => {
|
BaseMapChain (~ref mut map) => {
|
||||||
if satisfies_pred(map,&n,pred) {
|
if satisfies_pred(map,&n,pred) {
|
||||||
@ -622,9 +626,11 @@ impl <K: Eq + Hash + IterBytes + 'static, V: 'static> MapChain<K,V>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// returns true if the binding for 'n' satisfies 'pred' in 'map'
|
// returns true if the binding for 'n' satisfies 'pred' in 'map'
|
||||||
fn satisfies_pred<K : Eq + Hash + IterBytes,V>(map : &mut HashMap<K,V>,
|
fn satisfies_pred<K:Eq + Hash + IterBytes,
|
||||||
|
V>(
|
||||||
|
map: &mut HashMap<K,V>,
|
||||||
n: &K,
|
n: &K,
|
||||||
pred: &fn(&V)->bool)
|
pred: |&V| -> bool)
|
||||||
-> bool {
|
-> bool {
|
||||||
match map.find(n) {
|
match map.find(n) {
|
||||||
Some(ref v) => (pred(*v)),
|
Some(ref v) => (pred(*v)),
|
||||||
@ -637,7 +643,8 @@ mod test {
|
|||||||
use super::MapChain;
|
use super::MapChain;
|
||||||
use std::hashmap::HashMap;
|
use std::hashmap::HashMap;
|
||||||
|
|
||||||
#[test] fn testenv () {
|
#[test]
|
||||||
|
fn testenv() {
|
||||||
let mut a = HashMap::new();
|
let mut a = HashMap::new();
|
||||||
a.insert (@"abc",@15);
|
a.insert (@"abc",@15);
|
||||||
let m = MapChain::new(~a);
|
let m = MapChain::new(~a);
|
||||||
|
@ -124,9 +124,12 @@ fn decodable_substructure(cx: @ExtCtxt, span: Span,
|
|||||||
/// Create a decoder for a single enum variant/struct:
|
/// Create a decoder for a single enum variant/struct:
|
||||||
/// - `outer_pat_ident` is the name of this enum variant/struct
|
/// - `outer_pat_ident` is the name of this enum variant/struct
|
||||||
/// - `getarg` should retrieve the `uint`-th field with name `@str`.
|
/// - `getarg` should retrieve the `uint`-th field with name `@str`.
|
||||||
fn decode_static_fields(cx: @ExtCtxt, outer_span: Span, outer_pat_ident: Ident,
|
fn decode_static_fields(cx: @ExtCtxt,
|
||||||
|
outer_span: Span,
|
||||||
|
outer_pat_ident: Ident,
|
||||||
fields: &StaticFields,
|
fields: &StaticFields,
|
||||||
getarg: &fn(Span, @str, uint) -> @Expr) -> @Expr {
|
getarg: |Span, @str, uint| -> @Expr)
|
||||||
|
-> @Expr {
|
||||||
match *fields {
|
match *fields {
|
||||||
Unnamed(ref fields) => {
|
Unnamed(ref fields) => {
|
||||||
if fields.is_empty() {
|
if fields.is_empty() {
|
||||||
|
@ -1064,14 +1064,13 @@ Fold the fields. `use_foldl` controls whether this is done
|
|||||||
left-to-right (`true`) or right-to-left (`false`).
|
left-to-right (`true`) or right-to-left (`false`).
|
||||||
*/
|
*/
|
||||||
pub fn cs_fold(use_foldl: bool,
|
pub fn cs_fold(use_foldl: bool,
|
||||||
f: &fn(@ExtCtxt, Span,
|
f: |@ExtCtxt, Span, @Expr, @Expr, &[@Expr]| -> @Expr,
|
||||||
old: @Expr,
|
|
||||||
self_f: @Expr,
|
|
||||||
other_fs: &[@Expr]) -> @Expr,
|
|
||||||
base: @Expr,
|
base: @Expr,
|
||||||
enum_nonmatch_f: EnumNonMatchFunc,
|
enum_nonmatch_f: EnumNonMatchFunc,
|
||||||
cx: @ExtCtxt, trait_span: Span,
|
cx: @ExtCtxt,
|
||||||
substructure: &Substructure) -> @Expr {
|
trait_span: Span,
|
||||||
|
substructure: &Substructure)
|
||||||
|
-> @Expr {
|
||||||
match *substructure.fields {
|
match *substructure.fields {
|
||||||
EnumMatching(_, _, ref all_fields) | Struct(ref all_fields) => {
|
EnumMatching(_, _, ref all_fields) | Struct(ref all_fields) => {
|
||||||
if use_foldl {
|
if use_foldl {
|
||||||
@ -1104,10 +1103,12 @@ f(cx, span, ~[self_1.method(__arg_1_1, __arg_2_1),
|
|||||||
~~~
|
~~~
|
||||||
*/
|
*/
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn cs_same_method(f: &fn(@ExtCtxt, Span, ~[@Expr]) -> @Expr,
|
pub fn cs_same_method(f: |@ExtCtxt, Span, ~[@Expr]| -> @Expr,
|
||||||
enum_nonmatch_f: EnumNonMatchFunc,
|
enum_nonmatch_f: EnumNonMatchFunc,
|
||||||
cx: @ExtCtxt, trait_span: Span,
|
cx: @ExtCtxt,
|
||||||
substructure: &Substructure) -> @Expr {
|
trait_span: Span,
|
||||||
|
substructure: &Substructure)
|
||||||
|
-> @Expr {
|
||||||
match *substructure.fields {
|
match *substructure.fields {
|
||||||
EnumMatching(_, _, ref all_fields) | Struct(ref all_fields) => {
|
EnumMatching(_, _, ref all_fields) | Struct(ref all_fields) => {
|
||||||
// call self_n.method(other_1_n, other_2_n, ...)
|
// call self_n.method(other_1_n, other_2_n, ...)
|
||||||
@ -1136,11 +1137,13 @@ fields. `use_foldl` controls whether this is done left-to-right
|
|||||||
*/
|
*/
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn cs_same_method_fold(use_foldl: bool,
|
pub fn cs_same_method_fold(use_foldl: bool,
|
||||||
f: &fn(@ExtCtxt, Span, @Expr, @Expr) -> @Expr,
|
f: |@ExtCtxt, Span, @Expr, @Expr| -> @Expr,
|
||||||
base: @Expr,
|
base: @Expr,
|
||||||
enum_nonmatch_f: EnumNonMatchFunc,
|
enum_nonmatch_f: EnumNonMatchFunc,
|
||||||
cx: @ExtCtxt, trait_span: Span,
|
cx: @ExtCtxt,
|
||||||
substructure: &Substructure) -> @Expr {
|
trait_span: Span,
|
||||||
|
substructure: &Substructure)
|
||||||
|
-> @Expr {
|
||||||
cs_same_method(
|
cs_same_method(
|
||||||
|cx, span, vals| {
|
|cx, span, vals| {
|
||||||
if use_foldl {
|
if use_foldl {
|
||||||
|
@ -128,10 +128,12 @@ fn rand_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
|
|||||||
_ => cx.bug("Non-static method in `deriving(Rand)`")
|
_ => cx.bug("Non-static method in `deriving(Rand)`")
|
||||||
};
|
};
|
||||||
|
|
||||||
fn rand_thing(cx: @ExtCtxt, span: Span,
|
fn rand_thing(cx: @ExtCtxt,
|
||||||
|
span: Span,
|
||||||
ctor_ident: Ident,
|
ctor_ident: Ident,
|
||||||
summary: &StaticFields,
|
summary: &StaticFields,
|
||||||
rand_call: &fn(Span) -> @Expr) -> @Expr {
|
rand_call: |Span| -> @Expr)
|
||||||
|
-> @Expr {
|
||||||
match *summary {
|
match *summary {
|
||||||
Unnamed(ref fields) => {
|
Unnamed(ref fields) => {
|
||||||
if fields.is_empty() {
|
if fields.is_empty() {
|
||||||
|
@ -381,7 +381,7 @@ pub trait ast_fold {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn map_exprs(&self, f: &fn(@Expr) -> @Expr, es: &[@Expr]) -> ~[@Expr] {
|
fn map_exprs(&self, f: |@Expr| -> @Expr, es: &[@Expr]) -> ~[@Expr] {
|
||||||
es.map(|x| f(*x))
|
es.map(|x| f(*x))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,14 +50,14 @@ impl<T> OptVec<T> {
|
|||||||
*self = Vec(~[t]);
|
*self = Vec(~[t]);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn map<U>(&self, op: &fn(&T) -> U) -> OptVec<U> {
|
pub fn map<U>(&self, op: |&T| -> U) -> OptVec<U> {
|
||||||
match *self {
|
match *self {
|
||||||
Empty => Empty,
|
Empty => Empty,
|
||||||
Vec(ref v) => Vec(v.map(op))
|
Vec(ref v) => Vec(v.map(op))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn map_move<U>(self, op: &fn(T) -> U) -> OptVec<U> {
|
pub fn map_move<U>(self, op: |T| -> U) -> OptVec<U> {
|
||||||
match self {
|
match self {
|
||||||
Empty => Empty,
|
Empty => Empty,
|
||||||
Vec(v) => Vec(v.move_iter().map(op).collect())
|
Vec(v) => Vec(v.move_iter().map(op).collect())
|
||||||
@ -91,11 +91,11 @@ impl<T> OptVec<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn map_to_vec<B>(&self, op: &fn(&T) -> B) -> ~[B] {
|
pub fn map_to_vec<B>(&self, op: |&T| -> B) -> ~[B] {
|
||||||
self.iter().map(op).collect()
|
self.iter().map(op).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mapi_to_vec<B>(&self, op: &fn(uint, &T) -> B) -> ~[B] {
|
pub fn mapi_to_vec<B>(&self, op: |uint, &T| -> B) -> ~[B] {
|
||||||
let mut index = 0;
|
let mut index = 0;
|
||||||
self.map_to_vec(|a| {
|
self.map_to_vec(|a| {
|
||||||
let i = index;
|
let i = index;
|
||||||
|
@ -216,16 +216,22 @@ fn byte_offset(rdr: &StringReader, pos: BytePos) -> BytePos {
|
|||||||
/// Calls `f` with a string slice of the source text spanning from `start`
|
/// Calls `f` with a string slice of the source text spanning from `start`
|
||||||
/// up to but excluding `rdr.last_pos`, meaning the slice does not include
|
/// up to but excluding `rdr.last_pos`, meaning the slice does not include
|
||||||
/// the character `rdr.curr`.
|
/// the character `rdr.curr`.
|
||||||
pub fn with_str_from<T>(rdr: @mut StringReader, start: BytePos, f: &fn(s: &str) -> T) -> T {
|
pub fn with_str_from<T>(
|
||||||
|
rdr: @mut StringReader,
|
||||||
|
start: BytePos,
|
||||||
|
f: |s: &str| -> T)
|
||||||
|
-> T {
|
||||||
with_str_from_to(rdr, start, rdr.last_pos, f)
|
with_str_from_to(rdr, start, rdr.last_pos, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calls `f` with astring slice of the source text spanning from `start`
|
/// Calls `f` with astring slice of the source text spanning from `start`
|
||||||
/// up to but excluding `end`.
|
/// up to but excluding `end`.
|
||||||
fn with_str_from_to<T>(rdr: @mut StringReader,
|
fn with_str_from_to<T>(
|
||||||
|
rdr: @mut StringReader,
|
||||||
start: BytePos,
|
start: BytePos,
|
||||||
end: BytePos,
|
end: BytePos,
|
||||||
f: &fn(s: &str) -> T) -> T {
|
f: |s: &str| -> T)
|
||||||
|
-> T {
|
||||||
f(rdr.src.slice(
|
f(rdr.src.slice(
|
||||||
byte_offset(rdr, start).to_uint(),
|
byte_offset(rdr, start).to_uint(),
|
||||||
byte_offset(rdr, end).to_uint()))
|
byte_offset(rdr, end).to_uint()))
|
||||||
|
@ -177,19 +177,14 @@ pub fn parse_tts_from_source_str(
|
|||||||
// consumed all of the input before returning the function's
|
// consumed all of the input before returning the function's
|
||||||
// result.
|
// result.
|
||||||
pub fn parse_from_source_str<T>(
|
pub fn parse_from_source_str<T>(
|
||||||
f: &fn(&Parser) -> T,
|
f: |&Parser| -> T,
|
||||||
name: @str, ss: codemap::FileSubstr,
|
name: @str,
|
||||||
|
ss: codemap::FileSubstr,
|
||||||
source: @str,
|
source: @str,
|
||||||
cfg: ast::CrateConfig,
|
cfg: ast::CrateConfig,
|
||||||
sess: @mut ParseSess
|
sess: @mut ParseSess)
|
||||||
) -> T {
|
-> T {
|
||||||
let p = new_parser_from_source_substr(
|
let p = new_parser_from_source_substr(sess, cfg, name, ss, source);
|
||||||
sess,
|
|
||||||
cfg,
|
|
||||||
name,
|
|
||||||
ss,
|
|
||||||
source
|
|
||||||
);
|
|
||||||
let r = f(&p);
|
let r = f(&p);
|
||||||
if !p.reader.is_eof() {
|
if !p.reader.is_eof() {
|
||||||
p.reader.fatal(~"expected end-of-string");
|
p.reader.fatal(~"expected end-of-string");
|
||||||
|
@ -82,7 +82,7 @@ impl ParserObsoleteMethods for Parser {
|
|||||||
),
|
),
|
||||||
ObsoleteBareFnType => (
|
ObsoleteBareFnType => (
|
||||||
"bare function type",
|
"bare function type",
|
||||||
"use `&fn` or `extern fn` instead"
|
"use `|A| -> B` or `extern fn(A) -> B` instead"
|
||||||
),
|
),
|
||||||
ObsoleteNamedExternModule => (
|
ObsoleteNamedExternModule => (
|
||||||
"named external module",
|
"named external module",
|
||||||
|
@ -581,9 +581,7 @@ impl Parser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse a sequence bracketed by `|` and `|`, stopping before the `|`.
|
// Parse a sequence bracketed by `|` and `|`, stopping before the `|`.
|
||||||
fn parse_seq_to_before_or<T>(&self,
|
fn parse_seq_to_before_or<T>(&self, sep: &token::Token, f: |&Parser| -> T)
|
||||||
sep: &token::Token,
|
|
||||||
f: &fn(&Parser) -> T)
|
|
||||||
-> ~[T] {
|
-> ~[T] {
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
let mut vector = ~[];
|
let mut vector = ~[];
|
||||||
@ -619,9 +617,10 @@ impl Parser {
|
|||||||
|
|
||||||
// parse a sequence bracketed by '<' and '>', stopping
|
// parse a sequence bracketed by '<' and '>', stopping
|
||||||
// before the '>'.
|
// before the '>'.
|
||||||
pub fn parse_seq_to_before_gt<T>(&self,
|
pub fn parse_seq_to_before_gt<T>(
|
||||||
|
&self,
|
||||||
sep: Option<token::Token>,
|
sep: Option<token::Token>,
|
||||||
f: &fn(&Parser) -> T)
|
f: |&Parser| -> T)
|
||||||
-> OptVec<T> {
|
-> OptVec<T> {
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
let mut v = opt_vec::Empty;
|
let mut v = opt_vec::Empty;
|
||||||
@ -639,9 +638,10 @@ impl Parser {
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_seq_to_gt<T>(&self,
|
pub fn parse_seq_to_gt<T>(
|
||||||
|
&self,
|
||||||
sep: Option<token::Token>,
|
sep: Option<token::Token>,
|
||||||
f: &fn(&Parser) -> T)
|
f: |&Parser| -> T)
|
||||||
-> OptVec<T> {
|
-> OptVec<T> {
|
||||||
let v = self.parse_seq_to_before_gt(sep, f);
|
let v = self.parse_seq_to_before_gt(sep, f);
|
||||||
self.expect_gt();
|
self.expect_gt();
|
||||||
@ -651,10 +651,11 @@ impl Parser {
|
|||||||
// parse a sequence, including the closing delimiter. The function
|
// parse a sequence, including the closing delimiter. The function
|
||||||
// f must consume tokens until reaching the next separator or
|
// f must consume tokens until reaching the next separator or
|
||||||
// closing bracket.
|
// closing bracket.
|
||||||
pub fn parse_seq_to_end<T>(&self,
|
pub fn parse_seq_to_end<T>(
|
||||||
|
&self,
|
||||||
ket: &token::Token,
|
ket: &token::Token,
|
||||||
sep: SeqSep,
|
sep: SeqSep,
|
||||||
f: &fn(&Parser) -> T)
|
f: |&Parser| -> T)
|
||||||
-> ~[T] {
|
-> ~[T] {
|
||||||
let val = self.parse_seq_to_before_end(ket, sep, f);
|
let val = self.parse_seq_to_before_end(ket, sep, f);
|
||||||
self.bump();
|
self.bump();
|
||||||
@ -664,10 +665,11 @@ impl Parser {
|
|||||||
// parse a sequence, not including the closing delimiter. The function
|
// parse a sequence, not including the closing delimiter. The function
|
||||||
// f must consume tokens until reaching the next separator or
|
// f must consume tokens until reaching the next separator or
|
||||||
// closing bracket.
|
// closing bracket.
|
||||||
pub fn parse_seq_to_before_end<T>(&self,
|
pub fn parse_seq_to_before_end<T>(
|
||||||
|
&self,
|
||||||
ket: &token::Token,
|
ket: &token::Token,
|
||||||
sep: SeqSep,
|
sep: SeqSep,
|
||||||
f: &fn(&Parser) -> T)
|
f: |&Parser| -> T)
|
||||||
-> ~[T] {
|
-> ~[T] {
|
||||||
let mut first: bool = true;
|
let mut first: bool = true;
|
||||||
let mut v: ~[T] = ~[];
|
let mut v: ~[T] = ~[];
|
||||||
@ -688,11 +690,12 @@ impl Parser {
|
|||||||
// parse a sequence, including the closing delimiter. The function
|
// parse a sequence, including the closing delimiter. The function
|
||||||
// f must consume tokens until reaching the next separator or
|
// f must consume tokens until reaching the next separator or
|
||||||
// closing bracket.
|
// closing bracket.
|
||||||
pub fn parse_unspanned_seq<T>(&self,
|
pub fn parse_unspanned_seq<T>(
|
||||||
|
&self,
|
||||||
bra: &token::Token,
|
bra: &token::Token,
|
||||||
ket: &token::Token,
|
ket: &token::Token,
|
||||||
sep: SeqSep,
|
sep: SeqSep,
|
||||||
f: &fn(&Parser) -> T)
|
f: |&Parser| -> T)
|
||||||
-> ~[T] {
|
-> ~[T] {
|
||||||
self.expect(bra);
|
self.expect(bra);
|
||||||
let result = self.parse_seq_to_before_end(ket, sep, f);
|
let result = self.parse_seq_to_before_end(ket, sep, f);
|
||||||
@ -702,11 +705,12 @@ impl Parser {
|
|||||||
|
|
||||||
// NB: Do not use this function unless you actually plan to place the
|
// NB: Do not use this function unless you actually plan to place the
|
||||||
// spanned list in the AST.
|
// spanned list in the AST.
|
||||||
pub fn parse_seq<T>(&self,
|
pub fn parse_seq<T>(
|
||||||
|
&self,
|
||||||
bra: &token::Token,
|
bra: &token::Token,
|
||||||
ket: &token::Token,
|
ket: &token::Token,
|
||||||
sep: SeqSep,
|
sep: SeqSep,
|
||||||
f: &fn(&Parser) -> T)
|
f: |&Parser| -> T)
|
||||||
-> Spanned<~[T]> {
|
-> Spanned<~[T]> {
|
||||||
let lo = self.span.lo;
|
let lo = self.span.lo;
|
||||||
self.expect(bra);
|
self.expect(bra);
|
||||||
@ -765,7 +769,7 @@ impl Parser {
|
|||||||
}
|
}
|
||||||
return (4 - *self.buffer_start) + *self.buffer_end;
|
return (4 - *self.buffer_start) + *self.buffer_end;
|
||||||
}
|
}
|
||||||
pub fn look_ahead<R>(&self, distance: uint, f: &fn(&token::Token) -> R)
|
pub fn look_ahead<R>(&self, distance: uint, f: |&token::Token| -> R)
|
||||||
-> R {
|
-> R {
|
||||||
let dist = distance as int;
|
let dist = distance as int;
|
||||||
while self.buffer_length() < dist {
|
while self.buffer_length() < dist {
|
||||||
@ -1272,7 +1276,8 @@ impl Parser {
|
|||||||
// parse the type following a @ or a ~
|
// parse the type following a @ or a ~
|
||||||
pub fn parse_box_or_uniq_pointee(&self,
|
pub fn parse_box_or_uniq_pointee(&self,
|
||||||
sigil: ast::Sigil,
|
sigil: ast::Sigil,
|
||||||
ctor: &fn(v: mt) -> ty_) -> ty_ {
|
ctor: |v: mt| -> ty_)
|
||||||
|
-> ty_ {
|
||||||
// ~'foo fn() or ~fn() are parsed directly as obsolete fn types:
|
// ~'foo fn() or ~fn() are parsed directly as obsolete fn types:
|
||||||
match *self.token {
|
match *self.token {
|
||||||
token::LIFETIME(*) => {
|
token::LIFETIME(*) => {
|
||||||
@ -2467,8 +2472,8 @@ impl Parser {
|
|||||||
// this is used both in parsing a lambda expr
|
// this is used both in parsing a lambda expr
|
||||||
// and in parsing a block expr as e.g. in for...
|
// and in parsing a block expr as e.g. in for...
|
||||||
pub fn parse_lambda_expr_(&self,
|
pub fn parse_lambda_expr_(&self,
|
||||||
parse_decl: &fn() -> fn_decl,
|
parse_decl: || -> fn_decl,
|
||||||
parse_body: &fn() -> @Expr)
|
parse_body: || -> @Expr)
|
||||||
-> @Expr {
|
-> @Expr {
|
||||||
let lo = self.last_span.lo;
|
let lo = self.last_span.lo;
|
||||||
let decl = parse_decl();
|
let decl = parse_decl();
|
||||||
@ -2513,10 +2518,11 @@ impl Parser {
|
|||||||
// parse a 'for' or 'do'.
|
// parse a 'for' or 'do'.
|
||||||
// the 'for' and 'do' expressions parse as calls, but look like
|
// the 'for' and 'do' expressions parse as calls, but look like
|
||||||
// function calls followed by a closure expression.
|
// function calls followed by a closure expression.
|
||||||
pub fn parse_sugary_call_expr(&self, lo: BytePos,
|
pub fn parse_sugary_call_expr(&self,
|
||||||
|
lo: BytePos,
|
||||||
keyword: ~str,
|
keyword: ~str,
|
||||||
sugar: CallSugar,
|
sugar: CallSugar,
|
||||||
ctor: &fn(v: @Expr) -> Expr_)
|
ctor: |v: @Expr| -> Expr_)
|
||||||
-> @Expr {
|
-> @Expr {
|
||||||
// Parse the callee `foo` in
|
// Parse the callee `foo` in
|
||||||
// for foo || {
|
// for foo || {
|
||||||
@ -3611,11 +3617,12 @@ impl Parser {
|
|||||||
|
|
||||||
// parse the argument list and result type of a function
|
// parse the argument list and result type of a function
|
||||||
// that may have a self type.
|
// that may have a self type.
|
||||||
fn parse_fn_decl_with_self(&self, parse_arg_fn: &fn(&Parser) -> arg)
|
fn parse_fn_decl_with_self(&self, parse_arg_fn: |&Parser| -> arg)
|
||||||
-> (explicit_self, fn_decl) {
|
-> (explicit_self, fn_decl) {
|
||||||
|
fn maybe_parse_explicit_self(cnstr: |v: Mutability| ->
|
||||||
fn maybe_parse_explicit_self(cnstr: &fn(v: Mutability) -> ast::explicit_self_,
|
ast::explicit_self_,
|
||||||
p: &Parser) -> ast::explicit_self_ {
|
p: &Parser)
|
||||||
|
-> ast::explicit_self_ {
|
||||||
// We need to make sure it isn't a type
|
// We need to make sure it isn't a type
|
||||||
if p.look_ahead(1, |t| token::is_keyword(keywords::Self, t)) ||
|
if p.look_ahead(1, |t| token::is_keyword(keywords::Self, t)) ||
|
||||||
((p.look_ahead(1, |t| token::is_keyword(keywords::Const, t)) ||
|
((p.look_ahead(1, |t| token::is_keyword(keywords::Const, t)) ||
|
||||||
|
@ -331,7 +331,7 @@ pub fn synth_comment(s: @ps, text: ~str) {
|
|||||||
word(s.s, "*/");
|
word(s.s, "*/");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn commasep<T>(s: @ps, b: breaks, elts: &[T], op: &fn(@ps, &T)) {
|
pub fn commasep<T>(s: @ps, b: breaks, elts: &[T], op: |@ps, &T|) {
|
||||||
box(s, 0u, b);
|
box(s, 0u, b);
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
for elt in elts.iter() {
|
for elt in elts.iter() {
|
||||||
@ -342,8 +342,12 @@ pub fn commasep<T>(s: @ps, b: breaks, elts: &[T], op: &fn(@ps, &T)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn commasep_cmnt<T>(s: @ps, b: breaks, elts: &[T], op: &fn(@ps, &T),
|
pub fn commasep_cmnt<T>(
|
||||||
get_span: &fn(&T) -> codemap::Span) {
|
s: @ps,
|
||||||
|
b: breaks,
|
||||||
|
elts: &[T],
|
||||||
|
op: |@ps, &T|,
|
||||||
|
get_span: |&T| -> codemap::Span) {
|
||||||
box(s, 0u, b);
|
box(s, 0u, b);
|
||||||
let len = elts.len();
|
let len = elts.len();
|
||||||
let mut i = 0u;
|
let mut i = 0u;
|
||||||
@ -2289,7 +2293,7 @@ pub fn print_string(s: @ps, st: &str, style: ast::StrStyle) {
|
|||||||
word(s.s, st);
|
word(s.s, st);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_str<T>(t: &T, f: &fn(@ps, &T), intr: @ident_interner) -> ~str {
|
pub fn to_str<T>(t: &T, f: |@ps, &T|, intr: @ident_interner) -> ~str {
|
||||||
let wr = @mut MemWriter::new();
|
let wr = @mut MemWriter::new();
|
||||||
let s = rust_printer(wr as @mut io::Writer, intr);
|
let s = rust_printer(wr as @mut io::Writer, intr);
|
||||||
f(s, t);
|
f(s, t);
|
||||||
|
@ -39,7 +39,7 @@ pub fn string_to_parser(source_str: @str) -> Parser {
|
|||||||
p
|
p
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_error_checking_parse<T>(s: @str, f: &fn(&mut Parser) -> T) -> T {
|
fn with_error_checking_parse<T>(s: @str, f: |&mut Parser| -> T) -> T {
|
||||||
let mut p = string_to_parser(s);
|
let mut p = string_to_parser(s);
|
||||||
let x = f(&mut p);
|
let x = f(&mut p);
|
||||||
p.abort_if_errors();
|
p.abort_if_errors();
|
||||||
|
Loading…
Reference in New Issue
Block a user