From: Mark Thom Date: Sun, 23 Feb 2020 20:16:14 +0000 (-0700) Subject: update prolog_parser version, allow ('|') operator in DCGs (#274) X-Git-Tag: v0.8.119~71 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=8ba92d8b99f704d92979da5e6eca143eaa5caea7;p=scryer-prolog.git update prolog_parser version, allow ('|') operator in DCGs (#274) --- diff --git a/Cargo.lock b/Cargo.lock index 192d75e6..fd3edc80 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -316,7 +316,7 @@ dependencies = [ [[package]] name = "prolog_parser" -version = "0.8.40" +version = "0.8.41" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "lexical 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -453,7 +453,7 @@ dependencies = [ "nix 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "num-rug-adapter 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "ordered-float 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "prolog_parser 0.8.40 (registry+https://github.com/rust-lang/crates.io-index)", + "prolog_parser 0.8.41 (registry+https://github.com/rust-lang/crates.io-index)", "ref_thread_local 0.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "rug 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustyline 5.0.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -614,7 +614,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum num-traits 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "443c53b3c3531dfcbfa499d8893944db78474ad7a1d87fa2d94d1a2231693ac6" "checksum ordered-float 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7eb5259643245d3f292c7a146b2df53bba24d7eab159410e648eb73dc164669d" "checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" -"checksum prolog_parser 0.8.40 (registry+https://github.com/rust-lang/crates.io-index)" = "013131c03328aef02b069e6b325b01fb47597034af169b8b8a1bb8f2cfab0868" +"checksum prolog_parser 0.8.41 (registry+https://github.com/rust-lang/crates.io-index)" = "92be83a8004ae2c476b4257722e86f7df25fba80027e3c9e2e0d57ff2edc0023" "checksum quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" "checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" "checksum rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" diff --git a/Cargo.toml b/Cargo.toml index c6660e0f..f41007ec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ libc = "0.2.62" nix = "0.15.0" num-rug-adapter = { optional = true, version = "0.1.1" } ordered-float = "0.5.0" -prolog_parser = { version = "0.8.40", default-features = false } +prolog_parser = { version = "0.8.41", default-features = false } ref_thread_local = "0.0.0" rug = { version = "1.4.0", optional = true } rustyline = "5.0.3" diff --git a/src/prolog/lib/dcgs.pl b/src/prolog/lib/dcgs.pl index 20997551..bd35575d 100644 --- a/src/prolog/lib/dcgs.pl +++ b/src/prolog/lib/dcgs.pl @@ -1,6 +1,7 @@ -% :- op(1105, xfy, ('|')). - -:- module(dcgs, [op(1200, xfx, -->), phrase/2, phrase/3]). +:- module(dcgs, [op(1200, xfx, -->), + op(1105, xfy, '|'), + phrase/2, + phrase/3]). :- use_module(library(lists), [append/3]). @@ -31,8 +32,8 @@ phrase_((A -> B ; C), S0, S) :- ). phrase_((A ; B), S0, S) :- ( phrase(A, S0, S) ; phrase(B, S0, S) ). -%% phrase_((A | B), S0, S) :- -%% ( phrase(A, S0, S) ; phrase(B, S0, S) ). +phrase_((A | B), S0, S) :- + ( phrase(A, S0, S) ; phrase(B, S0, S) ). phrase_({G}, S0, S) :- ( call(G), S0 = S ). phrase_(call(G), S0, S) :- @@ -95,7 +96,7 @@ dcg_constr([]). % 7.14.1 dcg_constr([_|_]). % 7.14.2 - terminal sequence dcg_constr(( _, _ )). % 7.14.3 - concatenation dcg_constr(( _ ; _ )). % 7.14.4 - alternative -%% dcg_constr(( _'|'_ )). % 7.14.6 - alternative +dcg_constr(( _'|'_ )). % 7.14.6 - alternative dcg_constr({_}). % 7.14.7 dcg_constr(call(_)). % 7.14.8 dcg_constr(phrase(_)). % 7.14.9 @@ -119,9 +120,9 @@ dcg_cbody(( GRCond ; GRElse ), S0, S, ( Cond ; Else )) :- subsumes_term(( _GRIf -> _GRThen ), GRCond), dcg_cbody(GRCond, S0, S, Cond), dcg_body(GRElse, S0, S, Else). -%% dcg_cbody(( GREither '|' GROr ), S0, S, ( Either ; Or )) :- -%% dcg_body(GREither, S0, S, Either), -%% dcg_body(GROr, S0, S, Or). +dcg_cbody(( GREither '|' GROr ), S0, S, ( Either ; Or )) :- + dcg_body(GREither, S0, S, Either), + dcg_body(GROr, S0, S, Or). dcg_cbody({Goal}, S0, S, ( Goal, S0 = S )). dcg_cbody(call(Cont), S0, S, call(Cont, S0, S)). dcg_cbody(phrase(Body), S0, S, phrase(Body, S0, S)). diff --git a/src/prolog/machine/term_expansion.rs b/src/prolog/machine/term_expansion.rs index c1425955..da5dcd90 100644 --- a/src/prolog/machine/term_expansion.rs +++ b/src/prolog/machine/term_expansion.rs @@ -12,31 +12,6 @@ use std::io::Read; use std::iter::Rev; use std::vec::IntoIter; -fn unfold_by_str_once(term: &mut Term, s: &str) -> Option<(Term, Term)> { - if let &mut Term::Clause(_, ref name, ref mut subterms, _) = term { - if name.as_str() == s && subterms.len() == 2 { - let snd = *subterms.pop().unwrap(); - let fst = *subterms.pop().unwrap(); - - return Some((fst, snd)); - } - } - - None -} - -pub fn unfold_by_str(mut term: Term, s: &str) -> Vec { - let mut terms = vec![]; - - while let Some((fst, snd)) = unfold_by_str_once(&mut term, s) { - terms.push(fst); - term = snd; - } - - terms.push(term); - terms -} - pub fn fold_by_str(terms: I, mut term: Term, sym: ClauseName) -> Term where I: DoubleEndedIterator,