Use mentat-parser-utils in tx-parser. Fixes #235; r=rnewman,victorporof
Move macros query-parser/…/parser_utils.rs → parser-utils/…/query.rs Signed-off-by: Joe Walker <jwalker@mozilla.com>
This commit is contained in:
parent
1deed24f42
commit
f591c90738
6 changed files with 182 additions and 238 deletions
|
@ -5,3 +5,6 @@ authors = ["Victor Porof <vporof@mozilla.com>", "Richard Newman <rnewman@mozilla
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
combine = "2.1.1"
|
combine = "2.1.1"
|
||||||
|
|
||||||
|
[dependencies.edn]
|
||||||
|
path = "../edn"
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
// specific language governing permissions and limitations under the License.
|
// specific language governing permissions and limitations under the License.
|
||||||
|
|
||||||
extern crate combine;
|
extern crate combine;
|
||||||
|
extern crate edn;
|
||||||
|
|
||||||
use combine::ParseResult;
|
use combine::ParseResult;
|
||||||
use combine::combinator::{Expected, FnParser};
|
use combine::combinator::{Expected, FnParser};
|
||||||
|
@ -39,3 +40,68 @@ macro_rules! satisfy_unwrap {
|
||||||
satisfy_map(|x: edn::Value| if let $cas($var) = x $body else { None })
|
satisfy_map(|x: edn::Value| if let $cas($var) = x $body else { None })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Generate a `satisfy_map` expression that matches a `PlainSymbol`
|
||||||
|
/// value with the given name.
|
||||||
|
///
|
||||||
|
/// We do this rather than using `combine::token` so that we don't
|
||||||
|
/// need to allocate a new `String` inside a `PlainSymbol` inside a `Value`
|
||||||
|
/// just to match input.
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! matches_plain_symbol {
|
||||||
|
($name: expr, $input: ident) => {
|
||||||
|
satisfy_map(|x: edn::Value| {
|
||||||
|
if let edn::Value::PlainSymbol(ref s) = x {
|
||||||
|
if s.0.as_str() == $name {
|
||||||
|
return Some(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return None;
|
||||||
|
}).parse_stream($input)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Define an `impl` body for the `$parser` type. The body will contain a parser
|
||||||
|
/// function called `$name`, consuming a stream of `$item_type`s. The parser's
|
||||||
|
/// result type will be `$result_type`.
|
||||||
|
///
|
||||||
|
/// The provided `$body` will be evaluated with `$input` bound to the input stream.
|
||||||
|
///
|
||||||
|
/// `$body`, when run, should return a `ParseResult` of the appropriate result type.
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! def_parser_fn {
|
||||||
|
( $parser: ident, $name: ident, $item_type: ty, $result_type: ty, $input: ident, $body: block ) => {
|
||||||
|
impl<I> $parser<I> where I: Stream<Item = $item_type> {
|
||||||
|
fn $name() -> ResultParser<$result_type, I> {
|
||||||
|
fn inner<I: Stream<Item = $item_type>>($input: I) -> ParseResult<$result_type, I> {
|
||||||
|
$body
|
||||||
|
}
|
||||||
|
parser(inner as fn(I) -> ParseResult<$result_type, I>).expected("$name")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `def_value_parser_fn` is a short-cut to `def_parser_fn` with the input type
|
||||||
|
/// being `edn::Value`.
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! def_value_parser_fn {
|
||||||
|
( $parser: ident, $name: ident, $result_type: ty, $input: ident, $body: block ) => {
|
||||||
|
def_parser_fn!($parser, $name, edn::Value, $result_type, $input, $body);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `def_value_satisfy_parser_fn` is a short-cut to `def_parser_fn` with the input type
|
||||||
|
/// being `edn::Value` and the body being a call to `satisfy_map` with the given transformer.
|
||||||
|
///
|
||||||
|
/// In practice this allows you to simply pass a function that accepts an `&edn::Value` and
|
||||||
|
/// returns an `Option<$result_type>`: if a suitable value is at the front of the stream,
|
||||||
|
/// it will be converted and returned by the parser; otherwise, the parse will fail.
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! def_value_satisfy_parser_fn {
|
||||||
|
( $parser: ident, $name: ident, $result_type: ty, $transformer: path ) => {
|
||||||
|
def_value_parser_fn!($parser, $name, $result_type, input, {
|
||||||
|
satisfy_map(|x: edn::Value| $transformer(&x)).parse_stream(input)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -14,8 +14,6 @@ extern crate matches;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate mentat_parser_utils;
|
extern crate mentat_parser_utils;
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
mod parser_util;
|
|
||||||
mod util;
|
mod util;
|
||||||
mod parse;
|
mod parse;
|
||||||
pub mod find;
|
pub mod find;
|
||||||
|
|
|
@ -1,76 +0,0 @@
|
||||||
// Copyright 2016 Mozilla
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
||||||
// this file except in compliance with the License. You may obtain a copy of the
|
|
||||||
// License at http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
// Unless required by applicable law or agreed to in writing, software distributed
|
|
||||||
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
||||||
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
||||||
// specific language governing permissions and limitations under the License.
|
|
||||||
|
|
||||||
extern crate combine;
|
|
||||||
extern crate edn;
|
|
||||||
|
|
||||||
extern crate mentat_parser_utils;
|
|
||||||
extern crate mentat_query;
|
|
||||||
|
|
||||||
/// Generate a `satisfy_map` expression that matches a `PlainSymbol`
|
|
||||||
/// value with the given name.
|
|
||||||
///
|
|
||||||
/// We do this rather than using `combine::token` so that we don't
|
|
||||||
/// need to allocate a new `String` inside a `PlainSymbol` inside a `Value`
|
|
||||||
/// just to match input.
|
|
||||||
macro_rules! matches_plain_symbol {
|
|
||||||
($name: expr, $input: ident) => {
|
|
||||||
satisfy_map(|x: edn::Value| {
|
|
||||||
if let edn::Value::PlainSymbol(ref s) = x {
|
|
||||||
if s.0.as_str() == $name {
|
|
||||||
return Some(());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return None;
|
|
||||||
}).parse_stream($input)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Define an `impl` body for the `$parser` type. The body will contain a parser
|
|
||||||
/// function called `$name`, consuming a stream of `$item_type`s. The parser's
|
|
||||||
/// result type will be `$result_type`.
|
|
||||||
///
|
|
||||||
/// The provided `$body` will be evaluated with `$input` bound to the input stream.
|
|
||||||
///
|
|
||||||
/// `$body`, when run, should return a `ParseResult` of the appropriate result type.
|
|
||||||
macro_rules! def_parser_fn {
|
|
||||||
( $parser: ident, $name: ident, $item_type: ty, $result_type: ty, $input: ident, $body: block ) => {
|
|
||||||
impl<I> $parser<I> where I: Stream<Item = $item_type> {
|
|
||||||
fn $name() -> ResultParser<$result_type, I> {
|
|
||||||
fn inner<I: Stream<Item = $item_type>>($input: I) -> ParseResult<$result_type, I> {
|
|
||||||
$body
|
|
||||||
}
|
|
||||||
parser(inner as fn(I) -> ParseResult<$result_type, I>).expected("$name")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `def_value_parser_fn` is a short-cut to `def_parser_fn` with the input type
|
|
||||||
/// being `edn::Value`.
|
|
||||||
macro_rules! def_value_parser_fn {
|
|
||||||
( $parser: ident, $name: ident, $result_type: ty, $input: ident, $body: block ) => {
|
|
||||||
def_parser_fn!($parser, $name, edn::Value, $result_type, $input, $body);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `def_value_satisfy_parser_fn` is a short-cut to `def_parser_fn` with the input type
|
|
||||||
/// being `edn::Value` and the body being a call to `satisfy_map` with the given transformer.
|
|
||||||
///
|
|
||||||
/// In practice this allows you to simply pass a function that accepts an `&edn::Value` and
|
|
||||||
/// returns an `Option<$result_type>`: if a suitable value is at the front of the stream,
|
|
||||||
/// it will be converted and returned by the parser; otherwise, the parse will fail.
|
|
||||||
macro_rules! def_value_satisfy_parser_fn {
|
|
||||||
( $parser: ident, $name: ident, $result_type: ty, $transformer: path ) => {
|
|
||||||
def_value_parser_fn!($parser, $name, $result_type, input, {
|
|
||||||
satisfy_map(|x: edn::Value| $transformer(&x)).parse_stream(input)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -10,3 +10,6 @@ combine = "2.1.1"
|
||||||
|
|
||||||
[dependencies.mentat_tx]
|
[dependencies.mentat_tx]
|
||||||
path = "../tx"
|
path = "../tx"
|
||||||
|
|
||||||
|
[dependencies.mentat_parser_utils]
|
||||||
|
path = "../parser-utils"
|
||||||
|
|
|
@ -14,11 +14,15 @@ extern crate edn;
|
||||||
extern crate combine;
|
extern crate combine;
|
||||||
extern crate mentat_tx;
|
extern crate mentat_tx;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate mentat_parser_utils;
|
||||||
|
|
||||||
use combine::{any, eof, many, parser, satisfy_map, token, Parser, ParseResult, Stream};
|
use combine::{any, eof, many, parser, satisfy_map, token, Parser, ParseResult, Stream};
|
||||||
use combine::combinator::{Expected, FnParser};
|
use combine::combinator::{Expected, FnParser};
|
||||||
use edn::symbols::NamespacedKeyword;
|
use edn::symbols::NamespacedKeyword;
|
||||||
use edn::types::Value;
|
use edn::types::Value;
|
||||||
use mentat_tx::entities::{Entid, EntidOrLookupRef, Entity, LookupRef, OpType, ValueOrLookupRef};
|
use mentat_tx::entities::{Entid, EntidOrLookupRef, Entity, LookupRef, OpType, ValueOrLookupRef};
|
||||||
|
use mentat_parser_utils::ResultParser;
|
||||||
|
|
||||||
pub struct Tx<I>(::std::marker::PhantomData<fn(I) -> I>);
|
pub struct Tx<I>(::std::marker::PhantomData<fn(I) -> I>);
|
||||||
|
|
||||||
|
@ -30,181 +34,128 @@ fn fn_parser<O, I>(f: fn(I) -> ParseResult<O, I>, err: &'static str) -> TxParser
|
||||||
parser(f).expected(err)
|
parser(f).expected(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I> Tx<I>
|
def_value_satisfy_parser_fn!(Tx, integer, i64, Value::as_integer);
|
||||||
where I: Stream<Item = Value>
|
|
||||||
{
|
|
||||||
fn integer() -> TxParser<i64, I> {
|
|
||||||
fn_parser(Tx::<I>::integer_, "integer")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn integer_(input: I) -> ParseResult<i64, I> {
|
fn value_to_namespaced_keyword(val: &Value) -> Option<NamespacedKeyword> {
|
||||||
return satisfy_map(|x: Value| if let Value::Integer(y) = x {
|
val.as_namespaced_keyword().map(|x| x.clone())
|
||||||
Some(y)
|
}
|
||||||
} else {
|
def_value_satisfy_parser_fn!(Tx, keyword, NamespacedKeyword, value_to_namespaced_keyword);
|
||||||
None
|
|
||||||
})
|
|
||||||
.parse_stream(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn keyword() -> TxParser<NamespacedKeyword, I> {
|
def_parser_fn!(Tx, entid, Value, Entid, input, {
|
||||||
fn_parser(Tx::<I>::keyword_, "keyword")
|
Tx::<I>::integer()
|
||||||
}
|
.map(|x| Entid::Entid(x))
|
||||||
|
.or(Tx::<I>::keyword().map(|x| Entid::Ident(x)))
|
||||||
|
.parse_lazy(input)
|
||||||
|
.into()
|
||||||
|
});
|
||||||
|
|
||||||
fn keyword_(input: I) -> ParseResult<NamespacedKeyword, I> {
|
def_parser_fn!(Tx, lookup_ref, Value, LookupRef, input, {
|
||||||
return satisfy_map(|x: Value| if let Value::NamespacedKeyword(y) = x {
|
satisfy_map(|x: Value| if let Value::Vector(y) = x {
|
||||||
Some(y)
|
let mut p = (Tx::<&[Value]>::entid(), any(), eof())
|
||||||
} else {
|
.map(|(a, v, _)| LookupRef { a: a, v: v });
|
||||||
None
|
let r = p.parse_lazy(&y[..]).into();
|
||||||
})
|
match r {
|
||||||
.parse_stream(input);
|
Ok((r, _)) => Some(r),
|
||||||
}
|
_ => None,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
})
|
||||||
|
.parse_stream(input)
|
||||||
|
});
|
||||||
|
|
||||||
fn entid() -> TxParser<Entid, I> {
|
def_parser_fn!(Tx, entid_or_lookup_ref, Value, EntidOrLookupRef, input, {
|
||||||
fn_parser(Tx::<I>::entid_, "entid")
|
Tx::<I>::entid()
|
||||||
}
|
.map(|x| EntidOrLookupRef::Entid(x))
|
||||||
|
.or(Tx::<I>::lookup_ref().map(|x| EntidOrLookupRef::LookupRef(x)))
|
||||||
|
.parse_lazy(input)
|
||||||
|
.into()
|
||||||
|
});
|
||||||
|
|
||||||
fn entid_(input: I) -> ParseResult<Entid, I> {
|
// TODO: abstract the "match Vector, parse internal stream" pattern to remove this boilerplate.
|
||||||
let p = Tx::<I>::integer()
|
def_parser_fn!(Tx, add, Value, Entity, input, {
|
||||||
.map(|x| Entid::Entid(x))
|
satisfy_map(|x: Value| -> Option<Entity> {
|
||||||
.or(Tx::<I>::keyword().map(|x| Entid::Ident(x)))
|
if let Value::Vector(y) = x {
|
||||||
.parse_lazy(input)
|
let mut p = (token(Value::NamespacedKeyword(NamespacedKeyword::new("db", "add"))),
|
||||||
.into();
|
Tx::<&[Value]>::entid_or_lookup_ref(),
|
||||||
return p;
|
Tx::<&[Value]>::entid(),
|
||||||
}
|
// TODO: handle lookup-ref.
|
||||||
|
any(),
|
||||||
fn lookup_ref() -> TxParser<LookupRef, I> {
|
eof())
|
||||||
fn_parser(Tx::<I>::lookup_ref_, "lookup-ref")
|
.map(|(_, e, a, v, _)| {
|
||||||
}
|
Entity::AddOrRetract {
|
||||||
|
op: OpType::Add,
|
||||||
fn lookup_ref_(input: I) -> ParseResult<LookupRef, I> {
|
e: e,
|
||||||
return satisfy_map(|x: Value| if let Value::Vector(y) = x {
|
a: a,
|
||||||
let mut p = (Tx::<&[Value]>::entid(), any(), eof())
|
v: ValueOrLookupRef::Value(v),
|
||||||
.map(|(a, v, _)| LookupRef { a: a, v: v });
|
}
|
||||||
let r = p.parse_lazy(&y[..]).into();
|
});
|
||||||
match r {
|
// TODO: use ok() with a type annotation rather than explicit match.
|
||||||
|
match p.parse_lazy(&y[..]).into() {
|
||||||
Ok((r, _)) => Some(r),
|
Ok((r, _)) => Some(r),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
})
|
}
|
||||||
.parse_stream(input);
|
})
|
||||||
}
|
.parse_stream(input)
|
||||||
|
});
|
||||||
|
|
||||||
fn entid_or_lookup_ref() -> TxParser<EntidOrLookupRef, I> {
|
def_parser_fn!(Tx, retract, Value, Entity, input, {
|
||||||
fn_parser(Tx::<I>::entid_or_lookup_ref_, "entid|lookup-ref")
|
satisfy_map(|x: Value| -> Option<Entity> {
|
||||||
}
|
if let Value::Vector(y) = x {
|
||||||
|
let mut p = (token(Value::NamespacedKeyword(NamespacedKeyword::new("db", "retract"))),
|
||||||
fn entid_or_lookup_ref_(input: I) -> ParseResult<EntidOrLookupRef, I> {
|
Tx::<&[Value]>::entid_or_lookup_ref(),
|
||||||
let p = Tx::<I>::entid()
|
Tx::<&[Value]>::entid(),
|
||||||
.map(|x| EntidOrLookupRef::Entid(x))
|
// TODO: handle lookup-ref.
|
||||||
.or(Tx::<I>::lookup_ref().map(|x| EntidOrLookupRef::LookupRef(x)))
|
any(),
|
||||||
.parse_lazy(input)
|
eof())
|
||||||
.into();
|
.map(|(_, e, a, v, _)| {
|
||||||
return p;
|
Entity::AddOrRetract {
|
||||||
}
|
op: OpType::Retract,
|
||||||
|
e: e,
|
||||||
// TODO: abstract the "match Vector, parse internal stream" pattern to remove this boilerplate.
|
a: a,
|
||||||
fn add_(input: I) -> ParseResult<Entity, I> {
|
v: ValueOrLookupRef::Value(v),
|
||||||
return satisfy_map(|x: Value| -> Option<Entity> {
|
}
|
||||||
if let Value::Vector(y) = x {
|
});
|
||||||
let mut p = (token(Value::NamespacedKeyword(NamespacedKeyword::new("db",
|
// TODO: use ok() with a type annotation rather than explicit match.
|
||||||
"add"))),
|
match p.parse_lazy(&y[..]).into() {
|
||||||
Tx::<&[Value]>::entid_or_lookup_ref(),
|
Ok((r, _)) => Some(r),
|
||||||
Tx::<&[Value]>::entid(),
|
_ => None,
|
||||||
// TODO: handle lookup-ref.
|
|
||||||
any(),
|
|
||||||
eof())
|
|
||||||
.map(|(_, e, a, v, _)| {
|
|
||||||
Entity::AddOrRetract {
|
|
||||||
op: OpType::Add,
|
|
||||||
e: e,
|
|
||||||
a: a,
|
|
||||||
v: ValueOrLookupRef::Value(v),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// TODO: use ok() with a type annotation rather than explicit match.
|
|
||||||
match p.parse_lazy(&y[..]).into() {
|
|
||||||
Ok((r, _)) => Some(r),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
})
|
} else {
|
||||||
.parse_stream(input);
|
None
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.parse_stream(input)
|
||||||
|
});
|
||||||
|
|
||||||
fn add() -> TxParser<Entity, I> {
|
def_parser_fn!(Tx, entity, Value, Entity, input, {
|
||||||
fn_parser(Tx::<I>::add_, "[:db/add e a v]")
|
let mut p = Tx::<I>::add()
|
||||||
}
|
.or(Tx::<I>::retract());
|
||||||
|
p.parse_stream(input)
|
||||||
|
});
|
||||||
|
|
||||||
fn retract_(input: I) -> ParseResult<Entity, I> {
|
def_parser_fn!(Tx, entities, Value, Vec<Entity>, input, {
|
||||||
return satisfy_map(|x: Value| -> Option<Entity> {
|
satisfy_map(|x: Value| -> Option<Vec<Entity>> {
|
||||||
if let Value::Vector(y) = x {
|
if let Value::Vector(y) = x {
|
||||||
let mut p = (token(Value::NamespacedKeyword(NamespacedKeyword::new("db",
|
let mut p = (many(Tx::<&[Value]>::entity()), eof()).map(|(es, _)| es);
|
||||||
"retract"))),
|
// TODO: use ok() with a type annotation rather than explicit match.
|
||||||
Tx::<&[Value]>::entid_or_lookup_ref(),
|
match p.parse_lazy(&y[..]).into() {
|
||||||
Tx::<&[Value]>::entid(),
|
Ok((r, _)) => Some(r),
|
||||||
// TODO: handle lookup-ref.
|
_ => None,
|
||||||
any(),
|
|
||||||
eof())
|
|
||||||
.map(|(_, e, a, v, _)| {
|
|
||||||
Entity::AddOrRetract {
|
|
||||||
op: OpType::Retract,
|
|
||||||
e: e,
|
|
||||||
a: a,
|
|
||||||
v: ValueOrLookupRef::Value(v),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// TODO: use ok() with a type annotation rather than explicit match.
|
|
||||||
match p.parse_lazy(&y[..]).into() {
|
|
||||||
Ok((r, _)) => Some(r),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
})
|
} else {
|
||||||
.parse_stream(input);
|
None
|
||||||
}
|
}
|
||||||
|
})
|
||||||
fn retract() -> TxParser<Entity, I> {
|
.parse_stream(input)
|
||||||
fn_parser(Tx::<I>::retract_, "[:db/retract e a v]")
|
});
|
||||||
}
|
|
||||||
|
|
||||||
fn entity_(input: I) -> ParseResult<Entity, I> {
|
|
||||||
let mut p = Tx::<I>::add()
|
|
||||||
.or(Tx::<I>::retract());
|
|
||||||
p.parse_stream(input)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn entity() -> TxParser<Entity, I> {
|
|
||||||
fn_parser(Tx::<I>::entity_,
|
|
||||||
"[:db/add|:db/retract ...]")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn entities_(input: I) -> ParseResult<Vec<Entity>, I> {
|
|
||||||
return satisfy_map(|x: Value| -> Option<Vec<Entity>> {
|
|
||||||
if let Value::Vector(y) = x {
|
|
||||||
let mut p = (many(Tx::<&[Value]>::entity()), eof()).map(|(es, _)| es);
|
|
||||||
// TODO: use ok() with a type annotation rather than explicit match.
|
|
||||||
match p.parse_lazy(&y[..]).into() {
|
|
||||||
Ok((r, _)) => Some(r),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.parse_stream(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn entities() -> TxParser<Vec<Entity>, I> {
|
|
||||||
fn_parser(Tx::<I>::entities_,
|
|
||||||
"[[:db/add|:db/retract ...]*]")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
impl<I> Tx<I>
|
||||||
|
where I: Stream<Item = Value>
|
||||||
|
{
|
||||||
pub fn parse(input: I) -> Result<Vec<Entity>, combine::ParseError<I>> {
|
pub fn parse(input: I) -> Result<Vec<Entity>, combine::ParseError<I>> {
|
||||||
(Tx::<I>::entities(), eof())
|
(Tx::<I>::entities(), eof())
|
||||||
.map(|(es, _)| es)
|
.map(|(es, _)| es)
|
||||||
|
@ -219,7 +170,6 @@ mod tests {
|
||||||
use combine::Parser;
|
use combine::Parser;
|
||||||
use edn::symbols::NamespacedKeyword;
|
use edn::symbols::NamespacedKeyword;
|
||||||
use edn::types::Value;
|
use edn::types::Value;
|
||||||
use mentat_tx::entities::*;
|
|
||||||
|
|
||||||
fn kw(namespace: &str, name: &str) -> Value {
|
fn kw(namespace: &str, name: &str) -> Value {
|
||||||
Value::NamespacedKeyword(NamespacedKeyword::new(namespace, name))
|
Value::NamespacedKeyword(NamespacedKeyword::new(namespace, name))
|
||||||
|
|
Loading…
Reference in a new issue