Skip to content

Commit 190b94c

Browse files
committed
refactor: unify parsing method names and update documentation
1 parent 3ef1f90 commit 190b94c

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

parse-it-codegen/src/backend.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ impl Parsing {
211211
for (value, op) in self.into_iter() {
212212
let value = value.to_ident();
213213
let op = match op {
214-
ParseOp::Just(c) => quote! { let #value = #state.parse_terminal(#c); },
214+
ParseOp::Just(c) => quote! { let #value = #state.parse(#c); },
215215
ParseOp::Pat(p, caps) => quote! {
216-
let #value = #state.parse(|tt| match tt {
216+
let #value = #state.parse_with(|tt| match tt {
217217
#p => Some((#(#caps),*)),
218218
_ => None,
219219
});

parse-it-codegen/src/middle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ impl Parsing {
247247

248248
pub enum ParseOp {
249249
/// ```ignore
250-
/// {state}.parse_terminal({lit})
250+
/// {state}.parse({lit})
251251
/// ```
252252
Just(syn::Lit),
253253
/// ```ignore

parse-it/src/memo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ pub fn memorize<'a, L: Lexer<'a>, T: Clone>(
8484
/// let fork = &mut state.fork();
8585
/// if let Ok(mut s) = parse(fork, memo) {
8686
/// state.advance_to(fork);
87-
/// s.push(state.parse_terminal('b')?);
87+
/// s.push(state.parse('b')?);
8888
/// Ok(s)
8989
/// } else {
90-
/// state.parse_terminal('a').map(|_| String::from("a"))
90+
/// state.parse('a').map(|_| String::from("a"))
9191
/// }
9292
/// })
9393
/// }

parse-it/src/parser.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ impl Error {
5252
/// ```
5353
/// # use parse_it::*;
5454
/// fn parse_abc(state: &mut ParserState<CharLexer>) -> Result<char, Error> {
55-
/// state.parse_terminal('a')?;
56-
/// state.parse_terminal('b')?;
57-
/// state.parse_terminal('c')?;
55+
/// state.parse('a')?;
56+
/// state.parse('b')?;
57+
/// state.parse('c')?;
5858
/// Ok('c')
5959
/// }
6060
///
@@ -96,8 +96,8 @@ impl Error {
9696
/// }
9797
///
9898
/// let mut state = ParserState::new(CharLexer::new("aaa"));
99-
/// assert_eq!(parse_option(&mut state, |state| state.parse_terminal('a')).unwrap(), Some('a'));
100-
/// assert_eq!(parse_option(&mut state, |state| state.parse_terminal('b')).unwrap(), None);
99+
/// assert_eq!(parse_option(&mut state, |state| state.parse('a')).unwrap(), Some('a'));
100+
/// assert_eq!(parse_option(&mut state, |state| state.parse('b')).unwrap(), None);
101101
/// ```
102102
pub struct ParserState<L> {
103103
span: Span,
@@ -136,18 +136,18 @@ impl<'a, L: Lexer<'a>> ParserState<L> {
136136
}
137137

138138
/// Consume the next token if it matches the given token.
139-
pub fn parse<T>(&mut self, matches: impl FnOnce(L::Token) -> Option<T>) -> Result<T, Error> {
139+
pub fn parse_with<T>(&mut self, matches: impl FnOnce(L::Token) -> Option<T>) -> Result<T, Error> {
140140
self.next()
141141
.and_then(matches)
142142
.ok_or_else(|| Error::new(self.span))
143143
}
144144

145145
/// Consume the next token if it matches the given token via [`PartialEq`].
146-
pub fn parse_terminal<T>(&mut self, terminal: T) -> Result<L::Token, Error>
146+
pub fn parse<T>(&mut self, terminal: T) -> Result<L::Token, Error>
147147
where
148148
L::Token: PartialEq<T>,
149149
{
150-
self.parse(|tt| tt.eq(&terminal).then_some(tt))
150+
self.parse_with(|tt| tt.eq(&terminal).then_some(tt))
151151
}
152152

153153
/// Report an error at the current position.

0 commit comments

Comments
 (0)