Skip to content

Commit 9fdee0b

Browse files
committed
---
yaml --- r: 124925 b: refs/heads/auto c: 9fc5cf9 h: refs/heads/master i: 124923: 0be0d23 v: v3
1 parent 45588d8 commit 9fdee0b

File tree

3 files changed

+69
-32
lines changed

3 files changed

+69
-32
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: 76a15520212b1b9a72c099e0a163a31c102fcde4
16+
refs/heads/auto: 9fc5cf902f9613f40ce4d4346d1ae98a0904e67a
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/grammar/RustLexer.g4

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -153,28 +153,13 @@ LIFETIME : '\'' IDENT ;
153153

154154
WHITESPACE : [ \r\n\t]+ ;
155155

156-
LINE_COMMENT_NOT_A_TOKEN : '//' -> more, pushMode(LINE_COMMENT) ;
157-
156+
UNDOC_COMMENT : '////' ~[\r\n]* -> type(COMMENT) ;
157+
YESDOC_COMMENT : '///' ~[\r\n]* -> type(DOC_COMMENT) ;
158+
OUTER_DOC_COMMENT : '//!' ~[\r\n]* -> type(DOC_COMMENT) ;
159+
LINE_COMMENT : '//' ~[\r\n]* -> type(COMMENT) ;
158160

159161
DOC_BLOCK_COMMENT
160162
: ('/**' | '/*!') (DOC_BLOCK_COMMENT | .)*? '*/' -> type(DOC_COMMENT)
161163
;
162164

163165
BLOCK_COMMENT : '/*' (BLOCK_COMMENT | .)*? '*/' -> type(COMMENT) ;
164-
165-
mode LINE_COMMENT;
166-
167-
MAYBE_DOC_COMMENT
168-
: '/' -> more, pushMode(LINE_DOC_COMMENT)
169-
;
170-
171-
MAYBE_OUTER_DOC_COMMENT
172-
: '!' ~[\r\n]* -> type(LINE_DOC_COMMENT), popMode
173-
;
174-
175-
COMMENT : ~[\r\n]* -> popMode ;
176-
177-
mode LINE_DOC_COMMENT;
178-
179-
ACTUALLY_A_COMMENT : '/' ~[\r\n]* -> type(COMMENT), popMode ;
180-
REALLY_A_DOC_COMMENT : ~[\r\n]* -> type(DOC_COMMENT), popMode ;

branches/auto/src/grammar/verify.rs

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,10 @@ fn parse_token_list(file: &str) -> HashMap<String, Token> {
108108
res
109109
}
110110

