Skip to content

Commit 6f66cce

Browse files
authored
Merge pull request #29 from alexcrichton/no-underscore-ident
Parse a bare `_` as an `Op`, not a `Term`
2 parents fe8063c + 52725f7 commit 6f66cce

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/stable.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ named!(token_kind -> TokenNode, alt!(
358358
|
359359
map!(literal, TokenNode::Literal) // must be before symbol
360360
|
361-
map!(symbol, TokenNode::Term)
361+
symbol
362362
|
363363
map!(op, |(op, kind)| TokenNode::Op(op, kind))
364364
));
@@ -383,7 +383,7 @@ named!(delimited -> (Delimiter, ::TokenStream), alt!(
383383
) => { |ts| (Delimiter::Brace, ts) }
384384
));
385385

386-
fn symbol(mut input: &str) -> PResult<::Term> {
386+
fn symbol(mut input: &str) -> PResult<TokenNode> {
387387
input = skip_whitespace(input);
388388

389389
let mut chars = input.char_indices();
@@ -409,7 +409,12 @@ fn symbol(mut input: &str) -> PResult<::Term> {
409409
if lifetime && &input[..end] != "'static" && KEYWORDS.contains(&&input[1..end]) {
410410
Err(LexError)
411411
} else {
412-
Ok((&input[end..], ::Term::intern(&input[..end])))
412+
let (a, b) = input.split_at(end);
413+
if a == "_" {
414+
Ok((b, TokenNode::Op('_', Spacing::Alone)))
415+
} else {
416+
Ok((b, TokenNode::Term(::Term::intern(a))))
417+
}
413418
}
414419
}
415420

0 commit comments

Comments
 (0)