check for and load .scryerrc from the user's home directory
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "scryer-prolog"
|
name = "scryer-prolog"
|
||||||
version = "0.8.87"
|
version = "0.8.88"
|
||||||
authors = ["Mark Thom <markjordanthom@gmail.com>"]
|
authors = ["Mark Thom <markjordanthom@gmail.com>"]
|
||||||
repository = "https://github.com/mthom/scryer-prolog"
|
repository = "https://github.com/mthom/scryer-prolog"
|
||||||
description = "A modern Prolog implementation written mostly in Rust."
|
description = "A modern Prolog implementation written mostly in Rust."
|
||||||
@@ -11,6 +11,7 @@ default = ["readline_rs_compat"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cfg-if = "0.1.7"
|
cfg-if = "0.1.7"
|
||||||
|
dirs = "2.0.2"
|
||||||
downcast = "0.10.0"
|
downcast = "0.10.0"
|
||||||
indexmap = "1.0.2"
|
indexmap = "1.0.2"
|
||||||
ordered-float = "0.5.0"
|
ordered-float = "0.5.0"
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ use prolog::read::PrologStream;
|
|||||||
|
|
||||||
use std::collections::{HashMap, VecDeque};
|
use std::collections::{HashMap, VecDeque};
|
||||||
use std::io::{Read, Write, stdout};
|
use std::io::{Read, Write, stdout};
|
||||||
|
use std::fs::File;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ops::Index;
|
use std::ops::Index;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
@@ -153,7 +154,8 @@ impl SubModuleUser for IndexStore {
|
|||||||
|
|
||||||
static BUILTINS: &str = include_str!("../lib/builtins.pl");
|
static BUILTINS: &str = include_str!("../lib/builtins.pl");
|
||||||
static TOPLEVEL: &str = include_str!("../toplevel.pl");
|
static TOPLEVEL: &str = include_str!("../toplevel.pl");
|
||||||
static ERROR: &str = include_str!("../lib/error.pl");
|
static BETWEEN: &str = include_str!("../lib/between.pl");
|
||||||
|
static NON_ISO: &str = include_str!("../lib/non_iso.pl");
|
||||||
|
|
||||||
impl Machine {
|
impl Machine {
|
||||||
fn compile_special_forms(&mut self) {
|
fn compile_special_forms(&mut self) {
|
||||||
@@ -179,6 +181,24 @@ impl Machine {
|
|||||||
compile_user_module(self, parsing_stream(TOPLEVEL.as_bytes()));
|
compile_user_module(self, parsing_stream(TOPLEVEL.as_bytes()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn compile_scryerrc(&mut self) {
|
||||||
|
let mut path = match dirs::home_dir() {
|
||||||
|
Some(path) => path,
|
||||||
|
None => return
|
||||||
|
};
|
||||||
|
|
||||||
|
path.push(".scryerrc");
|
||||||
|
|
||||||
|
if path.is_file() {
|
||||||
|
let file_src = match File::open(&path) {
|
||||||
|
Ok(file_handle) => parsing_stream(file_handle),
|
||||||
|
Err(_) => return
|
||||||
|
};
|
||||||
|
|
||||||
|
compile_user_module(self, file_src);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub fn reset(&mut self) {
|
pub fn reset(&mut self) {
|
||||||
self.prolog_stream = readline::input_stream();
|
self.prolog_stream = readline::input_stream();
|
||||||
@@ -209,7 +229,10 @@ impl Machine {
|
|||||||
wam.compile_special_forms();
|
wam.compile_special_forms();
|
||||||
wam.compile_top_level();
|
wam.compile_top_level();
|
||||||
|
|
||||||
compile_user_module(&mut wam, parsing_stream(ERROR.as_bytes()));
|
compile_user_module(&mut wam, parsing_stream(BETWEEN.as_bytes()));
|
||||||
|
compile_user_module(&mut wam, parsing_stream(NON_ISO.as_bytes()));
|
||||||
|
|
||||||
|
wam.compile_scryerrc();
|
||||||
|
|
||||||
wam
|
wam
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
extern crate dirs;
|
||||||
extern crate ordered_float;
|
extern crate ordered_float;
|
||||||
extern crate prolog_parser;
|
extern crate prolog_parser;
|
||||||
extern crate rug;
|
extern crate rug;
|
||||||
|
|||||||
Reference in New Issue
Block a user