Skip to content

Commit

Permalink
Fixes while writing lalrpop parser
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Sep 6, 2016
1 parent 2b6f74c commit c94c38a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 31 deletions.
12 changes: 6 additions & 6 deletions src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,6 @@ pub mod parsing {
)
));

named!(quoted<&str, String>, delimited!(
punct!("\""),
escaped_string,
tag_s!("\"")
));

named!(meta_item<&str, MetaItem>, alt_complete!(
do_parse!(
ident: word >>
Expand All @@ -82,6 +76,12 @@ pub mod parsing {
|
map!(word, MetaItem::Word)
));

named!(quoted<&str, String>, delimited!(
punct!("\""),
escaped_string,
tag_s!("\"")
));
}

#[cfg(feature = "printing")]
Expand Down
2 changes: 1 addition & 1 deletion src/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub mod parsing {
life: lifetime >>
bounds: opt_vec!(preceded!(
punct!(":"),
separated_nonempty_list!(punct!(","), lifetime)
separated_nonempty_list!(punct!("+"), lifetime)
)) >>
(LifetimeDef {
lifetime: life,
Expand Down
12 changes: 6 additions & 6 deletions src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ pub mod parsing {
ident: word >>
generics: generics >>
item: switch!(value!(which),
"struct" => map!(struct_body, move |(style, fields)| Item {
"struct" => map!(struct_body, move |body| Item {
ident: ident,
vis: vis,
attrs: attrs,
generics: generics,
body: Body::Struct(style, fields),
body: body,
})
|
"enum" => map!(enum_body, move |body| Item {
Expand All @@ -75,12 +75,12 @@ pub mod parsing {
(item)
));

named!(struct_body<&str, (Style, Vec<Field>)>, alt_complete!(
struct_like_body => { |fields| (Style::Struct, fields) }
named!(struct_body<&str, Body>, alt_complete!(
struct_like_body => { |fields| Body::Struct(Style::Struct, fields) }
|
terminated!(tuple_like_body, punct!(";")) => { |fields| (Style::Tuple, fields) }
terminated!(tuple_like_body, punct!(";")) => { |fields| Body::Struct(Style::Tuple, fields) }
|
punct!(";") => { |_| (Style::Unit, Vec::new()) }
punct!(";") => { |_| Body::Struct(Style::Unit, Vec::new()) }
));

named!(enum_body<&str, Body>, do_parse!(
Expand Down
31 changes: 15 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub use ty::{

#[cfg(feature = "parsing")]
pub fn parse(input: &str) -> Item {
match item::parsing::item(input) {
return match item::parsing::item(input) {
nom::IResult::Done(rest, ast) => {
if rest.is_empty() {
ast
Expand All @@ -75,22 +75,21 @@ pub fn parse(input: &str) -> Item {
}
nom::IResult::Error(err) => raise(err),
nom::IResult::Incomplete(_) => panic!("incomplete input item"),
}
}
};

#[cfg(feature = "parsing")]
fn raise(mut err: nom::Err<&str>) -> ! {
loop {
match err {
nom::Err::Code(kind) => {
panic!("failed to parse {:?}", kind)
}
nom::Err::Position(kind, pos) => {
panic!("failed to parse {:?}: {:?}", kind, pos)
}
nom::Err::Node(_, next) |
nom::Err::NodePosition(_, _, next) => {
err = *next;
fn raise(mut err: nom::Err<&str>) -> ! {
loop {
match err {
nom::Err::Code(kind) => {
panic!("failed to parse {:?}", kind)
}
nom::Err::Position(kind, pos) => {
panic!("failed to parse {:?}: {:?}", kind, pos)
}
nom::Err::Node(_, next) |
nom::Err::NodePosition(_, _, next) => {
err = *next;
}
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,9 @@ pub mod parsing {
elem: ty >>
punct!(";") >>
option!(multispace) >>
size: map_res!(digit, str::parse) >>
(Ty::FixedLengthVec(Box::new(elem), size))
len: map_res!(digit, str::parse) >>
punct!("]") >>
(Ty::FixedLengthVec(Box::new(elem), len))
));

named!(ty_ptr<&str, Ty>, do_parse!(
Expand Down

0 comments on commit c94c38a

Please sign in to comment.