]> Repositorios git - scryer-prolog.git/commitdiff
allow set_prolog_flag in declarations
authorMark Thom <[email protected]>
Sat, 29 Feb 2020 04:42:22 +0000 (21:42 -0700)
committerMark Thom <[email protected]>
Sat, 29 Feb 2020 04:42:22 +0000 (21:42 -0700)
Cargo.lock
Cargo.toml
src/prolog/forms.rs
src/prolog/machine/compile.rs
src/prolog/machine/toplevel.rs

index fd3edc80a3528a0f9a6032a517df0c751deb2315..394f4511a956c46cffd9de706bbe87c08e4ea052 100644 (file)
@@ -316,7 +316,7 @@ dependencies = [
 
 [[package]]
 name = "prolog_parser"
-version = "0.8.41"
+version = "0.8.42"
 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.41 (registry+https://github.com/rust-lang/crates.io-index)",
+ "prolog_parser 0.8.42 (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.41 (registry+https://github.com/rust-lang/crates.io-index)" = "92be83a8004ae2c476b4257722e86f7df25fba80027e3c9e2e0d57ff2edc0023"
+"checksum prolog_parser 0.8.42 (registry+https://github.com/rust-lang/crates.io-index)" = "6e1dc25ecbd80bc9a1636b3c863ae95355b340cf2959f94fe8faeff13c4ad078"
 "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 f41007ec9d4c460ffedf1072506a02cd85a41ee8..85b7c9dc866aaa856df7b55f933cc14fb2613d22 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.41", default-features = false }
+prolog_parser = { version = "0.8.42", default-features = false }
 ref_thread_local = "0.0.0"
 rug = { version = "1.4.0", optional = true }
 rustyline = "5.0.3"
index 9897d9ce5545f9d8a20a0343bfeb14a85248987d..9c402bd2a8683042cbb37126a17e88dd3d6f2518 100644 (file)
@@ -394,6 +394,7 @@ pub enum Declaration {
     MultiFile(MultiFileIndicator),
     NonCountedBacktracking(ClauseName, usize), // name, arity
     Op(OpDecl),
+    SetPrologFlag(DoubleQuotes),
     UseModule(ModuleSource),
     UseQualifiedModule(ModuleSource, Vec<ModuleExport>),
 }
index ffa6d5171b3c5837511a9222d6a9e633cf695ea2..f13cb9bb65e102345cb1b2dc76178bae7033afd6 100644 (file)
@@ -968,6 +968,10 @@ impl ListingCompiler {
             Declaration::Op(op_decl) => {
                 self.submit_op(wam, indices, &op_decl)
             }
+            Declaration::SetPrologFlag(dbl_quotes) => {
+                wam.machine_st.flags.double_quotes = dbl_quotes;
+                Ok(())
+            }
             Declaration::UseModule(ModuleSource::Library(name)) => {
                 let name = if !wam.indices.modules.contains_key(&name) {
                     load_library(wam, name, true)?
index 3078beca2d6864b2b5213f0fb2733a67d9c43ead..9b685b762947bcf6ec72f8429b1aa7cf5ee5dece 100644 (file)
@@ -339,6 +339,32 @@ fn setup_use_module_decl(mut terms: Vec<Box<Term>>) -> Result<ModuleSource, Pars
     }
 }
 
+fn setup_double_quotes(mut terms: Vec<Box<Term>>) -> Result<DoubleQuotes, ParserError> {
+    let dbl_quotes = *terms.pop().unwrap();
+    
+    match terms[0].as_ref() {
+        Term::Constant(_, Constant::Atom(ref name, _))
+            if name.as_str() == "double_quotes" => {
+                match dbl_quotes {
+                    Term::Constant(_, Constant::Atom(name, _)) => {
+                        match name.as_str() {
+                            "atom"  => Ok(DoubleQuotes::Atom),
+                            "chars" => Ok(DoubleQuotes::Chars),
+                            "codes" => Ok(DoubleQuotes::Codes),
+                            _ => Err(ParserError::InvalidDoubleQuotesDecl),
+                        }
+                    }
+                    _ => {
+                        Err(ParserError::InvalidDoubleQuotesDecl)
+                    }
+                }
+            },
+        _ => {
+            Err(ParserError::InvalidDoubleQuotesDecl)
+        }
+    }
+}
+
 type UseModuleExport = (ModuleSource, Vec<ModuleExport>);
 
 fn setup_qualified_import(
@@ -620,6 +646,9 @@ fn setup_declaration<'a, 'b, 'c, R: Read>(
                    let (name, arity) = setup_predicate_indicator(&mut *terms.pop().unwrap())?;
                    Ok(Declaration::NonCountedBacktracking(name, arity))
                }
+                ("set_prolog_flag", 2) => {
+                    Ok(Declaration::SetPrologFlag(setup_double_quotes(terms)?))
+                }
                 ("multifile", 1) => {
                     let mut term = *terms.pop().unwrap();