0

I am attempting to use the nom library to parse a FEN String. I have used an alt! macro to combine three smaller combinators that operate on a single character. Now I would like to use use that same combinator to parse a string of characters into a vector.

I am trying to use the many1! combinator to extract 1 or more fen_char. This is what I assumed would work, and I have tried some other variations non of which seemed to work.

named!(fen_chars<Vec<FENChar>>, many1!(fen_char));
let (_, x) = fen_chars(b"RNBQKBNR").unwrap();

assert_eq!(x.len(), 8);
assert_eq!(x[0], FENChar::Piece(Piece::Rook, Color::White));

When I run this I receive a failed option with value Incomplete(Size(1)). I'm not certain what to make of that.

BBS
  • 1,351
  • 2
  • 12
  • 27
  • Upgrade to nom4 if you didn't already, and use CompleteStr. https://github.com/Geal/nom/blob/master/doc/upgrading_to_nom_4.md#dealing-with-incomplete-usage – Valentin Lorentz Dec 20 '18 at 08:58
  • I had a similar issue which I solved by just adding a `"\n"` at the end of the input. I had some difficulty getting it to compile with `CompleteStr` or `CompleteByteSlice` and that was sufficient for my needs. – Peter Hall Dec 20 '18 at 19:36
  • Similarly to Peter Hall I'm having no success with CompleteStr or CompleteByteSlice, but adding a newline character at the end of the input is enough to do the trick. – BBS Dec 21 '18 at 01:19
  • Alright, I got to the point where I did need to use nom properly with ComleteByteSlice. I had some trouble realizing that child parsers also needed to use CompleteByteSlice, which seems obvious now, but in the moment never occurred to me. – BBS Dec 21 '18 at 05:27

0 Answers0