Closed anasbarg closed 5 years ago
Hello .. I have this piece of code that is trying to make sure that constant ends with a line break.
pub fn constant<'a>() -> Parser<'a, u8, Constant> { let parsed_constant = (space() * seq(b"const") - space()) * ((ident() - space() - sym(b'=')) + (space() * (regex() | string() | float() | integer()) - space())) - linebreak().repeat(1..).discard(); parsed_constant.map(|term| Constant { identifier: String::from(term.0), value: term.1, }) } fn linebreak<'a>() -> Parser<'a, u8, ()> { sym(b'\r').opt() * sym(b'\n').discard() }
But it's not seeing the line break at all. I'm loading the text from a file as a String then I convert it to &[u8] using .as_bytes(). The linebreak parser is copied as is from the whitespace example. Am I doing something wrong?
String
&[u8]
.as_bytes()
linebreak
Thank you
That was my bad. I had a conflicting definition of space that matches before reaching linebreak.
space
pub fn space<'a>() -> Parser<'a, u8, ()> { one_of(b" \n\t\r").repeat(0..).discard() }
Hello .. I have this piece of code that is trying to make sure that constant ends with a line break.
But it's not seeing the line break at all. I'm loading the text from a file as a
String
then I convert it to&[u8]
using.as_bytes()
. Thelinebreak
parser is copied as is from the whitespace example. Am I doing something wrong?Thank you