111-
fn str_to_binop(mut s: &str) -> BinOp {
112-
if s.ends_with("'") {
113-
s = s.slice_to(s.len() - 1);
114-
}
115-
111+
fn str_to_binop(s: &str) -> BinOp {
116112
match s {
117113
"+" => PLUS,
114+
"/" => SLASH,
118115
"-" => MINUS,
119116
"*" => STAR,
120117
"%" => PERCENT,
@@ -123,12 +120,35 @@ fn str_to_binop(mut s: &str) -> BinOp {
123120
"|" => OR,
124121
"<<" => SHL,
125122
">>" => SHR,
126-
_ => fail!("Bad binop str {}", s)
123+
_ => fail!("Bad binop str `{}`", s)
124+
}
125+
}
126+
127+
/// Assuming a raw string/binary literal, strip out the leading/trailing
128+
/// hashes and surrounding quotes/raw/binary prefix.
129+
fn fix(mut lit: &str) -> ast::Name {
130+
if lit.char_at(0) == 'r' {
131+
if lit.char_at(1) == 'b' {
132+
lit = lit.slice_from(2)
133+
} else {
134+
lit = lit.slice_from(1);
135+
}
136+
} else if lit.char_at(0) == 'b' {
137+
lit = lit.slice_from(1);
127138
}
139+
140+
let leading_hashes = count(lit);
141+
142+
// +1/-1 to adjust for single quotes
143+
parse::token::intern(lit.slice(leading_hashes + 1, lit.len() - leading_hashes - 1))
144+
}
145+
146+
fn count(lit: &str) -> uint {
147+
lit.chars().take_while(|c| *c == '#').count()
128148
}
129149

130150
fn parse_antlr_token(s: &str, tokens: &HashMap<String, Token>) -> TokenAndSpan {
131-
let re = regex!(r"\[@(?P<seq>\d+),(?P<start>\d+):(?P<end>\d+)='(?P<content>.+?),<(?P<toknum>-?\d+)>,\d+:\d+]");
151+
let re = regex!(r"\[@(?P<seq>\d+),(?P<start>\d+):(?P<end>\d+)='(?P<content>.+?)',<(?P<toknum>-?\d+)>,\d+:\d+]");
132152

133153
let m = re.captures(s).expect(format!("The regex didn't match {}", s).as_slice());
134154
let start = m.name("start");
@@ -137,9 +157,24 @@ fn parse_antlr_token(s: &str, tokens: &HashMap<String, Token>) -> TokenAndSpan {
137157
let content = m.name("content");
138158

139159
let proto_tok = tokens.find_equiv(&toknum).expect(format!("didn't find token {} in the map", toknum).as_slice());
160+
161+
let nm = parse::token::intern(content);
162+
163+
debug!("What we got: content (`{}`), proto: {}", content, proto_tok);
164+
140165
let real_tok = match *proto_tok {
141-
BINOP(PLUS) => BINOP(str_to_binop(content)),
142-
BINOPEQ(PLUS) => BINOPEQ(str_to_binop(content.slice_to(content.len() - 2))),
166+
BINOP(..) => BINOP(str_to_binop(content)),
167+
BINOPEQ(..) => BINOPEQ(str_to_binop(content.slice_to(content.len() - 1))),
168+
LIT_STR(..) => LIT_STR(fix(content)),
169+
LIT_STR_RAW(..) => LIT_STR_RAW(fix(content), count(content)),
170+
LIT_CHAR(..) => LIT_CHAR(nm),
171+
DOC_COMMENT(..) => DOC_COMMENT(nm),
172+
LIT_INTEGER(..) => LIT_INTEGER(nm),
173+
LIT_FLOAT(..) => LIT_FLOAT(nm),
174+
LIT_BINARY(..) => LIT_BINARY(nm),
175+
LIT_BINARY_RAW(..) => LIT_BINARY_RAW(fix(content), count(content)),
176+
IDENT(..) => IDENT(ast::Ident { name: nm, ctxt: 0 }, true),
177+
LIFETIME(..) => LIFETIME(ast::Ident { name: nm, ctxt: 0 }),
143178
ref t => t.clone()
144179
};
145180

@@ -161,6 +196,16 @@ fn parse_antlr_token(s: &str, tokens: &HashMap<String, Token>) -> TokenAndSpan {
161196
}
162197
}
163198

199+
fn tok_cmp(a: &Token, b: &Token) -> bool {
200+
match a {
201+
&IDENT(id, _) => match b {
202+
&IDENT(id2, _) => id == id2,
203+
_ => false
204+
},
205+
_ => a == b
206+
}
207+
}
208+
164209
fn main() {
165210
fn next(r: &mut lexer::StringReader) -> TokenAndSpan {
166211
use syntax::parse::lexer::Reader;
@@ -173,7 +218,8 @@ fn main() {
173218

174219
let code = File::open(&Path::new(std::os::args().get(1).as_slice())).unwrap().read_to_string().unwrap();
175220
let options = config::basic_options();
176-
let session = session::build_session(options, None);
221+
let session = session::build_session(options, None,
222+
syntax::diagnostics::registry::Registry::new([]));
177223
let filemap = parse::string_to_filemap(&session.parse_sess,
178224
code,
179225
String::from_str("<n/a>"));
@@ -191,10 +237,16 @@ fn main() {
191237
( $($x:pat),+ ) => (
192238
match rustc_tok.tok {
193239
$($x => match antlr_tok.tok {
194-
$x => (),
240+
$x => {
241+
if !tok_cmp(&rustc_tok.tok, &antlr_tok.tok) {
242+
// FIXME #15677: needs more robust escaping in
243+
// antlr
244+
warn!("Different names for {} and {}", rustc_tok, antlr_tok);
245+
}
246+
}
195247
_ => fail!("{} is not {}", antlr_tok, rustc_tok)
196248
},)*
197-
ref c => assert!(c == antlr_tok.tok, "{} is not {}", rustc_tok, antlr_tok)
249+
ref c => assert!(c == &antlr_tok.tok, "{} is not {}", rustc_tok, antlr_tok)
198250
}
199251
)
200252
)

0 commit comments

Comments
 (0)