Skip to content

Commit 6cd5be8

Browse files
authored
Auto merge of #37607 - dns2utf8:doc_grammar, r=alexcrichton
Fix grammar verification * Use make check-lexer to verify the grammar. * Extend grammar/README * Add make clean-grammar rule * Add target check-build-lexer-verifier to make tidy, so it will build the verifier with every build and catch future errors This is the continuation of #34994 r? @steveklabnik @jonathandturner @alexcrichton
2 parents f22fdb0 + 0e1828a commit 6cd5be8

File tree

7 files changed

+37
-12
lines changed

7 files changed

+37
-12
lines changed

configure

+6
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,12 @@ probe_need CFG_CMAKE cmake
854854
# probe for it only in this case.
855855
if [ -n "$CFG_ANTLR4" ]
856856
then
857+
CFG_ANTLR4_JAR="\"$(find /usr/ -name antlr-complete.jar 2>/dev/null | head -n 1)\""
858+
if [ "x" -eq "x$CFG_ANTLR4_JAR" ]
859+
then
860+
CFG_ANTLR4_JAR="\"$(find ~ -name antlr-complete.jar 2>/dev/null | head -n 1)\""
861+
fi
862+
putvar CFG_ANTLR4_JAR $CFG_ANTLR4_JAR
857863
probe CFG_JAVAC javac
858864
fi
859865

mk/clean.mk

+4-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ clean-all: clean clean-llvm
3535

3636
clean-llvm: $(CLEAN_LLVM_RULES)
3737

38-
clean: clean-misc $(CLEAN_STAGE_RULES)
38+
clean: clean-misc clean-grammar $(CLEAN_STAGE_RULES)
3939

4040
clean-misc:
4141
@$(call E, cleaning)
@@ -47,6 +47,9 @@ clean-misc:
4747
$(Q)rm -Rf dist/*
4848
$(Q)rm -Rf doc
4949

50+
clean-grammar:
51+
@$(call E, cleaning grammar verification)
52+
$(Q)rm -Rf grammar
5053
define CLEAN_GENERIC
5154

5255
clean-generic-$(2)-$(1):

mk/grammar.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ $(BG):
3737

3838
$(BG)RustLexer.class: $(BG) $(SG)RustLexer.g4
3939
$(Q)$(CFG_ANTLR4) -o $(BG) $(SG)RustLexer.g4
40-
$(Q)$(CFG_JAVAC) -d $(BG) $(BG)RustLexer.java
40+
$(Q)$(CFG_JAVAC) -d $(BG) -classpath $(CFG_ANTLR4_JAR) $(BG)RustLexer.java
4141

4242
check-build-lexer-verifier: $(BG)verify
4343

mk/tests.mk

+2-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ cleantestlibs:
243243

244244
.PHONY: tidy
245245
tidy: $(HBIN0_H_$(CFG_BUILD))/tidy$(X_$(CFG_BUILD)) \
246-
$(SNAPSHOT_RUSTC_POST_CLEANUP)
246+
$(SNAPSHOT_RUSTC_POST_CLEANUP) \
247+
check-build-lexer-verifier
247248
$(TARGET_RPATH_VAR0_T_$(CFG_BUILD)_H_$(CFG_BUILD)) $< $(S)src
248249

249250
$(HBIN0_H_$(CFG_BUILD))/tidy$(X_$(CFG_BUILD)): \

src/grammar/README.md

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
Reference grammar.
1+
# Reference grammar.
22

33
Uses [antlr4](http://www.antlr.org/) and a custom Rust tool to compare
4-
ASTs/token streams generated. You can use the `check-lexer` make target to
4+
ASTs/token streams generated. You can use the `make check-lexer` target to
55
run all of the available tests.
66

7-
To use manually:
7+
The build of the rust part is included with `make tidy` and can be run with `make check-build-lexer-verifier`.
8+
9+
# Manual build
10+
11+
To use manually, assuming antlr4 ist installed at `/usr/share/java/antlr-complete.jar`:
812

913
```
1014
antlr4 RustLexer.g4
11-
javac *.java
15+
javac -classpath /usr/share/java/antlr-complete.jar *.java
1216
rustc -O verify.rs
1317
for file in ../*/**.rs; do
1418
echo $file;
@@ -18,3 +22,12 @@ done
1822

1923
Note That the `../*/**.rs` glob will match every `*.rs` file in the above
2024
directory and all of its recursive children. This is a zsh extension.
25+
26+
27+
## Cleanup
28+
29+
To cleanup you can use a command like this:
30+
31+
```bash
32+
rm -f verify *.class *.java *.tokens
33+
```

src/grammar/check.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ skipped=0
2020
check() {
2121
grep --silent "// ignore-lexer-test" "$1";
2222

23-
# if it's *not* found...
23+
# if it is *not* found...
2424
if [ $? -eq 1 ]; then
25-
cd $2 # This `cd` is so java will pick up RustLexer.class. I couldn't
25+
cd $2 # This `cd` is so java will pick up RustLexer.class. I could not
2626
# figure out how to wrangle the CLASSPATH, just adding build/grammar
27-
# didn't seem to have any effect.
27+
# did not seem to have any effect.
2828
if $3 RustLexer tokens -tokens < $1 | $4 $1 $5; then
2929
echo "pass: $1"
3030
passed=`expr $passed + 1`

src/grammar/verify.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#![feature(plugin, rustc_private)]
1212

1313
extern crate syntax;
14+
extern crate syntax_pos;
1415
extern crate rustc;
1516

1617
#[macro_use]
@@ -290,9 +291,10 @@ fn main() {
290291

291292
let options = config::basic_options();
292293
let session = session::build_session(options, &DepGraph::new(false), None,
293-
syntax::diagnostics::registry::Registry::new(&[]),
294+
syntax::errors::registry::Registry::new(&[]),
294295
Rc::new(DummyCrateStore));
295-
let filemap = session.parse_sess.codemap().new_filemap(String::from("<n/a>"), code);
296+
let filemap = session.parse_sess.codemap()
297+
.new_filemap("<n/a>".to_string(), None, code);
296298
let mut lexer = lexer::StringReader::new(session.diagnostic(), filemap);
297299
let cm = session.codemap();
298300

0 commit comments

Comments
 (0)