Skip to content

Commit

Permalink
nom: tag! is streaming by default, use complete version instead
Browse files Browse the repository at this point in the history
  • Loading branch information
vthriller committed Sep 11, 2021
1 parent 0247d68 commit d7d11c8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
19 changes: 10 additions & 9 deletions src/expr.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use nom::IResult;
use nom::bytes::complete::tag;
use nom::number::complete::recognize_float;
use str::string;
use vec::{label_name, vector, Vector};
Expand Down Expand Up @@ -136,8 +137,8 @@ named!(label_list <&[u8], Vec<String>>, ws!(delimited!(

named!(function_aggregation <&[u8], AggregationMod>, ws!(do_parse!(
action: alt!(
tag!("by") => { |_| AggregationAction::By }
| tag!("without") => { |_| AggregationAction::Without }
call!(tag("by")) => { |_| AggregationAction::By }
| call!(tag("without")) => { |_| AggregationAction::Without }
) >>
labels: label_list >>
(AggregationMod { action, labels })
Expand Down Expand Up @@ -226,7 +227,7 @@ macro_rules! with_modifier {
// this macro mimicks another parser macros, hence implicit input argument, $i
// for comparison, see nom's call!()
($i:expr, $literal:expr, $op:expr) => {
map!($i, preceded!(tag!($literal), opt!(op_modifier)), |op_mod| {
map!($i, preceded!(call!(tag($literal)), opt!(op_modifier)), |op_mod| {
$op(op_mod)
})
};
Expand All @@ -237,8 +238,8 @@ macro_rules! with_bool_modifier {
ws!(
$i,
do_parse!(
tag!($literal)
>> boolness: opt!(tag!("bool"))
call!(tag($literal))
>> boolness: opt!(call!(tag("bool")))
>> op_mod: opt!(op_modifier)
>> ($op(boolness.is_some(), op_mod))
)
Expand All @@ -248,15 +249,15 @@ macro_rules! with_bool_modifier {

named!(op_modifier <&[u8], OpMod>, ws!(do_parse!(
action: alt!(
tag!("on") => { |_| OpModAction::RestrictTo }
| tag!("ignoring") => { |_| OpModAction::Ignore }
call!(tag("on")) => { |_| OpModAction::RestrictTo }
| call!(tag("ignoring")) => { |_| OpModAction::Ignore }
) >>
labels: label_list >>
// TODO > Grouping modifiers can only be used for comparison and arithmetic. Operations as and, unless and or operations match with all possible entries in the right vector by default.
group: opt!(ws!(do_parse!(
side: alt!(
tag!("group_left") => { |_| OpGroupSide::Left }
| tag!("group_right") => { |_| OpGroupSide::Right }
call!(tag("group_left")) => { |_| OpGroupSide::Left }
| call!(tag("group_right")) => { |_| OpGroupSide::Right }
) >>
labels: map!(
opt!(label_list),
Expand Down
15 changes: 9 additions & 6 deletions src/vec.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use nom::IResult;
use nom::bytes::complete::is_a;
use nom::bytes::complete::{
is_a,
tag,
};
use nom::character::complete::{
alpha1,
alphanumeric1,
Expand Down Expand Up @@ -137,7 +140,7 @@ pub(crate) fn vector(
do_parse!(
labels: call!(instant_vec, allow_periods)
>> range: opt!(delimited!(char!('['), range_literal, char!(']')))
>> offset: opt!(ws!(preceded!(tag!("offset"), range_literal)))
>> offset: opt!(ws!(preceded!(call!(tag("offset")), range_literal)))
>> (Vector {
labels,
range,
Expand Down Expand Up @@ -176,10 +179,10 @@ named_attr!(#[doc(hidden)], pub label_name <&[u8], String>, flat_map!(
));

named!(label_op <&[u8], LabelMatchOp>, alt!(
tag!("=~") => { |_| LabelMatchOp::REq }
| tag!("!~") => { |_| LabelMatchOp::RNe }
| tag!("=") => { |_| LabelMatchOp::Eq } // should come after =~
| tag!("!=") => { |_| LabelMatchOp::Ne }
call!(tag("=~")) => { |_| LabelMatchOp::REq }
| call!(tag("!~")) => { |_| LabelMatchOp::RNe }
| call!(tag("=")) => { |_| LabelMatchOp::Eq } // should come after =~
| call!(tag("!=")) => { |_| LabelMatchOp::Ne }
));

#[allow(unused_imports)]
Expand Down

0 comments on commit d7d11c8

Please sign in to comment.