json_syntax/parse/
boolean.rs

1use super::{Context, Error, Parse, Parser};
2use decoded_char::DecodedChar;
3use locspan::Meta;
4
5impl Parse for bool {
6	fn parse_in<C, E>(
7		parser: &mut Parser<C, E>,
8		_context: Context,
9	) -> Result<Meta<Self, usize>, Error<E>>
10	where
11		C: Iterator<Item = Result<DecodedChar, E>>,
12	{
13		let i = parser.begin_fragment();
14		match parser.next_char()? {
15			(_, Some('t')) => match parser.next_char()? {
16				(_, Some('r')) => match parser.next_char()? {
17					(_, Some('u')) => match parser.next_char()? {
18						(_, Some('e')) => {
19							parser.end_fragment(i);
20							Ok(Meta(true, i))
21						}
22						(p, unexpected) => Err(Error::unexpected(p, unexpected)),
23					},
24					(p, unexpected) => Err(Error::unexpected(p, unexpected)),
25				},
26				(p, unexpected) => Err(Error::unexpected(p, unexpected)),
27			},
28			(_, Some('f')) => match parser.next_char()? {
29				(_, Some('a')) => match parser.next_char()? {
30					(_, Some('l')) => match parser.next_char()? {
31						(_, Some('s')) => match parser.next_char()? {
32							(_, Some('e')) => {
33								parser.end_fragment(i);
34								Ok(Meta(false, i))
35							}
36							(p, unexpected) => Err(Error::unexpected(p, unexpected)),
37						},
38						(p, unexpected) => Err(Error::unexpected(p, unexpected)),
39					},
40					(p, unexpected) => Err(Error::unexpected(p, unexpected)),
41				},
42				(p, unexpected) => Err(Error::unexpected(p, unexpected)),
43			},
44			(p, unexpected) => Err(Error::unexpected(p, unexpected)),
45		}
46	}
47}