Skip to content

Commit 0ced820

Browse files
committed
Replace parse_generictree, parse_noaction, with a new parse_map fn.
1 parent 5895724 commit 0ced820

File tree

7 files changed

+294
-101
lines changed

7 files changed

+294
-101
lines changed

lrlex/src/lib/ctbuilder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ where
548548
let input = fs::read_to_string(&path)?;
549549
let l: LRNonStreamingLexer<LexerTypesT> =
550550
closure_lexerdef.lexer(&input);
551-
for e in rtpb.parse_noaction(&l) {
551+
for e in rtpb.parse_map(&l, &|_| (), &|_, _| ()).1 {
552552
Err(format!("parsing {}: {}", path.display(), e))?
553553
}
554554
}

lrpar/examples/calc_parsetree/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::io::{self, BufRead, Write};
22

33
use cfgrammar::RIdx;
44
use lrlex::{DefaultLexeme, lrlex_mod};
5-
use lrpar::{Lexeme, Node, lrpar_mod};
5+
use lrpar::{Lexeme, lrpar_mod};
66

77
// Using `lrlex_mod!` brings the lexer for `calc.l` into scope. By default the module name will be
88
// `calc_l` (i.e. the file name, minus any extensions, with a suffix of `_l`).
@@ -11,6 +11,8 @@ lrlex_mod!("calc.l");
1111
// `calc_y` (i.e. the file name, minus any extensions, with a suffix of `_y`).
1212
lrpar_mod!("calc.y");
1313

14+
use calc_y::Node;
15+
1416
fn main() {
1517
// Get the `LexerDef` for the `calc` language.
1618
let lexerdef = calc_l::lexerdef();

lrpar/examples/start_states/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::io::{self, BufRead, Write};
22

33
use cfgrammar::RIdx;
44
use lrlex::{DefaultLexeme, lrlex_mod};
5-
use lrpar::{Lexeme, Node, lrpar_mod};
5+
use lrpar::{Lexeme, lrpar_mod};
66

77
// Using `lrlex_mod!` brings the lexer for `comment.l` into scope. By default the module name will be
88
// `comment_l` (i.e. the file name, minus any extensions, with a suffix of `_l`).
@@ -11,6 +11,8 @@ lrlex_mod!("comment.l");
1111
// `comment_y` (i.e. the file name, minus any extensions, with a suffix of `_y`).
1212
lrpar_mod!("comment.y");
1313

14+
use comment_y::Node;
15+
1416
fn main() {
1517
// Get the `LexerDef` for the `comment` language.
1618
let lexerdef = comment_l::lexerdef();

lrpar/src/lib/ctbuilder.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ where
522522
/// the return type of the `%start` rule;
523523
/// * or, if the `yacckind` was set to
524524
/// `YaccKind::Original(YaccOriginalActionKind::GenericParseTree)`, it
525-
/// is [`crate::Node<StorageT>`].
525+
/// is [`modname::Node<StorageT>`].
526526
///
527527
/// # Panics
528528
///
@@ -897,7 +897,6 @@ where
897897
since = "0.11.0",
898898
note = "Please use grammar_path(), output_path(), build(), and token_map() instead"
899899
)]
900-
#[allow(deprecated)]
901900
pub fn process_file<P, Q>(
902901
&mut self,
903902
inp: P,
@@ -958,6 +957,21 @@ where
958957
| YaccKind::Original(YaccOriginalActionKind::GenericParseTree) => None,
959958
_ => unreachable!(),
960959
};
960+
961+
let additional_decls =
962+
if let Some(YaccKind::Original(YaccOriginalActionKind::GenericParseTree)) =
963+
self.yacckind
964+
{
965+
// `lrpar::Node`` is deprecated within the lrpar crate, but not from within this module,
966+
// Once it is removed from `lrpar`, we should move the declaration here entirely.
967+
Some(quote! {
968+
#[allow(unused_imports)]
969+
pub use ::lrpar::parser::_deprecated_moved_::Node;
970+
})
971+
} else {
972+
None
973+
};
974+
961975
let mod_name = format_ident!("{}", mod_name);
962976
let out_tokens = quote! {
963977
#visibility mod #mod_name {
@@ -969,6 +983,7 @@ where
969983
#![deny(unsafe_code)]
970984
#[allow(unused_imports)]
971985
use super::*;
986+
#additional_decls
972987
#parse_function
973988
#rule_consts
974989
#token_epp
@@ -1069,14 +1084,18 @@ where
10691084
quote! {
10701085
::lrpar::RTParserBuilder::new(&grm, &stable)
10711086
.recoverer(#recoverer)
1072-
.parse_generictree(lexer)
1087+
.parse_map(
1088+
lexer,
1089+
&|lexeme| Node::Term{lexeme},
1090+
&|ridx, nodes| Node::Nonterm{ridx, nodes}
1091+
)
10731092
}
10741093
}
10751094
YaccKind::Original(YaccOriginalActionKind::NoAction) => {
10761095
quote! {
10771096
::lrpar::RTParserBuilder::new(&grm, &stable)
10781097
.recoverer(#recoverer)
1079-
.parse_noaction(lexer)
1098+
.parse_map(lexer, &|_| (), &|_, _| ()).1
10801099
}
10811100
}
10821101
YaccKind::Original(YaccOriginalActionKind::UserAction) | YaccKind::Grmtools => {
@@ -1160,7 +1179,7 @@ where
11601179
}
11611180
}
11621181
YaccKind::Original(YaccOriginalActionKind::GenericParseTree) => quote! {
1163-
(::std::option::Option<::lrpar::Node<<#lexertypest as ::lrpar::LexerTypes>::LexemeT, #storaget>>,
1182+
(::std::option::Option<crate::Node<<#lexertypest as ::lrpar::LexerTypes>::LexemeT, #storaget>>,
11641183
::std::vec::Vec<::lrpar::LexParseError<#storaget, #lexertypest>>)
11651184
},
11661185
YaccKind::Original(YaccOriginalActionKind::NoAction) => quote! {

lrpar/src/lib/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,15 @@ pub mod test_utils;
208208
pub use crate::{
209209
ctbuilder::{CTParser, CTParserBuilder, RustEdition, Visibility},
210210
lex_api::{LexError, Lexeme, Lexer, LexerTypes, NonStreamingLexer},
211-
parser::{LexParseError, Node, ParseError, ParseRepair, RTParserBuilder, RecoveryKind},
211+
parser::{LexParseError, ParseError, ParseRepair, RTParserBuilder, RecoveryKind},
212212
};
213213

214+
#[allow(deprecated)]
214215
pub use crate::parser::action_generictree;
216+
217+
#[allow(deprecated)]
218+
pub use parser::Node;
219+
215220
/// A convenience macro for including statically compiled `.y` files. A file `src/a/b/c.y`
216221
/// processed by [CTParserBuilder::grammar_in_src_dir] can then be used in a crate with
217222
/// `lrpar_mod!("a/b/c.y")`.

0 commit comments

Comments
 (0)