Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix grammar verifcation #34994

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion mk/clean.mk
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ clean-all: clean clean-llvm

clean-llvm: $(CLEAN_LLVM_RULES)

clean: clean-misc $(CLEAN_STAGE_RULES)
clean: clean-misc clean-grammar $(CLEAN_STAGE_RULES)

clean-misc:
@$(call E, cleaning)
Expand All @@ -47,6 +47,9 @@ clean-misc:
$(Q)rm -Rf dist/*
$(Q)rm -Rf doc

clean-grammar:
@$(call E, cleaning grammar verification)
$(Q)rm -Rf grammar
define CLEAN_GENERIC

clean-generic-$(2)-$(1):
Expand Down
2 changes: 1 addition & 1 deletion mk/grammar.mk
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ $(BG):

$(BG)RustLexer.class: $(BG) $(SG)RustLexer.g4
$(Q)$(CFG_ANTLR4) -o $(BG) $(SG)RustLexer.g4
$(Q)$(CFG_JAVAC) -d $(BG) $(BG)RustLexer.java
$(Q)$(CFG_JAVAC) -d $(BG) -classpath /usr/share/java/antlr-complete.jar $(BG)RustLexer.java
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, is this always going to be where this is? Feels system-specific

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the place in Arch Linux, but not on Mac OS X. I have not tested other distros.


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

Expand Down
3 changes: 2 additions & 1 deletion mk/tests.mk
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ cleantestlibs:

.PHONY: tidy
tidy: $(HBIN0_H_$(CFG_BUILD))/tidy$(X_$(CFG_BUILD)) \
$(SNAPSHOT_RUSTC_POST_CLEANUP)
$(SNAPSHOT_RUSTC_POST_CLEANUP) \
check-build-lexer-verifier
$(TARGET_RPATH_VAR0_T_$(CFG_BUILD)_H_$(CFG_BUILD)) $< $(S)src

$(HBIN0_H_$(CFG_BUILD))/tidy$(X_$(CFG_BUILD)): \
Expand Down
17 changes: 14 additions & 3 deletions src/grammar/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
Reference grammar.
# Reference grammar.

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

To use manually:
# Manual build

To use manually, assuming antlr4 ist installed at `/usr/share/java/antlr-complete.jar`:

```
antlr4 RustLexer.g4
javac *.java
javac -classpath /usr/share/java/antlr-complete.jar *.java
rustc -O verify.rs
for file in ../*/**.rs; do
echo $file;
Expand All @@ -18,3 +20,12 @@ done

Note That the `../*/**.rs` glob will match every `*.rs` file in the above
directory and all of its recursive children. This is a zsh extension.


## Cleanup

To cleanup you can use a command like this:

```bash
rm -f verify *.class *.java *.tokens
```
6 changes: 3 additions & 3 deletions src/grammar/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ skipped=0
check() {
grep --silent "// ignore-lexer-test" "$1";

# if it's *not* found...
# if it is *not* found...
if [ $? -eq 1 ]; then
cd $2 # This `cd` is so java will pick up RustLexer.class. I couldn't
cd $2 # This `cd` is so java will pick up RustLexer.class. I could not
# figure out how to wrangle the CLASSPATH, just adding build/grammar
# didn't seem to have any effect.
# did not seem to have any effect.
if $3 RustLexer tokens -tokens < $1 | $4 $1 $5; then
echo "pass: $1"
passed=`expr $passed + 1`
Expand Down
6 changes: 4 additions & 2 deletions src/grammar/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#![feature(plugin, rustc_private)]

extern crate syntax;
extern crate syntax_pos;
extern crate rustc;

#[macro_use]
Expand Down Expand Up @@ -290,9 +291,10 @@ fn main() {

let options = config::basic_options();
let session = session::build_session(options, &DepGraph::new(false), None,
syntax::diagnostics::registry::Registry::new(&[]),
syntax::errors::registry::Registry::new(&[]),
Rc::new(DummyCrateStore));
let filemap = session.parse_sess.codemap().new_filemap(String::from("<n/a>"), code);
let filemap = session.parse_sess.codemap()
.new_filemap("<n/a>".to_string(), None, code);
let mut lexer = lexer::StringReader::new(session.diagnostic(), filemap);
let cm = session.codemap();

Expand Down