allow set_prolog_flag in declarations

This commit is contained in:
Mark Thom
2020-02-28 21:42:22 -07:00
parent 934f73f696
commit aa5f186a96
5 changed files with 38 additions and 4 deletions

6
Cargo.lock generated
View File

@@ -316,7 +316,7 @@ dependencies = [
[[package]] [[package]]
name = "prolog_parser" name = "prolog_parser"
version = "0.8.41" version = "0.8.42"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"lexical 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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)", "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)", "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)", "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)", "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 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 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 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 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.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" "checksum rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"

View File

@@ -24,7 +24,7 @@ libc = "0.2.62"
nix = "0.15.0" nix = "0.15.0"
num-rug-adapter = { optional = true, version = "0.1.1" } num-rug-adapter = { optional = true, version = "0.1.1" }
ordered-float = "0.5.0" 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" ref_thread_local = "0.0.0"
rug = { version = "1.4.0", optional = true } rug = { version = "1.4.0", optional = true }
rustyline = "5.0.3" rustyline = "5.0.3"

View File

@@ -394,6 +394,7 @@ pub enum Declaration {
MultiFile(MultiFileIndicator), MultiFile(MultiFileIndicator),
NonCountedBacktracking(ClauseName, usize), // name, arity NonCountedBacktracking(ClauseName, usize), // name, arity
Op(OpDecl), Op(OpDecl),
SetPrologFlag(DoubleQuotes),
UseModule(ModuleSource), UseModule(ModuleSource),
UseQualifiedModule(ModuleSource, Vec<ModuleExport>), UseQualifiedModule(ModuleSource, Vec<ModuleExport>),
} }

View File

@@ -968,6 +968,10 @@ impl ListingCompiler {
Declaration::Op(op_decl) => { Declaration::Op(op_decl) => {
self.submit_op(wam, indices, &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)) => { Declaration::UseModule(ModuleSource::Library(name)) => {
let name = if !wam.indices.modules.contains_key(&name) { let name = if !wam.indices.modules.contains_key(&name) {
load_library(wam, name, true)? load_library(wam, name, true)?

View 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>); type UseModuleExport = (ModuleSource, Vec<ModuleExport>);
fn setup_qualified_import( 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())?; let (name, arity) = setup_predicate_indicator(&mut *terms.pop().unwrap())?;
Ok(Declaration::NonCountedBacktracking(name, arity)) Ok(Declaration::NonCountedBacktracking(name, arity))
} }
("set_prolog_flag", 2) => {
Ok(Declaration::SetPrologFlag(setup_double_quotes(terms)?))
}
("multifile", 1) => { ("multifile", 1) => {
let mut term = *terms.pop().unwrap(); let mut term = *terms.pop().unwrap();