Skip to content

[r+] Issue model lexer questionmark #21120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/grammar/RustLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,13 @@ LIT_STR_RAW
: 'r' LIT_STR_RAW_INNER SUFFIX?
;


QUESTION : '?';

IDENT : XID_start XID_continue* ;

fragment QUESTION_IDENTIFIER : QUESTION? IDENT;

LIFETIME : '\'' IDENT ;

WHITESPACE : [ \r\n\t]+ ;
Expand Down
19 changes: 10 additions & 9 deletions src/grammar/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(globs, plugin)]
#![feature(plugin)]

extern crate syntax;
extern crate rustc;
Expand Down Expand Up @@ -107,13 +107,14 @@ fn parse_token_list(file: &str) -> HashMap<String, token::Token> {
"LE" => token::Le,
"LIT_BINARY" => token::Literal(token::Binary(Name(0)), None),
"LIT_BINARY_RAW" => token::Literal(token::BinaryRaw(Name(0), 0), None),
"QUESTION" => token::Question,
_ => continue,
};

res.insert(num.to_string(), tok);
}

debug!("Token map: {}", res);
debug!("Token map: {:?}", res);
res
}

Expand Down Expand Up @@ -161,7 +162,7 @@ fn fixchar(mut lit: &str) -> ast::Name {
parse::token::intern(lit.slice(1, lit.len() - 1))
}

fn count(lit: &str) -> uint {
fn count(lit: &str) -> usize {
lit.chars().take_while(|c| *c == '#').count()
}

Expand All @@ -176,12 +177,12 @@ fn parse_antlr_token(s: &str, tokens: &HashMap<String, token::Token>) -> TokenAn
let toknum = m.name("toknum").unwrap_or("");
let content = m.name("content").unwrap_or("");

let proto_tok = tokens.get(toknum).expect(format!("didn't find token {} in the map",
let proto_tok = tokens.get(toknum).expect(format!("didn't find token {:?} in the map",
toknum).as_slice());

let nm = parse::token::intern(content);

debug!("What we got: content (`{}`), proto: {}", content, proto_tok);
debug!("What we got: content (`{}`), proto: {:?}", content, proto_tok);

let real_tok = match *proto_tok {
token::BinOp(..) => token::BinOp(str_to_binop(content)),
Expand Down Expand Up @@ -265,7 +266,7 @@ fn main() {
continue
}

assert!(rustc_tok.sp == antlr_tok.sp, "{} and {} have different spans", rustc_tok,
assert!(rustc_tok.sp == antlr_tok.sp, "{:?} and {:?} have different spans", rustc_tok,
antlr_tok);

macro_rules! matches {
Expand All @@ -276,12 +277,12 @@ fn main() {
if !tok_cmp(&rustc_tok.tok, &antlr_tok.tok) {
// FIXME #15677: needs more robust escaping in
// antlr
warn!("Different names for {} and {}", rustc_tok, antlr_tok);
warn!("Different names for {:?} and {:?}", rustc_tok, antlr_tok);
}
}
_ => panic!("{} is not {}", antlr_tok, rustc_tok)
_ => panic!("{:?} is not {:?}", antlr_tok, rustc_tok)
},)*
ref c => assert!(c == &antlr_tok.tok, "{} is not {}", rustc_tok, antlr_tok)
ref c => assert!(c == &antlr_tok.tok, "{:?} is not {:?}", rustc_tok, antlr_tok)
}
)
}
Expand Down