check for and load .scryerrc from the user's home directory

This commit is contained in:
Mark Thom
2019-09-04 23:30:48 -06:00
parent a757b92c9d
commit 4b22f80a77
3 changed files with 28 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
[package]
name = "scryer-prolog"
version = "0.8.87"
version = "0.8.88"
authors = ["Mark Thom <markjordanthom@gmail.com>"]
repository = "https://github.com/mthom/scryer-prolog"
description = "A modern Prolog implementation written mostly in Rust."
@@ -11,6 +11,7 @@ default = ["readline_rs_compat"]
[dependencies]
cfg-if = "0.1.7"
dirs = "2.0.2"
downcast = "0.10.0"
indexmap = "1.0.2"
ordered-float = "0.5.0"

View File

@@ -39,6 +39,7 @@ use prolog::read::PrologStream;
use std::collections::{HashMap, VecDeque};
use std::io::{Read, Write, stdout};
use std::fs::File;
use std::mem;
use std::ops::Index;
use std::rc::Rc;
@@ -153,7 +154,8 @@ impl SubModuleUser for IndexStore {
static BUILTINS: &str = include_str!("../lib/builtins.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 {
fn compile_special_forms(&mut self) {
@@ -179,6 +181,24 @@ impl Machine {
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)]
pub fn reset(&mut self) {
self.prolog_stream = readline::input_stream();
@@ -209,7 +229,10 @@ impl Machine {
wam.compile_special_forms();
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
}

View File

@@ -1,3 +1,4 @@
extern crate dirs;
extern crate ordered_float;
extern crate prolog_parser;
extern crate rug;