Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

* Parsing sequence changed #3838

Merged
merged 4 commits into from
Oct 24, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@ tmp.*.rs
config.stamp
.DS_Store
src/etc/dl
.settings/
20 changes: 10 additions & 10 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,10 @@ impl Parser {
let is_static = p.parse_staticness();
let static_sty = spanned(lo, p.span.hi, sty_static);

let vis = p.parse_visibility();
let pur = p.parse_fn_purity();
// NB: at the moment, trait methods are public by default; this
// could change.
let vis = p.parse_visibility();
let ident = p.parse_method_name();

let tps = p.parse_ty_params();
Expand Down Expand Up @@ -2528,13 +2528,14 @@ impl Parser {
self.parse_value_ident()
}

fn parse_method(pr: visibility) -> @method {
fn parse_method() -> @method {
let attrs = self.parse_outer_attributes();
let lo = self.span.lo;

let is_static = self.parse_staticness();
let static_sty = spanned(lo, self.span.hi, sty_static);

let visa = self.parse_visibility();
let pur = self.parse_fn_purity();
let ident = self.parse_method_name();
let tps = self.parse_ty_params();
Expand All @@ -2549,7 +2550,7 @@ impl Parser {
@{ident: ident, attrs: attrs,
tps: tps, self_ty: self_ty, purity: pur, decl: decl,
body: body, id: self.get_id(), span: mk_sp(lo, body.span.hi),
self_id: self.get_id(), vis: pr}
self_id: self.get_id(), vis: visa}
}

fn parse_item_trait() -> item_info {
Expand Down Expand Up @@ -2606,8 +2607,7 @@ impl Parser {
let mut meths = ~[];
self.expect(token::LBRACE);
while !self.eat(token::RBRACE) {
let vis = self.parse_visibility();
meths.push(self.parse_method(vis));
meths.push(self.parse_method());
}
(ident, item_impl(tps, opt_trait, ty, meths), None)
}
Expand Down Expand Up @@ -2763,7 +2763,7 @@ impl Parser {
return a_var;
} else {
self.obsolete(copy self.span, ObsoleteClassMethod);
return @method_member(self.parse_method(vis));
return @method_member(self.parse_method());
}
}

Expand Down Expand Up @@ -2869,9 +2869,9 @@ impl Parser {
(id, item_mod(m), Some(inner_attrs.inner))
}

fn parse_item_foreign_fn(vis: ast::visibility,
+attrs: ~[attribute]) -> @foreign_item {
fn parse_item_foreign_fn( +attrs: ~[attribute]) -> @foreign_item {
let lo = self.span.lo;
let vis = self.parse_visibility();
let purity = self.parse_fn_purity();
let t = self.parse_fn_header();
let (decl, _) = self.parse_fn_decl(|p| p.parse_arg());
Expand Down Expand Up @@ -2919,7 +2919,7 @@ impl Parser {
if self.is_keyword(~"const") {
self.parse_item_foreign_const(vis, move attrs)
} else {
self.parse_item_foreign_fn(vis, move attrs)
self.parse_item_foreign_fn( move attrs)
}
}

Expand Down Expand Up @@ -3239,7 +3239,7 @@ impl Parser {
maybe_append(attrs, extra_attrs)));
} else if foreign_items_allowed &&
(self.is_keyword(~"fn") || self.is_keyword(~"pure")) {
let item = self.parse_item_foreign_fn(visibility, attrs);
let item = self.parse_item_foreign_fn(attrs);
return iovi_foreign_item(item);
} else if items_allowed && self.is_keyword(~"unsafe")
&& self.look_ahead(1u) != token::LBRACE {
Expand Down
27 changes: 27 additions & 0 deletions src/test/run-pass/issue-3753.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Issue #3656
// Issue Name: pub method preceeded by attribute can't be parsed
// Abstract: Visibility parsing failed when compiler parsing

struct Point {
x: float,
y: float
}

pub enum Shape {
Circle(Point, float),
Rectangle(Point, Point)
}

pub impl Shape {
pub fn area(sh: Shape) -> float {
match sh {
Circle(_, size) => float::consts::pi * size * size,
Rectangle(Point {x, y}, Point {x: x2, y: y2}) => (x2 - x) * (y2 - y)
}
}
}

fn main(){
let s = Circle(Point { x: 1f, y: 2f }, 3f);
io::println(fmt!("%f", s.area(s)));
}