Skip to content

Commit

Permalink
nom bump
Browse files Browse the repository at this point in the history
  • Loading branch information
tomuxmon committed Jan 29, 2025
1 parent 863170c commit ee792ae
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion xml-mut-parse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ authors = ["Tomas Dambrauskas <[email protected]>"]
edition = "2021"

[dependencies]
nom = "7.1.3"
nom = "8.0.0"
xml-mut-data = { path = "../xml-mut-data" }
5 changes: 3 additions & 2 deletions xml-mut-parse/src/delete_clause.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use crate::{prelude::comma_surounded_mulispace01, where_clause::path_variant};
use nom::{
bytes::complete::tag_no_case, character::complete::multispace1, multi::separated_list1, IResult,
bytes::complete::tag_no_case, character::complete::multispace1, multi::separated_list1,
IResult, Parser,
};
use xml_mut_data::DeleteClause;

pub fn delete_clause(s: &str) -> IResult<&str, DeleteClause> {
let (s, delete_word) = tag_no_case("delete")(s)?;
let (s, _) = multispace1(s)?;
let (s, targets) = separated_list1(comma_surounded_mulispace01, path_variant)(s)?;
let (s, targets) = separated_list1(comma_surounded_mulispace01, path_variant).parse(s)?;

Ok((
s,
Expand Down
4 changes: 2 additions & 2 deletions xml-mut-parse/src/get_clause.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use nom::{
bytes::complete::{tag, tag_no_case, take_while1},
character::complete::multispace1,
multi::separated_list1,
IResult,
IResult, Parser,
};
use xml_mut_data::{GetClause, NodePath};

Expand All @@ -13,7 +13,7 @@ pub fn is_valid_in_xml_node_name(s: char) -> bool {
}

pub fn node_path(s: &str) -> IResult<&str, NodePath> {
let (s, path) = separated_list1(tag("/"), take_while1(is_valid_in_xml_node_name))(s)?;
let (s, path) = separated_list1(tag("/"), take_while1(is_valid_in_xml_node_name)).parse(s)?;
Ok((s, NodePath { path }))
}

Expand Down
8 changes: 4 additions & 4 deletions xml-mut-parse/src/mutation.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::prelude::*;
use nom::{character::complete::multispace1, combinator::opt, sequence::preceded, IResult};
use nom::{character::complete::multispace1, combinator::opt, sequence::preceded, IResult, Parser};
use xml_mut_data::Mutation;

pub fn mutation(s: &str) -> IResult<&str, Mutation> {
let (s, get_clause) = get_clause(s)?;
let (s, where_clause) = opt(preceded(multispace1, where_clause))(s)?;
let (s, where_clause) = opt(preceded(multispace1, where_clause)).parse(s)?;
let mem = s;
let (s, set_clause) = opt(preceded(multispace1, set_clause))(s)?;
let (s, delete_clause) = opt(preceded(multispace1, delete_clause))(s)?;
let (s, set_clause) = opt(preceded(multispace1, set_clause)).parse(s)?;
let (s, delete_clause) = opt(preceded(multispace1, delete_clause)).parse(s)?;

if set_clause.is_none() && delete_clause.is_none() {
return Err(nom::Err::Error(nom::error::Error {
Expand Down
9 changes: 5 additions & 4 deletions xml-mut-parse/src/set_clause.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ use nom::{
combinator::opt,
multi::separated_list1,
sequence::delimited,
IResult,
IResult, Parser,
};
use xml_mut_data::{SetClause, ValueAssignment, ValueVariant};

pub fn literal_quoted_string(s: &str) -> IResult<&str, &str> {
let (s, res) = delimited(char('\"'), take_till(|c| c == '\"'), char('\"'))(s)?;
let (s, res) = delimited(char('\"'), take_till(|c| c == '\"'), char('\"')).parse(s)?;
Ok((s, res))
}

pub fn value_variant(s: &str) -> IResult<&str, ValueVariant> {
let (s, maybe_p_node_exists) = opt(value_path)(s)?;
let (s, maybe_p_node_exists) = opt(value_path).parse(s)?;
Ok(if let Some(p_node_exists) = maybe_p_node_exists {
(s, ValueVariant::Selector(p_node_exists))
} else {
Expand Down Expand Up @@ -44,7 +44,8 @@ pub fn comma_surounded_mulispace01(s: &str) -> IResult<&str, &str> {
pub fn set_clause(s: &str) -> IResult<&str, SetClause> {
let (s, set_word) = tag_no_case("set")(s)?;
let (s, _) = multispace1(s)?;
let (s, assignments) = separated_list1(comma_surounded_mulispace01, value_assignment)(s)?;
let (s, assignments) =
separated_list1(comma_surounded_mulispace01, value_assignment).parse(s)?;
Ok((
s,
SetClause {
Expand Down
8 changes: 4 additions & 4 deletions xml-mut-parse/src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ use nom::{
combinator::opt,
multi::separated_list1,
sequence::delimited,
IResult,
IResult, Parser,
};
use xml_mut_data::{Statement, XmlMutGrammar};

fn block_comment(s: &str) -> IResult<&str, &str> {
let (s, comment) = delimited(tag("/*"), take_until("*/"), tag("*/"))(s)?;
let (s, comment) = delimited(tag("/*"), take_until("*/"), tag("*/")).parse(s)?;
Ok((s, comment))
}

// TODO: impl line comment

pub fn statement(s: &str) -> IResult<&str, Statement> {
let (s, comment) = opt(block_comment)(s)?;
let (s, comment) = opt(block_comment).parse(s)?;
if let Some(comment) = comment {
return Ok((s, Statement::Comment(comment)));
}
Expand All @@ -27,7 +27,7 @@ pub fn statement(s: &str) -> IResult<&str, Statement> {

pub fn xml_mut_grammar(s: &str) -> IResult<&str, XmlMutGrammar> {
let (s, _) = multispace0(s)?;
let (s, statements) = separated_list1(multispace1, statement)(s)?;
let (s, statements) = separated_list1(multispace1, statement).parse(s)?;
let (s, _) = multispace0(s)?;

Ok((s, XmlMutGrammar { statements }))
Expand Down
12 changes: 6 additions & 6 deletions xml-mut-parse/src/where_clause.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use nom::{
character::complete::multispace1,
combinator::opt,
multi::separated_list1,
IResult,
IResult, Parser,
};
use xml_mut_data::{
NodePath, PathVariant, Predicate, PredicateEquals, PredicateExists, ValuePath, ValueSelector,
Expand All @@ -13,7 +13,7 @@ use xml_mut_data::{

pub fn value_source(s: &str) -> IResult<&str, ValueSelector> {
let (s, _) = tag("[")(s)?;
let (s, at) = opt(tag("@"))(s)?;
let (s, at) = opt(tag("@")).parse(s)?;
let (s, name) = take_till(|c: char| c == ']')(s)?;
let (s, _) = tag("]")(s)?;

Expand All @@ -35,7 +35,7 @@ pub fn value_source(s: &str) -> IResult<&str, ValueSelector> {
}

pub fn value_path(s: &str) -> IResult<&str, ValuePath> {
let (s, node_path) = opt(node_path)(s)?;
let (s, node_path) = opt(node_path).parse(s)?;
let (s, source) = value_source(s)?;
Ok(if let Some(node_path) = node_path {
(
Expand All @@ -58,7 +58,7 @@ pub fn value_path(s: &str) -> IResult<&str, ValuePath> {

// TODO: non desttructive parse of node path or value selector
pub fn path_variant(s: &str) -> IResult<&str, PathVariant> {
let (s, value) = opt(value_path)(s)?;
let (s, value) = opt(value_path).parse(s)?;
if let Some(value) = value {
Ok((s, PathVariant::Value(value)))
} else {
Expand Down Expand Up @@ -92,7 +92,7 @@ pub fn predicate_equals(s: &str) -> IResult<&str, PredicateEquals> {
}

pub fn predicate(s: &str) -> IResult<&str, Predicate> {
let (s, maybe_p_node_exists) = opt(predicate_node_exists)(s)?;
let (s, maybe_p_node_exists) = opt(predicate_node_exists).parse(s)?;

Ok(if let Some(p_node_exists) = maybe_p_node_exists {
(s, Predicate::Exists(p_node_exists))
Expand All @@ -113,7 +113,7 @@ fn and_surounded_mulispace1(s: &str) -> IResult<&str, &str> {
pub fn where_clause(s: &str) -> IResult<&str, WhereClause> {
let (s, where_word) = tag_no_case("where")(s)?;
let (s, _) = multispace1(s)?;
let (s, predicates) = separated_list1(and_surounded_mulispace1, predicate)(s)?;
let (s, predicates) = separated_list1(and_surounded_mulispace1, predicate).parse(s)?;

Ok((
s,
Expand Down

0 comments on commit ee792ae

Please sign in to comment.