Skip to main content

json_syntax/parse/
boolean.rs

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