Skip to content

Commit 7cb6cef

Browse files
committed
Add span to invalid token lex error
1 parent dc95810 commit 7cb6cef

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/fallback.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub(crate) struct TokenStream {
3636

3737
#[derive(Debug)]
3838
pub(crate) struct LexError {
39-
span: Span,
39+
pub(crate) span: Span,
4040
}
4141

4242
impl LexError {

src/parse.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ pub(crate) fn token_stream(mut input: Cursor) -> Result<TokenStream, LexError> {
209209
} else {
210210
let (rest, mut tt) = match leaf_token(input) {
211211
Ok((rest, tt)) => (rest, tt),
212-
Err(Reject) => return Err(LexError::todo()),
212+
Err(Reject) => return Err(lex_error(input)),
213213
};
214214
tt.set_span(crate::Span::_new_stable(Span {
215215
#[cfg(span_locations)]
@@ -223,6 +223,19 @@ pub(crate) fn token_stream(mut input: Cursor) -> Result<TokenStream, LexError> {
223223
}
224224
}
225225

226+
fn lex_error(cursor: Cursor) -> LexError {
227+
#[cfg(not(span_locations))]
228+
let _ = cursor;
229+
LexError {
230+
span: Span {
231+
#[cfg(span_locations)]
232+
lo: cursor.off,
233+
#[cfg(span_locations)]
234+
hi: cursor.off,
235+
},
236+
}
237+
}
238+
226239
fn leaf_token(input: Cursor) -> PResult<TokenTree> {
227240
if let Ok((input, l)) = literal(input) {
228241
// must be parsed before ident

0 commit comments

Comments
 (0)