Fixing more errors.

This commit is contained in:
Tom Alexander 2023-09-03 12:52:09 -04:00
parent 0d438a8e0f
commit d262833f9b
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
7 changed files with 70 additions and 68 deletions

View File

@ -39,7 +39,7 @@ tracing-subscriber = { version = "0.3.17", optional = true, features = ["env-fil
walkdir = "2.3.3" walkdir = "2.3.3"
[features] [features]
default = [] default = ["compare"]
compare = [] compare = []
tracing = ["dep:opentelemetry", "dep:opentelemetry-otlp", "dep:opentelemetry-semantic-conventions", "dep:tokio", "dep:tracing", "dep:tracing-opentelemetry", "dep:tracing-subscriber"] tracing = ["dep:opentelemetry", "dep:opentelemetry-otlp", "dep:opentelemetry-semantic-conventions", "dep:tokio", "dep:tracing", "dep:tracing-opentelemetry", "dep:tracing-subscriber"]

View File

@ -5,64 +5,64 @@ use super::util::assert_name;
use super::util::get_property; use super::util::get_property;
use crate::parser::sexp::unquote; use crate::parser::sexp::unquote;
use crate::parser::sexp::Token; use crate::parser::sexp::Token;
use crate::parser::AngleLink; use crate::types::AngleLink;
use crate::parser::Bold; use crate::types::Bold;
use crate::parser::Citation; use crate::types::Citation;
use crate::parser::CitationReference; use crate::types::CitationReference;
use crate::parser::Clock; use crate::types::Clock;
use crate::parser::Code; use crate::types::Code;
use crate::parser::Comment; use crate::types::Comment;
use crate::parser::CommentBlock; use crate::types::CommentBlock;
use crate::parser::DiarySexp; use crate::types::DiarySexp;
use crate::parser::Document; use crate::types::Document;
use crate::parser::DocumentElement; use crate::types::DocumentElement;
use crate::parser::Drawer; use crate::types::Drawer;
use crate::parser::DynamicBlock; use crate::types::DynamicBlock;
use crate::parser::Element; use crate::types::Element;
use crate::parser::Entity; use crate::types::Entity;
use crate::parser::ExampleBlock; use crate::types::ExampleBlock;
use crate::parser::ExportBlock; use crate::types::ExportBlock;
use crate::parser::ExportSnippet; use crate::types::ExportSnippet;
use crate::parser::FixedWidthArea; use crate::types::FixedWidthArea;
use crate::parser::FootnoteDefinition; use crate::types::FootnoteDefinition;
use crate::parser::FootnoteReference; use crate::types::FootnoteReference;
use crate::parser::GreaterBlock; use crate::types::GreaterBlock;
use crate::parser::Heading; use crate::types::Heading;
use crate::parser::HorizontalRule; use crate::types::HorizontalRule;
use crate::parser::InlineBabelCall; use crate::types::InlineBabelCall;
use crate::parser::InlineSourceBlock; use crate::types::InlineSourceBlock;
use crate::parser::Italic; use crate::types::Italic;
use crate::parser::Keyword; use crate::types::Keyword;
use crate::parser::LatexEnvironment; use crate::types::LatexEnvironment;
use crate::parser::LatexFragment; use crate::types::LatexFragment;
use crate::parser::LineBreak; use crate::types::LineBreak;
use crate::parser::Object; use crate::types::Object;
use crate::parser::OrgMacro; use crate::types::OrgMacro;
use crate::parser::Paragraph; use crate::types::Paragraph;
use crate::parser::PlainLink; use crate::types::PlainLink;
use crate::parser::PlainList; use crate::types::PlainList;
use crate::parser::PlainListItem; use crate::types::PlainListItem;
use crate::parser::PlainText; use crate::types::PlainText;
use crate::parser::Planning; use crate::types::Planning;
use crate::parser::PropertyDrawer; use crate::types::PropertyDrawer;
use crate::parser::RadioLink; use crate::types::RadioLink;
use crate::parser::RadioTarget; use crate::types::RadioTarget;
use crate::parser::RegularLink; use crate::types::RegularLink;
use crate::parser::Section; use crate::types::Section;
use crate::parser::Source; use crate::types::Source;
use crate::parser::SrcBlock; use crate::types::SrcBlock;
use crate::parser::StatisticsCookie; use crate::types::StatisticsCookie;
use crate::parser::StrikeThrough; use crate::types::StrikeThrough;
use crate::parser::Subscript; use crate::types::Subscript;
use crate::parser::Superscript; use crate::types::Superscript;
use crate::parser::Table; use crate::types::Table;
use crate::parser::TableCell; use crate::types::TableCell;
use crate::parser::TableRow; use crate::types::TableRow;
use crate::parser::Target; use crate::types::Target;
use crate::parser::Timestamp; use crate::types::Timestamp;
use crate::parser::Underline; use crate::types::Underline;
use crate::parser::Verbatim; use crate::types::Verbatim;
use crate::parser::VerseBlock; use crate::types::VerseBlock;
#[derive(Debug)] #[derive(Debug)]
pub enum DiffEntry<'s> { pub enum DiffEntry<'s> {

View File

@ -1,5 +1,5 @@
use crate::parser::sexp::Token; use crate::parser::sexp::Token;
use crate::parser::Source; use crate::types::Source;
/// Check if the child string slice is a slice of the parent string slice. /// Check if the child string slice is a slice of the parent string slice.
fn is_slice_of(parent: &str, child: &str) -> bool { fn is_slice_of(parent: &str, child: &str) -> bool {

View File

@ -3,7 +3,7 @@
use std::io::Read; use std::io::Read;
use std::path::Path; use std::path::Path;
use ::organic::parser::document; use ::organic::parser::parse;
#[cfg(feature = "compare")] #[cfg(feature = "compare")]
use organic::compare_document; use organic::compare_document;
#[cfg(feature = "compare")] #[cfg(feature = "compare")]
@ -68,7 +68,7 @@ fn run_anonymous_parse<P: AsRef<str>>(org_contents: P) -> Result<(), Box<dyn std
let org_contents = org_contents.as_ref(); let org_contents = org_contents.as_ref();
eprintln!("Using emacs version: {}", get_emacs_version()?.trim()); eprintln!("Using emacs version: {}", get_emacs_version()?.trim());
eprintln!("Using org-mode version: {}", get_org_mode_version()?.trim()); eprintln!("Using org-mode version: {}", get_org_mode_version()?.trim());
let (remaining, rust_parsed) = document(org_contents).map_err(|e| e.to_string())?; let (remaining, rust_parsed) = parse(org_contents).map_err(|e| e.to_string())?;
let org_sexp = emacs_parse_anonymous_org_document(org_contents)?; let org_sexp = emacs_parse_anonymous_org_document(org_contents)?;
let (_remaining, parsed_sexp) = let (_remaining, parsed_sexp) =
sexp_with_padding(org_sexp.as_str()).map_err(|e| e.to_string())?; sexp_with_padding(org_sexp.as_str()).map_err(|e| e.to_string())?;
@ -96,7 +96,7 @@ fn run_anonymous_parse<P: AsRef<str>>(org_contents: P) -> Result<(), Box<dyn std
eprintln!( eprintln!(
"This program was built with compare disabled. Only parsing with organic, not comparing." "This program was built with compare disabled. Only parsing with organic, not comparing."
); );
let (_remaining, rust_parsed) = document(org_contents.as_ref()).map_err(|e| e.to_string())?; let (_remaining, rust_parsed) = parse(org_contents.as_ref()).map_err(|e| e.to_string())?;
println!("{:#?}", rust_parsed); println!("{:#?}", rust_parsed);
Ok(()) Ok(())
} }
@ -109,7 +109,7 @@ fn run_parse_on_file<P: AsRef<Path>>(org_path: P) -> Result<(), Box<dyn std::err
// TODO: This should take into account the original file path when parsing in Organic, not just in emacs. // TODO: This should take into account the original file path when parsing in Organic, not just in emacs.
let org_contents = std::fs::read_to_string(org_path)?; let org_contents = std::fs::read_to_string(org_path)?;
let org_contents = org_contents.as_str(); let org_contents = org_contents.as_str();
let (remaining, rust_parsed) = document(org_contents).map_err(|e| e.to_string())?; let (remaining, rust_parsed) = parse(org_contents).map_err(|e| e.to_string())?;
let org_sexp = emacs_parse_file_org_document(org_path)?; let org_sexp = emacs_parse_file_org_document(org_path)?;
let (_remaining, parsed_sexp) = let (_remaining, parsed_sexp) =
sexp_with_padding(org_sexp.as_str()).map_err(|e| e.to_string())?; sexp_with_padding(org_sexp.as_str()).map_err(|e| e.to_string())?;
@ -141,7 +141,7 @@ fn run_parse_on_file<P: AsRef<Path>>(org_path: P) -> Result<(), Box<dyn std::err
// TODO: This should take into account the original file path when parsing // TODO: This should take into account the original file path when parsing
let org_contents = std::fs::read_to_string(org_path)?; let org_contents = std::fs::read_to_string(org_path)?;
let org_contents = org_contents.as_str(); let org_contents = org_contents.as_str();
let (_remaining, rust_parsed) = document(org_contents).map_err(|e| e.to_string())?; let (_remaining, rust_parsed) = parse(org_contents).map_err(|e| e.to_string())?;
println!("{:#?}", rust_parsed); println!("{:#?}", rust_parsed);
Ok(()) Ok(())
} }

View File

@ -48,18 +48,18 @@ use crate::types::Section;
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
#[allow(dead_code)] #[allow(dead_code)]
pub fn document(input: &str) -> Res<&str, Document> { pub fn parse(input: &str) -> Res<&str, Document> {
let global_settings = GlobalSettings::default(); let global_settings = GlobalSettings::default();
let initial_context = ContextElement::document_context(); let initial_context = ContextElement::document_context();
let initial_context = Context::new(&global_settings, List::new(&initial_context)); let initial_context = Context::new(&global_settings, List::new(&initial_context));
let wrapped_input = OrgSource::new(input); let wrapped_input = OrgSource::new(input);
let _foo = double_pass_document(&initial_context, wrapped_input); let _foo = document(&initial_context, wrapped_input);
todo!() todo!()
} }
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
#[allow(dead_code)] #[allow(dead_code)]
fn double_pass_document<'r, 's>( pub fn document<'r, 's>(
context: RefContext<'_, 'r, 's>, context: RefContext<'_, 'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
) -> Res<OrgSource<'s>, Document<'s>> { ) -> Res<OrgSource<'s>, Document<'s>> {

View File

@ -43,4 +43,5 @@ mod timestamp;
mod token; mod token;
mod util; mod util;
pub use document::document; pub use document::document;
pub use document::parse;
pub use org_source::OrgSource; pub use org_source::OrgSource;

View File

@ -74,6 +74,7 @@ mod tests {
use crate::context::List; use crate::context::List;
use crate::parser::element_parser::element; use crate::parser::element_parser::element;
use crate::parser::org_source::OrgSource; use crate::parser::org_source::OrgSource;
use crate::types::Source;
#[test] #[test]
fn two_paragraphs() { fn two_paragraphs() {