diff options
| author | Corey Richardson <corey@octayn.net> | 2014-07-21 13:04:35 -0700 |
|---|---|---|
| committer | Corey Richardson <corey@octayn.net> | 2014-07-21 18:38:40 -0700 |
| commit | c41a7dfcc7b1c71305bd1816bb2e6aff7abddbb2 (patch) | |
| tree | 7b5e7dad1eee54ccf0b1e36995428d51c95062ce /src | |
| parent | dd3afb42d1cc5eb11f2e024167aca0a6d6173b98 (diff) | |
| download | rust-c41a7dfcc7b1c71305bd1816bb2e6aff7abddbb2.tar.gz rust-c41a7dfcc7b1c71305bd1816bb2e6aff7abddbb2.zip | |
Shuffle around check-lexer conditions
Diffstat (limited to 'src')
| -rwxr-xr-x | src/grammar/check.sh | 31 | ||||
| -rw-r--r-- | src/grammar/verify.rs | 23 |
2 files changed, 41 insertions, 13 deletions
diff --git a/src/grammar/check.sh b/src/grammar/check.sh index 3ddbb8a34c8..69ec490a08a 100755 --- a/src/grammar/check.sh +++ b/src/grammar/check.sh @@ -2,20 +2,33 @@ # Run the reference lexer against libsyntax and compare the tokens and spans. # If "// ignore-lexer-test" is present in the file, it will be ignored. -# + + # Argument $1 is the file to check, $2 is the classpath to use, $3 is the path # to the grun binary, $4 is the path to the verify binary, $5 is the path to # RustLexer.tokens - if [ "${VERBOSE}" == "1" ]; then set -x fi -grep -q "// ignore lexer-test" $1; +check() { + grep --silent "// ignore-lexer-test" $1; -if [ $? -eq 1 ]; then - cd $2 # This `cd` is so java will pick up RustLexer.class. I couldn't - # figure out how to wrangle the CLASSPATH, just adding build/grammr didn't - # seem to have anny effect. - $3 RustLexer tokens -tokens < $1 | $4 $1 $5 -fi + # if it's *not* found... + if [ $? -eq 1 ]; then + cd $2 # This `cd` is so java will pick up RustLexer.class. I couldn't + # figure out how to wrangle the CLASSPATH, just adding build/grammr didn't + # seem to have anny effect. + if $3 RustLexer tokens -tokens < $1 | $4 $1 $5; then + echo "pass: $1" + else + echo "fail: $1" + fi + else + echo "skip: $1" + fi +} + +for file in $(find $1 -iname '*.rs' ! -path '*/test/compile-fail/*' ); do + check $file $2 $3 $4 $5 +done diff --git a/src/grammar/verify.rs b/src/grammar/verify.rs index a6a1a75854d..f2ae5a1ea4e 100644 --- a/src/grammar/verify.rs +++ b/src/grammar/verify.rs @@ -1,3 +1,13 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + #![feature(globs, phase, macro_rules)] extern crate syntax; @@ -158,7 +168,9 @@ fn count(lit: &str) -> uint { } fn parse_antlr_token(s: &str, tokens: &HashMap<String, Token>) -> TokenAndSpan { - let re = regex!(r"\[@(?P<seq>\d+),(?P<start>\d+):(?P<end>\d+)='(?P<content>.+?)',<(?P<toknum>-?\d+)>,\d+:\d+]"); + let re = regex!( + r"\[@(?P<seq>\d+),(?P<start>\d+):(?P<end>\d+)='(?P<content>.+?)',<(?P<toknum>-?\d+)>,\d+:\d+]" + ); let m = re.captures(s).expect(format!("The regex didn't match {}", s).as_slice()); let start = m.name("start"); @@ -166,7 +178,8 @@ fn parse_antlr_token(s: &str, tokens: &HashMap<String, Token>) -> TokenAndSpan { let toknum = m.name("toknum"); let content = m.name("content"); - let proto_tok = tokens.find_equiv(&toknum).expect(format!("didn't find token {} in the map", toknum).as_slice()); + let proto_tok = tokens.find_equiv(&toknum).expect(format!("didn't find token {} in the map", + toknum).as_slice()); let nm = parse::token::intern(content); @@ -229,7 +242,8 @@ fn main() { let token_map = parse_token_list(token_file.read_to_string().unwrap().as_slice()); let mut stdin = std::io::stdin(); - let mut antlr_tokens = stdin.lines().map(|l| parse_antlr_token(l.unwrap().as_slice().trim(), &token_map)); + let mut antlr_tokens = stdin.lines().map(|l| parse_antlr_token(l.unwrap().as_slice().trim(), + &token_map)); let code = File::open(&Path::new(args.get(1).as_slice())).unwrap().read_to_string().unwrap(); let options = config::basic_options(); @@ -246,7 +260,8 @@ fn main() { continue } - assert!(rustc_tok.sp == antlr_tok.sp, "{} and {} have different spans", rustc_tok, antlr_tok); + assert!(rustc_tok.sp == antlr_tok.sp, "{} and {} have different spans", rustc_tok, + antlr_tok); macro_rules! matches ( ( $($x:pat),+ ) => ( |
