pub fn seq<'a, 'b: 'a, I>(tag: &'b [I]) -> Parser<'a, I, &'a [I]>Expand description
Success when sequence of symbols matches current input.
Examples found in repository?
More examples
examples/whitespace.rs (line 58)
57fn container<'a>() -> Parser<'a, u8, Container> {
58 seq(b"Container\n") *
59 (
60 indented() |
61 empty().map(|()| vec![])
62 ).repeat(1..).map(
63 |lines| lines.into_iter().filter(
64 |line| line.len() > 0
65 ).fold(
66 vec![],
67 |accum, line| accum.into_iter().chain(
68 line.into_iter().chain(vec![b'\n'].into_iter())
69 ).collect()
70 )
71 ).map(|deden| {
72 subcontainer().parse(&deden).expect("subcont")
73 }).map(|(containers, contents)| Container { containers, contents })
74}examples/json.rs (line 36)
30fn string<'a>() -> Parser<'a, u8, String> {
31 let special_char = sym(b'\\') | sym(b'/') | sym(b'"')
32 | sym(b'b').map(|_|b'\x08') | sym(b'f').map(|_|b'\x0C')
33 | sym(b'n').map(|_|b'\n') | sym(b'r').map(|_|b'\r') | sym(b't').map(|_|b'\t');
34 let escape_sequence = sym(b'\\') * special_char;
35 let char_string = (none_of(b"\\\"") | escape_sequence).repeat(1..).convert(String::from_utf8);
36 let utf16_char = seq(b"\\u") * is_a(hex_digit).repeat(4).convert(String::from_utf8).convert(|digits|u16::from_str_radix(&digits, 16));
37 let utf16_string = utf16_char.repeat(1..).map(|chars|decode_utf16(chars).map(|r| r.unwrap_or(REPLACEMENT_CHARACTER)).collect::<String>());
38 let string = sym(b'"') * (char_string | utf16_string).repeat(0..) - sym(b'"');
39 string.map(|strings| strings.concat())
40}
41
42fn array<'a>() -> Parser<'a, u8, Vec<JsonValue>> {
43 let elems = list(call(value), sym(b',') * space());
44 sym(b'[') * space() * elems - sym(b']')
45}
46
47fn object<'a>() -> Parser<'a, u8, HashMap<String, JsonValue>> {
48 let member = string() - space() - sym(b':') - space() + call(value);
49 let members = list(member, sym(b',') * space());
50 let obj = sym(b'{') * space() * members - sym(b'}');
51 obj.map(|members| members.into_iter().collect::<HashMap<_, _>>())
52}
53
54fn value<'a>() -> Parser<'a, u8, JsonValue> {
55 ( seq(b"null").map(|_|JsonValue::Null)
56 | seq(b"true").map(|_|JsonValue::Bool(true))
57 | seq(b"false").map(|_|JsonValue::Bool(false))
58 | number().map(|num|JsonValue::Num(num))
59 | string().map(|text|JsonValue::Str(text))
60 | array().map(|arr|JsonValue::Array(arr))
61 | object().map(|obj|JsonValue::Object(obj))
62 ) - space()
63}