-
Notifications
You must be signed in to change notification settings - Fork 819
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
nom consuming 100% cpu #27
Comments
Update: This is harmless: named!(setting_name<&[u8], String>,
chain!(
h: map_res!(alpha, from_utf8) ~
t: map_res!(alt!(alphanumeric | tag!("-") | tag!("_")), from_utf8),
|| { let mut s = h.to_string(); s.push_str(t); s })); Apparently, adding |
Can I get back to you on Saturday about this issue? I am currently at a conference and do not have much time. Usually, when there was a lot of CPU and memory consumption, it was caused by the compiler having a hard time resolving macros. Since nom uses a lot of macros, it happens sometimes. You could try making a named function for the |
Sure, take your time. I tried with latest I'll try to follow your suggestion and go with a function when I have the chance. I'll let you know when I have news. Enjoy the conference! |
I've also experienced this with the |
Ok, can you share the code? I'll investigate.
|
After some digging I have a minimal test case that reproduces the issue. It is triggered by combining The same happens with This is enough to reproduce the bug: #[macro_use]
extern crate nom;
use nom::alphanumeric;
use nom::IResult;
use nom::IResult::*;
named!(just_a_test<&[u8], Vec<&[u8]> >,
many0!(alphanumeric));
fn main() {
println!("Entered main()");
let test = &b"1as32"[..];
let res = just_a_test(test);
println!("Parsed input");
assert_eq!(res, Done(&b""[..], vec![&b"1"[..], &b"a"[..], &b"s"[..], &b"3"[..], &b"2"[..]]));
} This will print In your opinion, what would be the correct way to fix this? I thought about changing Perhaps a better design would be for |
Good catch. I think I will also update |
Alright, good to know. I'll wait for your fix. Keep up the good job, this library is really cool. |
Here is a fix, let me know if this works for you. |
Works like a charm. Thanks! |
Great! |
Failing when nothing is parsed is probably not a great idea either, it may be better if For example, I'm trying to parse comments (in the context of a programming language), and have the following code: fn space0(input: &str) -> IResult<&str, &str> {
recognize(many0(tuple((
complete::multispace0,
opt(comment),
complete::multispace0,
))))(input)
} Unfortunately it fails when there is no whitespace, what can I do? |
@NilsIrl without detail of grammar of what you try to parse is gonna be hard to advice you. |
it should be possibl to make a separate function for |
I was able to fix it like so: fn space0(input: &str) -> IResult<&str, &str> {
recognize(many0(verify(
recognize(tuple((
complete::multispace0,
opt(comment),
complete::multispace0,
))),
|s: &str| !s.is_empty(),
)))(input)
} |
I am exploring the possibility of switching to
nom
in a project I am working on. I am not fully familiar withnom
yet, so please bear with me.For starters, I was trying to come up with a parser that matches strings of the form
[a-zA-Z][-a-zA-Z0-9_]*
. I wrote this:And I tested it with:
When I run
cargo test
my PC completely hangs. Withtop
I can see that it starts consuming more and more CPU and memory until the entire system is completely unusable and I have to hard reset.Am I doing something wrong? Is this the best way to make a parser to match this type of strings?
The text was updated successfully, but these errors were encountered: