Skip to content

Commit 75e50d5

Browse files
committed
runtime: split Parser into Parser (more general) and Runtime (GLL-specific).
1 parent b84918f commit 75e50d5

2 files changed

Lines changed: 184 additions & 108 deletions

File tree

src/generate/rust.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ impl Continuation<'_> {
470470
fn to_inline(&mut self) -> &mut Src {
471471
if let Code::Label(ref label) = self.code {
472472
self.code = Code::Inline(quote!(
473-
p.spawn(#label);
473+
rt.spawn(#label);
474474
));
475475
}
476476

@@ -583,7 +583,7 @@ macro_rules! thunk {
583583
}
584584

585585
fn pop_saved<F: ContFn>(f: impl FnOnce(Src) -> Thunk<F>) -> Thunk<impl ContFn> {
586-
thunk!(let saved = p.take_saved();)
586+
thunk!(let saved = rt.take_saved();)
587587
+ f(quote!(saved))
588588
+ Thunk::new(|mut cont| {
589589
if let Some(&None) = cont.nested_frames.last() {
@@ -600,7 +600,7 @@ fn pop_saved<F: ContFn>(f: impl FnOnce(Src) -> Thunk<F>) -> Thunk<impl ContFn> {
600600
}
601601

602602
fn push_saved(parse_node_kind: ParseNodeKind) -> Thunk<impl ContFn> {
603-
thunk!(p.save(#parse_node_kind);)
603+
thunk!(rt.save(#parse_node_kind);)
604604
+ Thunk::new(move |mut cont| {
605605
if let Some((ret_label, outer_fn_label)) = cont.nested_frames.pop().unwrap() {
606606
let inner_fn_label = mem::replace(cont.fn_code_label, outer_fn_label);
@@ -627,14 +627,14 @@ fn call(callee: Rc<CodeLabel>) -> Thunk<impl ContFn> {
627627
Thunk::new(move |mut cont| {
628628
let label = cont.to_label().clone();
629629
cont.code = Code::Inline(quote!(
630-
p.call(#callee, #label);
630+
rt.call(#callee, #label);
631631
));
632632
cont
633633
})
634634
}
635635

636636
fn ret() -> Thunk<impl ContFn> {
637-
thunk!(p.ret();)
637+
thunk!(rt.ret();)
638638
+ Thunk::new(|mut cont| {
639639
assert!(cont.to_inline().is_empty());
640640
cont
@@ -748,7 +748,7 @@ fn reify_as(label: Rc<CodeLabel>) -> Thunk<impl ContFn> {
748748
}
749749

750750
fn forest_add_choice(parse_node_kind: &ParseNodeKind, choice: ParseNodeKind) -> Thunk<impl ContFn> {
751-
thunk!(p.forest_add_choice(#parse_node_kind, #choice);)
751+
thunk!(rt.forest_add_choice(#parse_node_kind, #choice);)
752752
}
753753

754754
fn concat_and_forest_add(
@@ -760,7 +760,7 @@ fn concat_and_forest_add(
760760
left + push_saved(left_parse_node_kind)
761761
+ right
762762
+ pop_saved(move |saved| {
763-
thunk!(p.forest_add_split(
763+
thunk!(rt.forest_add_split(
764764
#parse_node_kind,
765765
#saved,
766766
);)
@@ -792,7 +792,7 @@ impl<Pat: Ord + Hash + RustInputPat> RuleGenerateMethods<Pat> for Rule<Pat> {
792792
(Rule::Empty, _) => cont,
793793
(Rule::Eat(pat), _) => {
794794
let pat = pat.rust_matcher();
795-
check(quote!(let Some(mut p) = p.input_consume_left(&(#pat)))).apply(cont)
795+
check(quote!(let Some(mut rt) = rt.input_consume_left(&(#pat)))).apply(cont)
796796
}
797797
(Rule::Call(r), _) => call(Rc::new(CodeLabel::NamedRule(r.clone()))).apply(cont),
798798
(Rule::Concat([left, right]), None) => {
@@ -942,7 +942,7 @@ where
942942
gll::runtime::ParseError<I::SourceInfoPoint>,
943943
>
944944
{
945-
gll::runtime::Parser::parse(
945+
gll::runtime::Runtime::parse(
946946
input,
947947
#code_label,
948948
#parse_node_kind,
@@ -1387,7 +1387,7 @@ where
13871387
quote!(impl<I> gll::runtime::CodeStep<I> for _C
13881388
where I: gll::input::Input<Slice = #rust_slice_ty>,
13891389
{
1390-
fn step<'i>(self, mut p: gll::runtime::Parser<'_, 'i, _C, I>) {
1390+
fn step<'i>(self, mut rt: gll::runtime::Runtime<'_, 'i, _C, I>) {
13911391
match self {
13921392
#(#code_label_arms)*
13931393
}

0 commit comments

Comments
 (0)