Skip to content

Commit

Permalink
chore: reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
igordejanovic committed Nov 16, 2024
1 parent ee616d5 commit d595578
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 22 deletions.
9 changes: 2 additions & 7 deletions rustemo/src/glr/gss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -653,12 +649,11 @@ where
S: State,
P: Copy,
{

match &*self.root {
SPPFTree::Term { token, .. } => {
context.set_location(Context::<I, S, TK>::location(&*self.root));
builder.shift_action(context, token.clone())
},
}
SPPFTree::NonTerm { prod, .. } => {
let children = self.children();
children.iter().for_each(|c| {
Expand Down
19 changes: 11 additions & 8 deletions rustemo/src/glr/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
//! <https://doi.org/10.1145/1146809.1146810>
use crate::{
context::Context,
Expand Down Expand Up @@ -618,7 +618,8 @@ where
)
.start,
end: <SPPFTree<'_, I, P, TK> 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,
}
Expand All @@ -631,14 +632,16 @@ where
}
} else {
Location {
start: <SPPFTree<'_, I, P, TK> as Context<'_, I, S, TK>>::location(
&path.parents[0].possibilities.borrow()[0],
)
.start,
start:
<SPPFTree<'_, I, P, TK> as Context<'_, I, S, TK>>::location(
&path.parents[0].possibilities.borrow()[0],
)
.start,
end: Some(
<SPPFTree<'_, I, P, TK> 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(),
Expand Down
2 changes: 1 addition & 1 deletion rustemo/src/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion rustemo/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// Simple deduplication.
/// See: https://stackoverflow.com/a/57889826/2024430
/// See: <https://stackoverflow.com/a/57889826/2024430>
pub trait Dedup<T: PartialEq + Clone> {
fn clear_duplicates(&mut self);
}
Expand Down
6 changes: 4 additions & 2 deletions tests/src/builder/loc_info/mod.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions tests/src/glr/build/loc_info/mod.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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!(
Expand Down
5 changes: 4 additions & 1 deletion tests/src/glr/lexical_ambiguity/most_specific_off/mod.rs
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit d595578

Please sign in to comment.