]> Repositorios git - scryer-prolog.git/commitdiff
update prolog_parser version, allow ('|') operator in DCGs (#274)
authorMark Thom <[email protected]>
Sun, 23 Feb 2020 20:16:14 +0000 (13:16 -0700)
committerMark Thom <[email protected]>
Sun, 23 Feb 2020 20:16:14 +0000 (13:16 -0700)
Cargo.lock
Cargo.toml
src/prolog/lib/dcgs.pl
src/prolog/machine/term_expansion.rs

index 192d75e6f41ffc2497c484c4c18126a0be6540e2..fd3edc80a3528a0f9a6032a517df0c751deb2315 100644 (file)
@@ -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"
index c6660e0f600fd3a38264b9d21f02fc5b00e8de88..f41007ec9d4c460ffedf1072506a02cd85a41ee8 100644 (file)
@@ -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"
index 20997551f5014b478655d3a5f35df6328c3e9186..bd35575dc5aad65c27becc6341e2b555dfa6a72e 100644 (file)
@@ -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)).
index c14259557a5a4787be6a1a71f7594f69c82cf1ee..da5dcd909d1bd7d07818395a78a78adf2eebfa03 100644 (file)
@@ -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<Term> {
-    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<I>(terms: I, mut term: Term, sym: ClauseName) -> Term
 where
     I: DoubleEndedIterator<Item = Term>,