Skip to content

Commit

Permalink
rework: simplify the Parser trait
Browse files Browse the repository at this point in the history
Remove Lexer type param from the trait.
  • Loading branch information
igordejanovic committed Nov 27, 2023
1 parent f008401 commit 92d7afd
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl<
}
}
#[allow(dead_code)]
impl<'i, I, L, B> Parser<'i, I, Context<'i, I>, L, State, TokenKind>
impl<'i, I, L, B> Parser<'i, I, Context<'i, I>, State, TokenKind>
for CalculatorParser<'i, I, L, B>
where
I: InputT + ?Sized + Debug,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ impl<
}
}
#[allow(dead_code)]
impl<'i, I, L, B> Parser<'i, I, Context<'i, I>, L, State, TokenKind>
impl<'i, I, L, B> Parser<'i, I, Context<'i, I>, State, TokenKind>
for CalculatorParser<'i, I, L, B>
where
I: InputT + ?Sized + Debug,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ impl<
}
}
#[allow(dead_code)]
impl<'i, I, L, B> Parser<'i, I, Context<'i, I>, L, State, TokenKind>
impl<'i, I, L, B> Parser<'i, I, Context<'i, I>, State, TokenKind>
for CalculatorParser<'i, I, L, B>
where
I: InputT + ?Sized + Debug,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ impl<
}
}
#[allow(dead_code)]
impl<'i, I, L, B> Parser<'i, I, Context<'i, I>, L, State, TokenKind>
impl<'i, I, L, B> Parser<'i, I, Context<'i, I>, State, TokenKind>
for CalculatorParser<'i, I, L, B>
where
I: InputT + ?Sized + Debug,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ impl<
}
}
#[allow(dead_code)]
impl<'i, I, L, B> Parser<'i, I, Context<'i, I>, L, State, TokenKind>
impl<'i, I, L, B> Parser<'i, I, Context<'i, I>, State, TokenKind>
for CalculatorParser<'i, I, L, B>
where
I: InputT + ?Sized + Debug,
Expand Down
2 changes: 1 addition & 1 deletion rustemo-compiler/src/generator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ impl<'g, 's> ParserGenerator<'g, 's> {

ast.push(parse_quote! {
#[allow(dead_code)]
impl<'i, I, L, B> Parser<'i, I, Context<'i, I>, L, State, TokenKind> for #parser <'i, I, L, B>
impl<'i, I, L, B> Parser<'i, I, Context<'i, I>, State, TokenKind> for #parser <'i, I, L, B>
where
I: InputT + ?Sized + Debug,
L: Lexer<'i, Context<'i, I>, State, TokenKind, Input = I>,
Expand Down
2 changes: 1 addition & 1 deletion rustemo-compiler/src/lang/rustemo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16771,7 +16771,7 @@ impl<
}
}
#[allow(dead_code)]
impl<'i, I, L, B> Parser<'i, I, Context<'i, I>, L, State, TokenKind>
impl<'i, I, L, B> Parser<'i, I, Context<'i, I>, State, TokenKind>
for RustemoParser<'i, I, L, B>
where
I: InputT + ?Sized + Debug,
Expand Down
7 changes: 3 additions & 4 deletions rustemo/src/glr/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -875,8 +875,7 @@ where
}
}

impl<'i, I, L, S, TK, NTK, P, D, B>
Parser<'i, I, GssHead<'i, I, S, TK>, L, S, TK>
impl<'i, I, S, TK, NTK, L, P, D, B> Parser<'i, I, GssHead<'i, I, S, TK>, S, TK>
for GlrParser<'i, S, L, P, TK, NTK, D, I, B>
where
I: Input + ?Sized + Debug,
Expand All @@ -888,7 +887,7 @@ where
{
type Output = Forest<'i, I, P, TK>;

fn parse(&self, input: &'i L::Input) -> Result<Self::Output> {
fn parse(&self, input: &'i I) -> Result<Self::Output> {
let mut context = GssHead::default();
context.set_position(self.start_position);
self.parse_with_context(&mut context, input)
Expand All @@ -897,7 +896,7 @@ where
fn parse_with_context(
&self,
context: &mut GssHead<'i, I, S, TK>,
input: &'i L::Input,
input: &'i I,
) -> Result<Self::Output> {
let mut gss: GssGraph<'i, I, S, P, TK> = GssGraph::new();
let start_head = gss.add_head(context.clone());
Expand Down
6 changes: 3 additions & 3 deletions rustemo/src/lr/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ where
}
}

impl<'i, C, S, P, I, TK, NTK, D, L, B> Parser<'i, I, C, L, S, TK>
impl<'i, C, S, P, I, TK, NTK, D, L, B> Parser<'i, I, C, S, TK>
for LRParser<'i, C, S, P, TK, NTK, D, L, B, I>
where
C: Context<'i, I, S, TK> + Default,
Expand All @@ -302,7 +302,7 @@ where
{
type Output = B::Output;

fn parse(&self, input: &'i L::Input) -> Result<Self::Output> {
fn parse(&self, input: &'i I) -> Result<Self::Output> {
log!("\n{}", "*** Parsing started".red().bold());
log!("\nfile: {}", self.file_name);
let mut context = C::default();
Expand All @@ -313,7 +313,7 @@ where
fn parse_with_context(
&self,
context: &mut C,
input: &'i L::Input,
input: &'i I,
) -> Result<Self::Output> {
let mut parse_stack: ParseStack<S, I, C, TK> =
ParseStack::new(context, self.start_state);
Expand Down
9 changes: 4 additions & 5 deletions rustemo/src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
use std::path::Path;

use crate::{context::Context, error::Result, input::Input, lexer::Lexer};
use crate::{context::Context, error::Result, input::Input};

/// The trait implemented by all Rustemo parsers.
pub trait Parser<'i, I, C, L, S, TK>
pub trait Parser<'i, I, C, S, TK>
where
I: Input + ?Sized,
C: Context<'i, I, S, TK>,
L: Lexer<'i, C, S, TK, Input = I>,
S: State,
{
type Output;

/// Parse the given input and produce the result. The output type is set by
/// the parser implementers and it is usually defined by the builder if the
/// building is done during the parse process.
fn parse(&self, input: &'i L::Input) -> Result<Self::Output>;
fn parse(&self, input: &'i I) -> Result<Self::Output>;

/// Parse with the given context which has information about the current
/// parsing state (e.g. position, location). Used in situation when we need
Expand All @@ -24,7 +23,7 @@ where
fn parse_with_context(
&self,
context: &mut C,
input: &'i L::Input,
input: &'i I,
) -> Result<Self::Output>;

/// A convenience method for loading the content from the given file and
Expand Down
2 changes: 1 addition & 1 deletion tests/src/output_dir/output_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl<
}
}
#[allow(dead_code)]
impl<'i, I, L, B> Parser<'i, I, Context<'i, I>, L, State, TokenKind>
impl<'i, I, L, B> Parser<'i, I, Context<'i, I>, State, TokenKind>
for OutputDirParser<'i, I, L, B>
where
I: InputT + ?Sized + Debug,
Expand Down

0 comments on commit 92d7afd

Please sign in to comment.