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 verification #37607

Merged
merged 1 commit into from
Nov 17, 2016
Merged
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
6 changes: 6 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,12 @@ probe_need CFG_CMAKE cmake
# probe for it only in this case.
if [ -n "$CFG_ANTLR4" ]
then
CFG_ANTLR4_JAR="\"$(find /usr/ -name antlr-complete.jar 2>/dev/null | head -n 1)\""
if [ "x" -eq "x$CFG_ANTLR4_JAR" ]
then
CFG_ANTLR4_JAR="\"$(find ~ -name antlr-complete.jar 2>/dev/null | head -n 1)\""
fi
putvar CFG_ANTLR4_JAR $CFG_ANTLR4_JAR
probe CFG_JAVAC javac
fi

Expand Down
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 $(CFG_ANTLR4_JAR) $(BG)RustLexer.java

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
21 changes: 17 additions & 4 deletions src/grammar/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
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
ASTs/token streams generated. You can use the `make check-lexer` target to
run all of the available tests.

To use manually:
The build of the rust part is included with `make tidy` and can be run with `make check-build-lexer-verifier`.

# 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 +22,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...
Copy link
Member

Choose a reason for hiding this comment

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

Not sure to see the usefulness of this change...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well I read it and I thought I change it. Is it wrong?

Copy link
Member

Choose a reason for hiding this comment

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

Well it's not wrong, but "it's is just as good as "it is" so why changing it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I learned it that way in school, an old habit.

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
Copy link
Member

Choose a reason for hiding this comment

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

Same.

# 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.
Copy link
Member

Choose a reason for hiding this comment

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

Same.

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