Add HasExtraState
This commit is contained in:
parent
4b2430ceef
commit
619c2ff63b
@ -12,7 +12,7 @@ backward_trace = ["nom-tracable/backward_trace"]
|
||||
[dependencies]
|
||||
nom = "5.0.0"
|
||||
nom_locate = { path = "../../nom_locate" }
|
||||
nom-packrat = "0.1.17"
|
||||
nom-packrat = { path = "../../nom-packrat/nom-packrat" }
|
||||
nom-recursive = { path = "../../nom-recursive/nom-recursive" }
|
||||
nom-tracable = { path = "../../nom-tracable/nom-tracable" }
|
||||
str-concat = "*"
|
||||
|
@ -51,9 +51,9 @@ pub(crate) fn conditional_expression(s: Span) -> IResult<Span, ConditionalExpres
|
||||
#[tracable_parser]
|
||||
pub(crate) fn constant_expression(s: Span) -> IResult<Span, ConstantExpression> {
|
||||
alt((
|
||||
constant_expression_unary,
|
||||
constant_expression_binary,
|
||||
constant_expression_ternary,
|
||||
constant_expression_unary,
|
||||
map(constant_primary, |x| {
|
||||
ConstantExpression::ConstantPrimary(Box::new(x))
|
||||
}),
|
||||
@ -203,11 +203,6 @@ pub(crate) fn constant_indexed_range(s: Span) -> IResult<Span, ConstantIndexedRa
|
||||
#[tracable_parser]
|
||||
pub(crate) fn expression(s: Span) -> IResult<Span, Expression> {
|
||||
alt((
|
||||
expression_unary,
|
||||
map(inc_or_dec_expression, |x| {
|
||||
Expression::IncOrDecExpression(Box::new(x))
|
||||
}),
|
||||
expression_operator_assignment,
|
||||
expression_binary,
|
||||
map(conditional_expression, |x| {
|
||||
Expression::ConditionalExpression(Box::new(x))
|
||||
@ -215,6 +210,11 @@ pub(crate) fn expression(s: Span) -> IResult<Span, Expression> {
|
||||
map(inside_expression, |x| {
|
||||
Expression::InsideExpression(Box::new(x))
|
||||
}),
|
||||
expression_unary,
|
||||
map(inc_or_dec_expression, |x| {
|
||||
Expression::IncOrDecExpression(Box::new(x))
|
||||
}),
|
||||
expression_operator_assignment,
|
||||
map(tagged_union_expression, |x| {
|
||||
Expression::TaggedUnionExpression(Box::new(x))
|
||||
}),
|
||||
|
@ -31,8 +31,8 @@ pub(crate) use nom::error::{make_error, ErrorKind};
|
||||
pub(crate) use nom::multi::*;
|
||||
pub(crate) use nom::sequence::*;
|
||||
pub(crate) use nom::{Err, IResult};
|
||||
pub(crate) use nom_packrat::{self, packrat_parser};
|
||||
pub(crate) use nom_recursive::{recursive_parser, RecursiveInfo, RecursiveTracer};
|
||||
pub(crate) use nom_packrat::{self, packrat_parser, HasExtraState};
|
||||
pub(crate) use nom_recursive::{recursive_parser, HasRecursiveInfo, RecursiveInfo};
|
||||
pub(crate) use nom_tracable::tracable_parser;
|
||||
#[cfg(any(feature = "forward_trace", feature = "backward_trace"))]
|
||||
pub(crate) use nom_tracable::{HasTracableInfo, Tracable, TracableInfo};
|
||||
@ -50,12 +50,12 @@ pub struct SpanInfo {
|
||||
|
||||
pub type Span<'a> = nom_locate::LocatedSpanEx<&'a str, SpanInfo>;
|
||||
|
||||
impl RecursiveTracer for SpanInfo {
|
||||
fn get_info(&self) -> RecursiveInfo {
|
||||
impl HasRecursiveInfo for SpanInfo {
|
||||
fn get_recursive_info(&self) -> RecursiveInfo {
|
||||
self.recursive_info
|
||||
}
|
||||
|
||||
fn set_info(mut self, info: RecursiveInfo) -> Self {
|
||||
fn set_recursive_info(mut self, info: RecursiveInfo) -> Self {
|
||||
self.recursive_info = info;
|
||||
self
|
||||
}
|
||||
@ -73,9 +73,15 @@ impl HasTracableInfo for SpanInfo {
|
||||
}
|
||||
}
|
||||
|
||||
impl HasExtraState<RecursiveInfo> for SpanInfo {
|
||||
fn get_extra_state(&self) -> RecursiveInfo {
|
||||
self.recursive_info
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
nom_packrat::storage!(AnyNode);
|
||||
nom_packrat::storage!(AnyNode, RecursiveInfo);
|
||||
|
||||
pub fn parse_sv(s: &str) -> Result<SourceText, ()> {
|
||||
let s = Span::new_extra(s, SpanInfo::default());
|
||||
|
@ -789,3 +789,12 @@ fn test_attribute_instance() {
|
||||
Ok((_, _))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_expression() {
|
||||
test!(
|
||||
mintypmax_expression,
|
||||
"!a ? 0 : !b : 1 : c ? 0 : 1",
|
||||
Ok((_, _))
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user