Compare commits
2 commits
00862f3aca
...
54cac55fbc
| Author | SHA1 | Date | |
|---|---|---|---|
| 54cac55fbc | |||
| 95b61ebdc5 |
4 changed files with 31 additions and 28 deletions
|
|
@ -9,7 +9,7 @@ pub fn index_notebook_once(mut output: impl FeedbackChannel, context: &NotebookC
|
|||
let notebook = indexer::index_and_save(context)
|
||||
.map_err(|err| CliErr {
|
||||
exit_code: 2,
|
||||
message: format!("Failed to index notebook.\n {:?}", err)
|
||||
message: format!("Failed to index notebook:\n {:?}", err)
|
||||
})?;
|
||||
|
||||
output.push_log(
|
||||
|
|
|
|||
|
|
@ -72,10 +72,10 @@ enum EntryValue {
|
|||
// Reference of an EntryValue need to store: in which repository I need to get the data, and
|
||||
// where I need to look
|
||||
Reference(Reference),
|
||||
/// a Float quantity, with a float number associated to a measurement class
|
||||
FQuantity(f64, Reference),
|
||||
/// a Float quantity, with a integer associated to a measurement class
|
||||
IQuantity(i64, Reference),
|
||||
/// a Float quantity, with a float number associated to a measurement class (or no units)
|
||||
FQuantity(f64, Option<Reference>),
|
||||
/// a Float quantity, with a integer associated to a measurement class (or no units)
|
||||
IQuantity(i64, Option<Reference>),
|
||||
/// coordinate on a globe, by default the earth, but we can define it on other globe
|
||||
GlobeCoordinate { lat: f64, lng: f64 },
|
||||
Time(DateTime<Utc>),
|
||||
|
|
@ -218,8 +218,10 @@ impl fmt::Display for EntryValue {
|
|||
use EntryValue as EV;
|
||||
let res = match self {
|
||||
EV::String(str) => str.to_string(),
|
||||
EV::FQuantity(val, class) => format!("Quantity({}, {})", val, class),
|
||||
EV::IQuantity(val, class) => format!("Quantity({}, {})", val, class),
|
||||
EV::FQuantity(val, Some(unit_ref)) => format!("Quantity({}, {})", val, unit_ref),
|
||||
EV::IQuantity(val, Some(unit_ref)) => format!("Quantity({}, {})", val, unit_ref),
|
||||
EV::FQuantity(val, None) => format!("Quantity({})", val),
|
||||
EV::IQuantity(val, None) => format!("Quantity({})", val),
|
||||
EV::GlobeCoordinate { lat, lng } => format!("Geo({lat}, {lng})"),
|
||||
EV::Time(val) => format!("Date({})", val),
|
||||
val => format!("{:?}", val),
|
||||
|
|
|
|||
|
|
@ -102,20 +102,20 @@ pub fn get_pure_value(parsed_value: &PEntryValue) -> Result<EntryValue> {
|
|||
"Quantity" => {
|
||||
let value_arg = func.arguments.get(0).map(|x| &x.p)
|
||||
.map(get_argument_value)
|
||||
.ok_or(anyhow!("Quantity: Cannot get value input argument"))?;
|
||||
let measurement_arg = func.arguments.get(1).map(|x| &x.p)
|
||||
.map(get_argument_value)
|
||||
.ok_or(anyhow!("Quantity: Cannot get measure class input argument"))?;
|
||||
.ok_or(anyhow!("Quantity: cannot get value input argument"))?;
|
||||
let unit_arg = func.arguments.get(1).map(|x| &x.p)
|
||||
.map(get_argument_value);
|
||||
|
||||
let measurement_ref = match measurement_arg {
|
||||
PEntryValue::Reference(parsed_ref) => Reference::Unresolved(parsed_ref.clone()),
|
||||
_ => {
|
||||
return Err(anyhow!("Quantity: expected second argument to be a reference."))
|
||||
}
|
||||
let unit_ref = match unit_arg {
|
||||
Some(PEntryValue::Reference(parsed_ref)) => Some(Reference::Unresolved(parsed_ref.clone())),
|
||||
Some(_) => {
|
||||
return Err(anyhow!("Quantity: expected a reference as unit argument"));
|
||||
},
|
||||
None => None
|
||||
};
|
||||
match value_arg {
|
||||
PEntryValue::Integer(val) => EntryValue::IQuantity(val.clone(), measurement_ref),
|
||||
PEntryValue::Float(val) => EntryValue::FQuantity(val.clone(), measurement_ref),
|
||||
PEntryValue::Integer(val) => EntryValue::IQuantity(val.clone(), unit_ref),
|
||||
PEntryValue::Float(val) => EntryValue::FQuantity(val.clone(), unit_ref),
|
||||
_ => {
|
||||
return Err(anyhow!("Quantity: expected first argument to be integer or float"))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@ pub enum IndexingErr {
|
|||
CannotOpen,
|
||||
IoErr(io::Error),
|
||||
SaveErr(SaveErr),
|
||||
PreprocessingErr(ParseError),
|
||||
ParseErr,
|
||||
PreprocessingErr(PathBuf, ParseError),
|
||||
ParseErr(PathBuf, ParseError),
|
||||
LinkErr,
|
||||
CannotProcessCodeToAddId,
|
||||
CannotWriteFileToAddId(io::Error),
|
||||
|
|
@ -67,11 +67,11 @@ fn index_file(base_dir: &Path, file_path: &Path, file_id: Uuid) -> Result<Indexi
|
|||
eprintln!("Indexing file {:?}", file_path);
|
||||
// keep an existing id or get a new one
|
||||
// or use the git id?
|
||||
let mut contents = fs::read_to_string(file_path)
|
||||
let contents = fs::read_to_string(file_path)
|
||||
.expect("Should be able to read the file, there is something wrong with it");
|
||||
|
||||
let preprocessed_val = preprocess_code(&contents)
|
||||
.map_err(|err| IndexingErr::PreprocessingErr(err))?;
|
||||
.map_err(|err| IndexingErr::PreprocessingErr(file_path.into(), err))?;
|
||||
let source_file = SourceFile {
|
||||
id: file_id,
|
||||
path: file_path
|
||||
|
|
@ -82,8 +82,8 @@ fn index_file(base_dir: &Path, file_path: &Path, file_id: Uuid) -> Result<Indexi
|
|||
};
|
||||
|
||||
let parsed_file = parse_markdown(&preprocessed_val.code_output, 0)
|
||||
.map_err(|_e|
|
||||
IndexingErr::ParseErr
|
||||
.map_err(|e|
|
||||
IndexingErr::ParseErr(file_path.into(), e)
|
||||
)?;
|
||||
|
||||
// TODO: call a function to flatten all the entries (handle embedded entries)
|
||||
|
|
@ -368,15 +368,16 @@ impl Notebook {
|
|||
manifest: NotebookManifest,
|
||||
markdown_code: &str
|
||||
)-> Result<Notebook, IndexingErr> {
|
||||
let markdown_val = parse_markdown(markdown_code, 0).map_err(
|
||||
|e| IndexingErr::ParseErr(e)
|
||||
)?;
|
||||
let virtual_file = PathBuf::from("./index.md");
|
||||
let sf = SourceFile {
|
||||
id: Uuid::new_v4(),
|
||||
path: PathBuf::from("./all_in_one_virtual.md"),
|
||||
path: virtual_file.clone(),
|
||||
expansions: vec![]
|
||||
};
|
||||
|
||||
let markdown_val = parse_markdown(markdown_code, 0).map_err(
|
||||
|e| IndexingErr::ParseErr(virtual_file, e)
|
||||
)?;
|
||||
let mut entries_containers: Vec<EntryContainer> = vec![];
|
||||
|
||||
for parsed_entry in markdown_val.tree.p {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue