Skip to content

Commit c41a7df

Browse files
committed
Shuffle around check-lexer conditions
1 parent dd3afb4 commit c41a7df

File tree

5 files changed

+59
-29
lines changed

5 files changed

+59
-29
lines changed

Makefile.in

+1-13
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ ifneq ($(strip $(findstring check,$(MAKECMDGOALS)) \
216216
$(findstring tidy,$(MAKECMDGOALS))),)
217217
CFG_INFO := $(info cfg: including test rules)
218218
include $(CFG_SRC_DIR)mk/tests.mk
219+
include $(CFG_SRC_DIR)mk/grammar.mk
219220
endif
220221

221222
# Performance and benchmarking
@@ -252,19 +253,6 @@ ifneq ($(findstring clean,$(MAKECMDGOALS)),)
252253
include $(CFG_SRC_DIR)mk/clean.mk
253254
endif
254255

255-
# Grammar tests
256-
257-
ifneq ($(findstring lexer,$(MAKECMDGOALS)),)
258-
ifdef CFG_JAVAC
259-
ifdef CFG_ANTLR4
260-
ifdef CFG_GRUN
261-
CFG_INFO := $(info cfg: including grammar tests)
262-
include $(CFG_SRC_DIR)mk/grammar.mk
263-
endif
264-
endif
265-
endif
266-
endif
267-
268256
# CTAGS building
269257
ifneq ($(strip $(findstring TAGS.emacs,$(MAKECMDGOALS)) \
270258
$(findstring TAGS.vi,$(MAKECMDGOALS))),)

mk/grammar.mk

+14-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ $(BG)verify: $(SG)verify.rs rustc-stage2-H-$(CFG_BUILD) $(LD)stamp.regex_macros
3838
$(Q)$(RUSTC) -O --out-dir $(BG) -L $(L) $(SG)verify.rs
3939

4040
check-lexer: $(BG) $(BG)RustLexer.class $(BG)verify
41+
ifdef CFG_JAVAC
42+
ifdef CFG_ANTLR4
43+
ifdef CFG_GRUN
4144
$(info Verifying libsyntax against the reference lexer ...)
42-
$(Q)find $(S) -iname '*.rs' -exec "$(SG)check.sh" {} "$(BG)" \
43-
"$(CFG_GRUN)" "$(BG)verify" "$(BG)RustLexer.tokens" "$(VERBOSE)" \;
45+
$(Q)$(SG)check.sh $(S) "$(BG)" \
46+
"$(CFG_GRUN)" "$(BG)verify" "$(BG)RustLexer.tokens"
47+
else
48+
$(info grun not available, skipping lexer test...)
49+
endif
50+
else
51+
$(info antlr4 not available, skipping lexer test...)
52+
endif
53+
else
54+
$(info javac not available, skipping lexer test...)
55+
endif

mk/tests.mk

+3-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ endif
171171
# Main test targets
172172
######################################################################
173173

174-
check: cleantmptestlogs cleantestlibs check-notidy tidy
174+
check: cleantmptestlogs cleantestlibs check-notidy tidy check-syntax
175175

176176
check-notidy: cleantmptestlogs cleantestlibs all check-stage2
177177
$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
@@ -192,6 +192,8 @@ check-docs: cleantestlibs cleantmptestlogs check-stage2-docs
192192
# NOTE: Remove after reprogramming windows bots
193193
check-fast: check-lite
194194

195+
check-syntax: check-lexer
196+
195197
.PHONY: cleantmptestlogs cleantestlibs
196198

197199
cleantmptestlogs:

src/grammar/check.sh

+22-9
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,33 @@
22

33
# Run the reference lexer against libsyntax and compare the tokens and spans.
44
# If "// ignore-lexer-test" is present in the file, it will be ignored.
5-
#
5+
6+
67
# Argument $1 is the file to check, $2 is the classpath to use, $3 is the path
78
# to the grun binary, $4 is the path to the verify binary, $5 is the path to
89
# RustLexer.tokens
9-
1010
if [ "${VERBOSE}" == "1" ]; then
1111
set -x
1212
fi
1313

14-
grep -q "// ignore lexer-test" $1;
14+
check() {
15+
grep --silent "// ignore-lexer-test" $1;
1516

16-
if [ $? -eq 1 ]; then
17-
cd $2 # This `cd` is so java will pick up RustLexer.class. I couldn't
18-
# figure out how to wrangle the CLASSPATH, just adding build/grammr didn't
19-
# seem to have anny effect.
20-
$3 RustLexer tokens -tokens < $1 | $4 $1 $5
21-
fi
17+
# if it's *not* found...
18+
if [ $? -eq 1 ]; then
19+
cd $2 # This `cd` is so java will pick up RustLexer.class. I couldn't
20+
# figure out how to wrangle the CLASSPATH, just adding build/grammr didn't
21+
# seem to have anny effect.
22+
if $3 RustLexer tokens -tokens < $1 | $4 $1 $5; then
23+
echo "pass: $1"
24+
else
25+
echo "fail: $1"
26+
fi
27+
else
28+
echo "skip: $1"
29+
fi
30+
}
31+
32+
for file in $(find $1 -iname '*.rs' ! -path '*/test/compile-fail/*' ); do
33+
check $file $2 $3 $4 $5
34+
done

src/grammar/verify.rs

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
111
#![feature(globs, phase, macro_rules)]
212

313
extern crate syntax;
@@ -158,15 +168,18 @@ fn count(lit: &str) -> uint {
158168
}
159169

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

163175
let m = re.captures(s).expect(format!("The regex didn't match {}", s).as_slice());
164176
let start = m.name("start");
165177
let end = m.name("end");
166178
let toknum = m.name("toknum");
167179
let content = m.name("content");
168180

169-
let proto_tok = tokens.find_equiv(&toknum).expect(format!("didn't find token {} in the map", toknum).as_slice());
181+
let proto_tok = tokens.find_equiv(&toknum).expect(format!("didn't find token {} in the map",
182+
toknum).as_slice());
170183

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

@@ -229,7 +242,8 @@ fn main() {
229242
let token_map = parse_token_list(token_file.read_to_string().unwrap().as_slice());
230243

231244
let mut stdin = std::io::stdin();
232-
let mut antlr_tokens = stdin.lines().map(|l| parse_antlr_token(l.unwrap().as_slice().trim(), &token_map));
245+
let mut antlr_tokens = stdin.lines().map(|l| parse_antlr_token(l.unwrap().as_slice().trim(),
246+
&token_map));
233247

234248
let code = File::open(&Path::new(args.get(1).as_slice())).unwrap().read_to_string().unwrap();
235249
let options = config::basic_options();
@@ -246,7 +260,8 @@ fn main() {
246260
continue
247261
}
248262

249-
assert!(rustc_tok.sp == antlr_tok.sp, "{} and {} have different spans", rustc_tok, antlr_tok);
263+
assert!(rustc_tok.sp == antlr_tok.sp, "{} and {} have different spans", rustc_tok,
264+
antlr_tok);
250265

251266
macro_rules! matches (
252267
( $($x:pat),+ ) => (

0 commit comments

Comments
 (0)