iowo/crates/json-pawarser/src/grammar.rs

25 lines
681 B
Rust
Raw Normal View History

2024-10-23 11:01:39 +00:00
use array::array;
2024-10-18 12:05:27 +00:00
use enumset::{enum_set, EnumSet};
use crate::{syntax_error::SyntaxError, syntax_kind::SyntaxKind};
use self::object::object;
pub(crate) type Parser<'src> = pawarser::Parser<'src, SyntaxKind, SyntaxError>;
pub(crate) type CompletedMarker = pawarser::CompletedMarker<SyntaxKind, SyntaxError>;
2024-10-18 12:05:27 +00:00
const BASIC_VALUE_TOKENS: EnumSet<SyntaxKind> =
enum_set!(SyntaxKind::BOOL | SyntaxKind::NULL | SyntaxKind::NUMBER | SyntaxKind::STRING);
pub fn value(p: &mut Parser) -> bool {
if BASIC_VALUE_TOKENS.contains(p.current()) {
p.do_bump();
return true;
} else {
2024-10-23 11:01:39 +00:00
object(p).or_else(|| array(p)).is_some()
2024-10-18 12:05:27 +00:00
}
}
2024-10-23 11:27:36 +00:00
mod array;
mod object;