Skip to content

Commit 7ce7dd1

Browse files
committed
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
1 parent 7bf54f9 commit 7ce7dd1

File tree

6 files changed

+28
-11
lines changed

6 files changed

+28
-11
lines changed

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 /usr/share/java/antlr-complete.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

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
Reference grammar.
1+
# Reference grammar.
22

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

7-
To use manually:
7+
# Manual build
8+
9+
To use manually, assuming antlr4 ist installed at `/usr/share/java/antlr-complete.jar`:
810

911
```
1012
antlr4 RustLexer.g4
11-
javac *.java
13+
javac -classpath /usr/share/java/antlr-complete.jar *.java
1214
rustc -O verify.rs
1315
for file in ../*/**.rs; do
1416
echo $file;
@@ -18,3 +20,12 @@ done
1820

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

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)