Skip to content

Commit

Permalink
rework: hide Rc from LRParser::new
Browse files Browse the repository at this point in the history
  • Loading branch information
igordejanovic committed Dec 15, 2023
1 parent 2562fdf commit 8f78cd8
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 20 deletions.
3 changes: 1 addition & 2 deletions docs/src/tutorials/calculator/calculator1/src/calculator.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/// Generated by rustemo. Do not edit manually!
use std::fmt::Debug;
use std::hash::Hash;
use std::rc::Rc;
use rustemo::{
Result, Input as InputT, Lexer, Token, TokenRecognizer as TokenRecognizerT, Parser,
ParserDefinition, State as StateT, Builder,
Expand Down Expand Up @@ -193,7 +192,7 @@ impl<
State::default(),
false,
false,
Rc::new(StringLexer::new(true, &RECOGNIZERS)),
StringLexer::new(true, &RECOGNIZERS),
DefaultBuilder::new(),
),
)
Expand Down
3 changes: 1 addition & 2 deletions docs/src/tutorials/calculator/calculator2/src/calculator.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/// Generated by rustemo. Do not edit manually!
use std::fmt::Debug;
use std::hash::Hash;
use std::rc::Rc;
use rustemo::{
Result, Input as InputT, Lexer, Token, TokenRecognizer as TokenRecognizerT, Parser,
ParserDefinition, State as StateT, Builder,
Expand Down Expand Up @@ -319,7 +318,7 @@ impl<
State::default(),
false,
false,
Rc::new(StringLexer::new(true, &RECOGNIZERS)),
StringLexer::new(true, &RECOGNIZERS),
DefaultBuilder::new(),
),
)
Expand Down
3 changes: 1 addition & 2 deletions docs/src/tutorials/calculator/calculator3/src/calculator.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/// Generated by rustemo. Do not edit manually!
use std::fmt::Debug;
use std::hash::Hash;
use std::rc::Rc;
use rustemo::{
Result, Input as InputT, Lexer, Token, TokenRecognizer as TokenRecognizerT, Parser,
ParserDefinition, State as StateT, Builder,
Expand Down Expand Up @@ -319,7 +318,7 @@ impl<
State::default(),
false,
false,
Rc::new(StringLexer::new(true, &RECOGNIZERS)),
StringLexer::new(true, &RECOGNIZERS),
DefaultBuilder::new(),
),
)
Expand Down
3 changes: 1 addition & 2 deletions docs/src/tutorials/calculator/calculator4/src/calculator.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/// Generated by rustemo. Do not edit manually!
use std::fmt::Debug;
use std::hash::Hash;
use std::rc::Rc;
use rustemo::{
Result, Input as InputT, Lexer, Token, TokenRecognizer as TokenRecognizerT, Parser,
ParserDefinition, State as StateT, Builder,
Expand Down Expand Up @@ -319,7 +318,7 @@ impl<
State::default(),
false,
false,
Rc::new(StringLexer::new(true, &RECOGNIZERS)),
StringLexer::new(true, &RECOGNIZERS),
DefaultBuilder::new(),
),
)
Expand Down
3 changes: 1 addition & 2 deletions docs/src/tutorials/calculator/calculator5/src/calculator.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/// Generated by rustemo. Do not edit manually!
use std::fmt::Debug;
use std::hash::Hash;
use std::rc::Rc;
use rustemo::{
Result, Input as InputT, Lexer, Token, TokenRecognizer as TokenRecognizerT, Parser,
ParserDefinition, State as StateT, Builder,
Expand Down Expand Up @@ -319,7 +318,7 @@ impl<
State::default(),
false,
false,
Rc::new(StringLexer::new(true, &RECOGNIZERS)),
StringLexer::new(true, &RECOGNIZERS),
DefaultBuilder::new(),
),
)
Expand Down
3 changes: 1 addition & 2 deletions rustemo-compiler/src/lang/rustemo.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/// Generated by rustemo. Do not edit manually!
use std::fmt::Debug;
use std::hash::Hash;
use std::rc::Rc;
use rustemo::{
Result, Input as InputT, Lexer, Token, TokenRecognizer as TokenRecognizerT, Parser,
ParserDefinition, State as StateT, Builder,
Expand Down Expand Up @@ -16764,7 +16763,7 @@ impl<
State::default(),
false,
true,
Rc::new(StringLexer::new(false, &RECOGNIZERS)),
StringLexer::new(false, &RECOGNIZERS),
DefaultBuilder::new(),
),
)
Expand Down
4 changes: 2 additions & 2 deletions rustemo/src/glr/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,13 +957,13 @@ where
let mut gss: GssGraph<'i, I, S, P, TK> = GssGraph::new();
let start_head = gss.add_head(context.clone());
if self.has_layout {
*self.layout_parser.borrow_mut() = Some(LRParser::new(
*self.layout_parser.borrow_mut() = Some(LRParser::new_default(
self.definition,
S::default_layout().expect("Layout state not defined."),
true,
false,
Rc::clone(&self.lexer),
SliceBuilder::new(input),
RefCell::new(SliceBuilder::new(input)),
))
}

Expand Down
26 changes: 22 additions & 4 deletions rustemo/src/lr/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,26 @@ where
state: S,
partial_parse: bool,
has_layout: bool,
lexer: Rc<L>,
lexer: L,
builder: B,
) -> Self {
Self::new_default(
definition,
state,
partial_parse,
has_layout,
Rc::new(lexer),
RefCell::new(builder),
)
}

pub(crate) fn new_default(
definition: &'i D,
state: S,
partial_parse: bool,
has_layout: bool,
lexer: Rc<L>,
builder: RefCell<B>,
) -> Self {
Self {
definition,
Expand All @@ -183,7 +201,7 @@ where
start_state: state,
has_layout,
lexer,
builder: RefCell::new(builder),
builder,
phantom: PhantomData,
}
}
Expand Down Expand Up @@ -308,13 +326,13 @@ where
// produce the output and it never uses partial parse.
let layout_parser: LayoutParser<'i, C, S, P, TK, NTK, D, L, I> =
self.has_layout.then(|| {
LRParser::new(
LRParser::new_default(
self.definition,
S::default_layout().expect("Layout state not defined."),
true,
false,
Rc::clone(&self.lexer),
SliceBuilder::new(input),
RefCell::new(SliceBuilder::new(input)),
)
});

Expand Down
3 changes: 1 addition & 2 deletions tests/src/output_dir/output_dir.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/// Generated by rustemo. Do not edit manually!
use std::fmt::Debug;
use std::hash::Hash;
use std::rc::Rc;
use rustemo::{
Result, Input as InputT, Lexer, Token, TokenRecognizer as TokenRecognizerT, Parser,
ParserDefinition, State as StateT, Builder,
Expand Down Expand Up @@ -216,7 +215,7 @@ impl<
State::default(),
false,
false,
Rc::new(StringLexer::new(true, &RECOGNIZERS)),
StringLexer::new(true, &RECOGNIZERS),
DefaultBuilder::new(),
),
)
Expand Down

0 comments on commit 8f78cd8

Please sign in to comment.