Fixes while writing lalrpop parser
diff --git a/src/attr.rs b/src/attr.rs
index 387759a..7e14f2d 100644
--- a/src/attr.rs
+++ b/src/attr.rs
@@ -58,12 +58,6 @@
)
));
- named!(quoted<&str, String>, delimited!(
- punct!("\""),
- escaped_string,
- tag_s!("\"")
- ));
-
named!(meta_item<&str, MetaItem>, alt_complete!(
do_parse!(
ident: word >>
@@ -82,6 +76,12 @@
|
map!(word, MetaItem::Word)
));
+
+ named!(quoted<&str, String>, delimited!(
+ punct!("\""),
+ escaped_string,
+ tag_s!("\"")
+ ));
}
#[cfg(feature = "printing")]
diff --git a/src/generics.rs b/src/generics.rs
index 2a00787..05d351f 100644
--- a/src/generics.rs
+++ b/src/generics.rs
@@ -110,7 +110,7 @@
life: lifetime >>
bounds: opt_vec!(preceded!(
punct!(":"),
- separated_nonempty_list!(punct!(","), lifetime)
+ separated_nonempty_list!(punct!("+"), lifetime)
)) >>
(LifetimeDef {
lifetime: life,
diff --git a/src/item.rs b/src/item.rs
index 7b4a955..d36caae 100644
--- a/src/item.rs
+++ b/src/item.rs
@@ -55,12 +55,12 @@
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 {
@@ -75,12 +75,12 @@
(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!(
diff --git a/src/lib.rs b/src/lib.rs
index cd7b545..c1951de 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -65,7 +65,7 @@
#[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
@@ -75,22 +75,21 @@
}
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;
+ }
}
}
}
diff --git a/src/ty.rs b/src/ty.rs
index 1850258..7b05272 100644
--- a/src/ty.rs
+++ b/src/ty.rs
@@ -224,8 +224,9 @@
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!(