From e33ec4a02c4e3742ecf074474c87de0a9a55e139 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 13 Aug 2023 01:06:55 -0400 Subject: [PATCH] Add support for reading begin/end bounds in the new standard-properties format. --- Makefile | 2 +- src/compare/util.rs | 33 +++++++++++++++++++++++++-------- src/parser/sexp.rs | 7 +++++++ 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index bb1cbdb2..235a305f 100644 --- a/Makefile +++ b/Makefile @@ -40,7 +40,7 @@ test: .PHONY: dockertest dockertest: > $(MAKE) -C docker/organic_test -> docker run --rm -i -t -v "$$(readlink -f ./):/.source:ro" -w / organic-test sh -c "cp -r /.source /source && cd /source && cargo test" +> docker run --rm -i -t -v "$$(readlink -f ./):/.source:ro" -w / organic-test sh -c "cp -r /.source /source && cd /source && cargo test --lib --test test_loader" .PHONY: integrationtest integrationtest: diff --git a/src/compare/util.rs b/src/compare/util.rs index 2386943e..a3441d44 100644 --- a/src/compare/util.rs +++ b/src/compare/util.rs @@ -48,14 +48,31 @@ pub fn assert_bounds<'s, S: Source<'s>>( .nth(1) .ok_or("Should have an attributes child.")?; let attributes_map = attributes_child.as_map()?; - let begin = attributes_map - .get(":begin") - .ok_or("Missing :begin attribute.")? - .as_atom()?; - let end = attributes_map - .get(":end") - .ok_or("Missing :end attribute.")? - .as_atom()?; + let standard_properties = attributes_map.get(":standard-properties"); + let (begin, end) = if standard_properties.is_some() { + let std_props = standard_properties + .expect("if statement proves its Some") + .as_vector()?; + let begin = std_props + .get(0) + .ok_or("Missing first element in standard properties")? + .as_atom()?; + let end = std_props + .get(1) + .ok_or("Missing first element in standard properties")? + .as_atom()?; + (begin, end) + } else { + let begin = attributes_map + .get(":begin") + .ok_or("Missing :begin attribute.")? + .as_atom()?; + let end = attributes_map + .get(":end") + .ok_or("Missing :end attribute.")? + .as_atom()?; + (begin, end) + }; let (rust_begin, rust_end) = get_offsets(source, rust); if (rust_begin + 1).to_string() != begin || (rust_end + 1).to_string() != end { Err(format!("Rust bounds ({rust_begin}, {rust_end}) do not match emacs bounds ({emacs_begin}, {emacs_end})", rust_begin = rust_begin + 1, rust_end = rust_end + 1, emacs_begin=begin, emacs_end=end))?; diff --git a/src/parser/sexp.rs b/src/parser/sexp.rs index cb44d5f7..c0188797 100644 --- a/src/parser/sexp.rs +++ b/src/parser/sexp.rs @@ -74,6 +74,13 @@ enum ParseState { } impl<'s> Token<'s> { + pub fn as_vector<'p>(&'p self) -> Result<&'p Vec>, Box> { + Ok(match self { + Token::Vector(children) => Ok(children), + _ => Err(format!("wrong token type {:?}", self)), + }?) + } + pub fn as_list<'p>(&'p self) -> Result<&'p Vec>, Box> { Ok(match self { Token::List(children) => Ok(children),