Skip to content

Commit

Permalink
rework: simplify API by reexporting public types
Browse files Browse the repository at this point in the history
  • Loading branch information
igordejanovic committed Oct 19, 2023
1 parent c930651 commit 6f259ac
Show file tree
Hide file tree
Showing 82 changed files with 210 additions and 264 deletions.
6 changes: 3 additions & 3 deletions docs/src/builders.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ If you have a specific requirement for the build process you can implement a
builder from scratch.

To provide a custom builder you start with a type that implements a
`rustemo::builder::Builder` trait and after that implements a concrete parsing
algorithm trait. Currently, Rustemo is a LR parser thus you can use
`rustemo::builder::lr::Builder` trait.
`rustemo::Builder` trait and after that implements a concrete parsing algorithm
trait. Currently, Rustemo is a LR parser thus you can use `rustemo::LRBuilder`
trait.

Let's see how can we do all of this by implementing a builder that does
on-the-fly calculation of the arithmetic expression. Start with a type and a
Expand Down
2 changes: 1 addition & 1 deletion docs/src/parsing/expressions/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use expressions::ExpressionsParser;
use rustemo::parser::Parser;
use rustemo::rustemo_mod;
use rustemo::Parser;

rustemo_mod! {#[allow(unused_imports)]
pub(crate) expressions, "/src"}
Expand Down
26 changes: 12 additions & 14 deletions docs/src/tutorials/calculator/calculator1/src/calculator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@
use std::fmt::Debug;
use std::hash::Hash;
use std::rc::Rc;
use rustemo::Result;
use rustemo::input;
use rustemo::lexer::{self, Lexer, Token};
use rustemo::parser::{self, Parser};
use rustemo::builder::Builder;
use rustemo::lr::parser::ParserDefinition;
use rustemo::{
Result, Input as InputT, Lexer, Token, TokenRecognizer as TokenRecognizerT, Parser,
ParserDefinition, State as StateT, Builder,
};
use regex::Regex;
use once_cell::sync::Lazy;
use rustemo::lexer::StringLexer;
use rustemo::lr::builder::LRBuilder;
use rustemo::StringLexer;
use rustemo::LRBuilder;
use super::calculator_actions;
use rustemo::lr::{parser::LRParser, context::LRContext};
use rustemo::lr::parser::Action::{self, Shift, Reduce, Accept, Error};
use rustemo::{LRParser, LRContext};
use rustemo::Action::{self, Shift, Reduce, Accept, Error};
#[allow(unused_imports)]
use rustemo::debug::{log, logn};
#[allow(unused_imports)]
Expand Down Expand Up @@ -78,7 +76,7 @@ pub enum State {
OperatorS3,
OperandS4,
}
impl parser::State for State {
impl StateT for State {
fn default_layout() -> Option<Self> {
None
}
Expand Down Expand Up @@ -162,7 +160,7 @@ for CalculatorParserDefinition {
pub(crate) type Context<'i, I> = LRContext<'i, I, State, TokenKind>;
pub struct CalculatorParser<
'i,
I: input::Input + ?Sized,
I: InputT + ?Sized,
L: Lexer<'i, Context<'i, I>, State, TokenKind, Input = I>,
B,
>(
Expand Down Expand Up @@ -205,7 +203,7 @@ impl<
impl<'i, I, L, B> Parser<'i, I, Context<'i, I>, L, State, TokenKind>
for CalculatorParser<'i, I, L, B>
where
I: input::Input + ?Sized + Debug,
I: InputT + ?Sized + Debug,
L: Lexer<'i, Context<'i, I>, State, TokenKind, Input = I>,
B: LRBuilder<'i, I, Context<'i, I>, State, ProdKind, TokenKind>,
{
Expand Down Expand Up @@ -240,7 +238,7 @@ pub enum Recognizer {
#[allow(dead_code)]
#[derive(Debug)]
pub struct TokenRecognizer(TokenKind, Recognizer);
impl<'i> lexer::TokenRecognizer<'i> for TokenRecognizer {
impl<'i> TokenRecognizerT<'i> for TokenRecognizer {
fn recognize(&self, input: &'i str) -> Option<&'i str> {
match &self {
#[allow(unused_variables)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/// This file is maintained by rustemo but can be modified manually.
/// All manual changes will be preserved except non-doc comments.
use ::rustemo::context::Context;
use rustemo::lexer;
use ::rustemo::{Context, Token as BaseToken};
use super::calculator::{self, TokenKind};
pub type Input = str;
pub type Ctx<'i> = super::calculator::Context<'i, Input>;
#[allow(dead_code)]
pub type Token<'i> = lexer::Token<'i, Input, TokenKind>;
pub type Token<'i> = BaseToken<'i, Input, TokenKind>;
pub type Operand = String;
pub fn operand(_ctx: &Ctx, token: Token) -> Operand {
token.value.into()
Expand Down
2 changes: 1 addition & 1 deletion docs/src/tutorials/calculator/calculator1/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ANCHOR: header
use rustemo::parser::Parser;
use rustemo::Parser;
use std::io;
// Use the generated parser
use crate::calculator::CalculatorParser;
Expand Down
2 changes: 1 addition & 1 deletion docs/src/tutorials/calculator/calculator1/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Use the generated parser
use crate::calculator::CalculatorParser;
use rustemo::parser::Parser;
use rustemo::Parser;
use rustemo_compiler::output_cmp;

#[test]
Expand Down
26 changes: 12 additions & 14 deletions docs/src/tutorials/calculator/calculator2/src/calculator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@
use std::fmt::Debug;
use std::hash::Hash;
use std::rc::Rc;
use rustemo::Result;
use rustemo::input;
use rustemo::lexer::{self, Lexer, Token};
use rustemo::parser::{self, Parser};
use rustemo::builder::Builder;
use rustemo::lr::parser::ParserDefinition;
use rustemo::{
Result, Input as InputT, Lexer, Token, TokenRecognizer as TokenRecognizerT, Parser,
ParserDefinition, State as StateT, Builder,
};
use regex::Regex;
use once_cell::sync::Lazy;
use rustemo::lexer::StringLexer;
use rustemo::lr::builder::LRBuilder;
use rustemo::StringLexer;
use rustemo::LRBuilder;
use super::calculator_actions;
use rustemo::lr::{parser::LRParser, context::LRContext};
use rustemo::lr::parser::Action::{self, Shift, Reduce, Accept, Error};
use rustemo::{LRParser, LRContext};
use rustemo::Action::{self, Shift, Reduce, Accept, Error};
#[allow(unused_imports)]
use rustemo::debug::{log, logn};
#[allow(unused_imports)]
Expand Down Expand Up @@ -99,7 +97,7 @@ pub enum State {
ES9,
ES10,
}
impl parser::State for State {
impl StateT for State {
fn default_layout() -> Option<Self> {
None
}
Expand Down Expand Up @@ -288,7 +286,7 @@ for CalculatorParserDefinition {
pub(crate) type Context<'i, I> = LRContext<'i, I, State, TokenKind>;
pub struct CalculatorParser<
'i,
I: input::Input + ?Sized,
I: InputT + ?Sized,
L: Lexer<'i, Context<'i, I>, State, TokenKind, Input = I>,
B,
>(
Expand Down Expand Up @@ -331,7 +329,7 @@ impl<
impl<'i, I, L, B> Parser<'i, I, Context<'i, I>, L, State, TokenKind>
for CalculatorParser<'i, I, L, B>
where
I: input::Input + ?Sized + Debug,
I: InputT + ?Sized + Debug,
L: Lexer<'i, Context<'i, I>, State, TokenKind, Input = I>,
B: LRBuilder<'i, I, Context<'i, I>, State, ProdKind, TokenKind>,
{
Expand Down Expand Up @@ -366,7 +364,7 @@ pub enum Recognizer {
#[allow(dead_code)]
#[derive(Debug)]
pub struct TokenRecognizer(TokenKind, Recognizer);
impl<'i> lexer::TokenRecognizer<'i> for TokenRecognizer {
impl<'i> TokenRecognizerT<'i> for TokenRecognizer {
fn recognize(&self, input: &'i str) -> Option<&'i str> {
match &self {
#[allow(unused_variables)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/// This file is maintained by rustemo but can be modified manually.
/// All manual changes will be preserved except non-doc comments.
use ::rustemo::context::Context;
use rustemo::lexer;
use ::rustemo::{Context, Token as BaseToken};
use super::calculator::{self, TokenKind};
pub type Input = str;
pub type Ctx<'i> = super::calculator::Context<'i, Input>;
#[allow(dead_code)]
pub type Token<'i> = lexer::Token<'i, Input, TokenKind>;
pub type Token<'i> = BaseToken<'i, Input, TokenKind>;
pub type Number = String;
pub fn number(_ctx: &Ctx, token: Token) -> Number {
token.value.into()
Expand Down
2 changes: 1 addition & 1 deletion docs/src/tutorials/calculator/calculator2/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustemo::parser::Parser;
use rustemo::Parser;
use std::io;
// Use the generated parser
use crate::calculator::CalculatorParser;
Expand Down
2 changes: 1 addition & 1 deletion docs/src/tutorials/calculator/calculator2/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Use the generated parser
use crate::calculator::CalculatorParser;
use rustemo::parser::Parser;
use rustemo::Parser;
use rustemo_compiler::output_cmp;

#[test]
Expand Down
26 changes: 12 additions & 14 deletions docs/src/tutorials/calculator/calculator3/src/calculator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@
use std::fmt::Debug;
use std::hash::Hash;
use std::rc::Rc;
use rustemo::Result;
use rustemo::input;
use rustemo::lexer::{self, Lexer, Token};
use rustemo::parser::{self, Parser};
use rustemo::builder::Builder;
use rustemo::lr::parser::ParserDefinition;
use rustemo::{
Result, Input as InputT, Lexer, Token, TokenRecognizer as TokenRecognizerT, Parser,
ParserDefinition, State as StateT, Builder,
};
use regex::Regex;
use once_cell::sync::Lazy;
use rustemo::lexer::StringLexer;
use rustemo::lr::builder::LRBuilder;
use rustemo::StringLexer;
use rustemo::LRBuilder;
use super::calculator_actions;
use rustemo::lr::{parser::LRParser, context::LRContext};
use rustemo::lr::parser::Action::{self, Shift, Reduce, Accept, Error};
use rustemo::{LRParser, LRContext};
use rustemo::Action::{self, Shift, Reduce, Accept, Error};
#[allow(unused_imports)]
use rustemo::debug::{log, logn};
#[allow(unused_imports)]
Expand Down Expand Up @@ -99,7 +97,7 @@ pub enum State {
ES9,
ES10,
}
impl parser::State for State {
impl StateT for State {
fn default_layout() -> Option<Self> {
None
}
Expand Down Expand Up @@ -288,7 +286,7 @@ for CalculatorParserDefinition {
pub(crate) type Context<'i, I> = LRContext<'i, I, State, TokenKind>;
pub struct CalculatorParser<
'i,
I: input::Input + ?Sized,
I: InputT + ?Sized,
L: Lexer<'i, Context<'i, I>, State, TokenKind, Input = I>,
B,
>(
Expand Down Expand Up @@ -331,7 +329,7 @@ impl<
impl<'i, I, L, B> Parser<'i, I, Context<'i, I>, L, State, TokenKind>
for CalculatorParser<'i, I, L, B>
where
I: input::Input + ?Sized + Debug,
I: InputT + ?Sized + Debug,
L: Lexer<'i, Context<'i, I>, State, TokenKind, Input = I>,
B: LRBuilder<'i, I, Context<'i, I>, State, ProdKind, TokenKind>,
{
Expand Down Expand Up @@ -366,7 +364,7 @@ pub enum Recognizer {
#[allow(dead_code)]
#[derive(Debug)]
pub struct TokenRecognizer(TokenKind, Recognizer);
impl<'i> lexer::TokenRecognizer<'i> for TokenRecognizer {
impl<'i> TokenRecognizerT<'i> for TokenRecognizer {
fn recognize(&self, input: &'i str) -> Option<&'i str> {
match &self {
#[allow(unused_variables)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/// This file is maintained by rustemo but can be modified manually.
/// All manual changes will be preserved except non-doc comments.
use ::rustemo::context::Context;
use rustemo::lexer;
use ::rustemo::{Context, Token as BaseToken};
use super::calculator::{self, TokenKind};
pub type Input = str;
pub type Ctx<'i> = super::calculator::Context<'i, Input>;
#[allow(dead_code)]
pub type Token<'i> = lexer::Token<'i, Input, TokenKind>;
pub type Token<'i> = BaseToken<'i, Input, TokenKind>;
pub type Number = String;
pub fn number(_ctx: &Ctx, token: Token) -> Number {
token.value.into()
Expand Down
2 changes: 1 addition & 1 deletion docs/src/tutorials/calculator/calculator3/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustemo::parser::Parser;
use rustemo::Parser;
use std::io;
// Use the generated parser
use crate::calculator::CalculatorParser;
Expand Down
2 changes: 1 addition & 1 deletion docs/src/tutorials/calculator/calculator3/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustemo::parser::Parser;
use rustemo::Parser;
// Use the generated parser
use crate::calculator::CalculatorParser;
use rustemo_compiler::output_cmp;
Expand Down
26 changes: 12 additions & 14 deletions docs/src/tutorials/calculator/calculator4/src/calculator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@
use std::fmt::Debug;
use std::hash::Hash;
use std::rc::Rc;
use rustemo::Result;
use rustemo::input;
use rustemo::lexer::{self, Lexer, Token};
use rustemo::parser::{self, Parser};
use rustemo::builder::Builder;
use rustemo::lr::parser::ParserDefinition;
use rustemo::{
Result, Input as InputT, Lexer, Token, TokenRecognizer as TokenRecognizerT, Parser,
ParserDefinition, State as StateT, Builder,
};
use regex::Regex;
use once_cell::sync::Lazy;
use rustemo::lexer::StringLexer;
use rustemo::lr::builder::LRBuilder;
use rustemo::StringLexer;
use rustemo::LRBuilder;
use super::calculator_actions;
use rustemo::lr::{parser::LRParser, context::LRContext};
use rustemo::lr::parser::Action::{self, Shift, Reduce, Accept, Error};
use rustemo::{LRParser, LRContext};
use rustemo::Action::{self, Shift, Reduce, Accept, Error};
#[allow(unused_imports)]
use rustemo::debug::{log, logn};
#[allow(unused_imports)]
Expand Down Expand Up @@ -99,7 +97,7 @@ pub enum State {
ES9,
ES10,
}
impl parser::State for State {
impl StateT for State {
fn default_layout() -> Option<Self> {
None
}
Expand Down Expand Up @@ -288,7 +286,7 @@ for CalculatorParserDefinition {
pub(crate) type Context<'i, I> = LRContext<'i, I, State, TokenKind>;
pub struct CalculatorParser<
'i,
I: input::Input + ?Sized,
I: InputT + ?Sized,
L: Lexer<'i, Context<'i, I>, State, TokenKind, Input = I>,
B,
>(
Expand Down Expand Up @@ -331,7 +329,7 @@ impl<
impl<'i, I, L, B> Parser<'i, I, Context<'i, I>, L, State, TokenKind>
for CalculatorParser<'i, I, L, B>
where
I: input::Input + ?Sized + Debug,
I: InputT + ?Sized + Debug,
L: Lexer<'i, Context<'i, I>, State, TokenKind, Input = I>,
B: LRBuilder<'i, I, Context<'i, I>, State, ProdKind, TokenKind>,
{
Expand Down Expand Up @@ -366,7 +364,7 @@ pub enum Recognizer {
#[allow(dead_code)]
#[derive(Debug)]
pub struct TokenRecognizer(TokenKind, Recognizer);
impl<'i> lexer::TokenRecognizer<'i> for TokenRecognizer {
impl<'i> TokenRecognizerT<'i> for TokenRecognizer {
fn recognize(&self, input: &'i str) -> Option<&'i str> {
match &self {
#[allow(unused_variables)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/// This file is maintained by rustemo but can be modified manually.
/// All manual changes will be preserved except non-doc comments.
use ::rustemo::context::Context;
use rustemo::lexer;
use ::rustemo::{Context, Token as BaseToken};
use super::calculator::{self, TokenKind};
pub type Input = str;
pub type Ctx<'i> = super::calculator::Context<'i, Input>;
#[allow(dead_code)]
pub type Token<'i> = lexer::Token<'i, Input, TokenKind>;
pub type Token<'i> = BaseToken<'i, Input, TokenKind>;
/// ANCHOR: number
pub type Number = String;
/// ANCHOR_END: number
Expand Down
2 changes: 1 addition & 1 deletion docs/src/tutorials/calculator/calculator4/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustemo::parser::Parser;
use rustemo::Parser;
use std::io;
// Use the generated parser
use crate::calculator::CalculatorParser;
Expand Down
2 changes: 1 addition & 1 deletion docs/src/tutorials/calculator/calculator4/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustemo::parser::Parser;
use rustemo::Parser;
// Use the generated parser
use crate::calculator::CalculatorParser;
use rustemo_compiler::output_cmp;
Expand Down
Loading

0 comments on commit 6f259ac

Please sign in to comment.