diff --git a/rustemo/src/glr/gss.rs b/rustemo/src/glr/gss.rs index 13d9279f..30a3a147 100644 --- a/rustemo/src/glr/gss.rs +++ b/rustemo/src/glr/gss.rs @@ -9,11 +9,7 @@ use std::{ use petgraph::{graph::Edges, prelude::*}; use crate::{ - context::Context, - input::Input, - lexer::Token, - location::Location, - lr::builder::LRBuilder, + context::Context, input::Input, lexer::Token, location::Location, lr::builder::LRBuilder, parser::State, }; @@ -653,12 +649,11 @@ where S: State, P: Copy, { - match &*self.root { SPPFTree::Term { token, .. } => { context.set_location(Context::::location(&*self.root)); builder.shift_action(context, token.clone()) - }, + } SPPFTree::NonTerm { prod, .. } => { let children = self.children(); children.iter().for_each(|c| { diff --git a/rustemo/src/glr/parser.rs b/rustemo/src/glr/parser.rs index 3d194274..359366a1 100644 --- a/rustemo/src/glr/parser.rs +++ b/rustemo/src/glr/parser.rs @@ -3,7 +3,7 @@ //! The implementation is based on this paper: //! Elizabeth Scott and Adrian Johnstone. 2006. Right nulled GLR parsers. ACM //! Trans. Program. Lang. Syst. 28, 4 (July 2006), 577–618. -//! https://doi.org/10.1145/1146809.1146810 +//! use crate::{ context::Context, @@ -618,7 +618,8 @@ where ) .start, end: as Context<'_, I, S, TK>>::range( - &path.parents[path.parents.len() - 1].possibilities.borrow()[0], + &path.parents[path.parents.len() - 1].possibilities.borrow() + [0], ) .end, } @@ -631,14 +632,16 @@ where } } else { Location { - start: as Context<'_, I, S, TK>>::location( - &path.parents[0].possibilities.borrow()[0], - ) - .start, + start: + as Context<'_, I, S, TK>>::location( + &path.parents[0].possibilities.borrow()[0], + ) + .start, end: Some( as Context<'_, I, S, TK>>::location( - &path.parents[path.parents.len() - 1].possibilities.borrow() - [0], + &path.parents[path.parents.len() - 1] + .possibilities + .borrow()[0], ) .end .unwrap(), diff --git a/rustemo/src/location.rs b/rustemo/src/location.rs index 63c801aa..3d1cecf5 100644 --- a/rustemo/src/location.rs +++ b/rustemo/src/location.rs @@ -107,7 +107,7 @@ impl Location { pub fn to(&self, loc_to: Self) -> Self { Self { start: self.start, - end: loc_to.end.or(Some(loc_to.start)) + end: loc_to.end.or(Some(loc_to.start)), } } } diff --git a/rustemo/src/utils.rs b/rustemo/src/utils.rs index 5f30bee7..f38ba0a0 100644 --- a/rustemo/src/utils.rs +++ b/rustemo/src/utils.rs @@ -1,5 +1,5 @@ /// Simple deduplication. -/// See: https://stackoverflow.com/a/57889826/2024430 +/// See: pub trait Dedup { fn clear_duplicates(&mut self); } diff --git a/tests/src/builder/loc_info/mod.rs b/tests/src/builder/loc_info/mod.rs index 61d92461..a8fcf2d5 100644 --- a/tests/src/builder/loc_info/mod.rs +++ b/tests/src/builder/loc_info/mod.rs @@ -1,6 +1,6 @@ -use serial_test::serial; use rustemo::{rustemo_mod, Parser}; use rustemo_compiler::{local_file, output_cmp}; +use serial_test::serial; use self::json::JsonParser; @@ -11,7 +11,9 @@ rustemo_mod!(json_actions, "/src/builder/loc_info"); #[serial(loc_info)] fn loc_info() { let mut parser = JsonParser::new(); - let result = parser.parse_file(local_file!(file!(), "loc_info.json")).unwrap(); + let result = parser + .parse_file(local_file!(file!(), "loc_info.json")) + .unwrap(); output_cmp!( "src/builder/loc_info/loc_info.ast", format!("{:#?}", result) diff --git a/tests/src/glr/build/loc_info/mod.rs b/tests/src/glr/build/loc_info/mod.rs index 32de4353..be939cf3 100644 --- a/tests/src/glr/build/loc_info/mod.rs +++ b/tests/src/glr/build/loc_info/mod.rs @@ -1,6 +1,6 @@ -use serial_test::serial; use rustemo::{rustemo_mod, Parser}; use rustemo_compiler::{local_file, output_cmp}; +use serial_test::serial; use self::json::JsonParser; @@ -13,7 +13,10 @@ fn glr_loc_info() { let mut parser = JsonParser::new(); let forest = parser // Using the same input file from LR test. - .parse_file(local_file!(file!(), "../../../builder/loc_info/loc_info.json")) + .parse_file(local_file!( + file!(), + "../../../builder/loc_info/loc_info.json" + )) .unwrap(); output_cmp!( diff --git a/tests/src/glr/lexical_ambiguity/most_specific_off/mod.rs b/tests/src/glr/lexical_ambiguity/most_specific_off/mod.rs index 850a3573..5db03bcb 100644 --- a/tests/src/glr/lexical_ambiguity/most_specific_off/mod.rs +++ b/tests/src/glr/lexical_ambiguity/most_specific_off/mod.rs @@ -1,7 +1,10 @@ use rustemo::{rustemo_mod, Parser}; use rustemo_compiler::output_cmp; -rustemo_mod!(most_specific, "/src/glr/lexical_ambiguity/most_specific_off"); +rustemo_mod!( + most_specific, + "/src/glr/lexical_ambiguity/most_specific_off" +); rustemo_mod!( most_specific_actions, "/src/glr/lexical_ambiguity/most_specific_off"