Merge remote-tracking branch 'origin/pr/338' into spell

This commit is contained in:
Carol (Nichols || Goulding) 2016-12-11 11:54:44 -05:00
commit d5aa0440f7
14 changed files with 324 additions and 12 deletions

View File

@ -8,6 +8,7 @@ rust:
before_script:
- (cargo install mdbook --git https://github.com/azerupi/mdBook.git --force || true)
script:
- bash spellcheck.sh list
- PATH=$PATH:/home/travis/.cargo/bin mdbook test
- PATH=$PATH:/home/travis/.cargo/bin mdbook build
- cargo run --bin lfp src

View File

@ -92,6 +92,14 @@ In the generated SVG, remove the width and the height attributes from the `svg`
element and set the `viewBox` attribute to `0.00 0.00 1000.00 1000.00` or other
values that don't cut off the image.
## Spellchecking
To scan source file for spell errors, you can use `spellcheck.sh` script. It
needs a dictionary of valid words, which is provided in `dictionary.txt`. If
script produces a false positive (say, you used word `BTreeMap` which script
considers invalid) you need to add this word to dictionary file (in any place
in the file, but you can keep sorted order for consistency).
## Converting Windows newlines to Unix
This is mostly for Carol's reference because she keeps having to look it up.

225
dictionary.txt Normal file
View File

@ -0,0 +1,225 @@
personal_ws-1.1 en 0 utf-8
abcabcabc
abcd
Addr
adeb
aliasability
alignof
Amir
APIs
aren
backtrace
BACKTRACE
benchmarking
bitand
BitAnd
bitor
BitOr
bitwise
Bitwise
bitxor
BitXor
Boehm
bool
boolean
booleans
Bors
BuildHasher
Cagain
callsite
CamelCase
ChangeColor
ChangeColorMessage
chXX
chYY
config
Config
const
copyeditor
couldn
cratesio
cryptographically
CStr
CString
ctrl
Ctrl
deallocated
debuginfo
deps
deref
Deref
dereference
Dereference
dereferencing
DerefMut
destructure
destructuring
Destructuring
didn
Dobrý
doccargo
doccratesio
doesn
Edsger
else's
encodings
enum
Enum
enums
enum's
Enums
ErrorKind
Executables
extern
FFFF
figcaption
filename
Filename
filesystem
Filesystem
formatter
gitignore
grapheme
Grapheme
growable
hardcoded
hardcoding
hasher
hashmap
HashMap
Hashmaps
Haskell
hasn
helloworld
Hmmm
Hoare
Hola
homogenous
html
impl
init
instantiation
InvalidDigit
ioerror
iokind
ioresult
iostdin
IpAddr
IpAddrKind
irst
isize
iter
judgement
lang
latin
libc
libcore
libreoffice
lifecycle
loopback
lval
mathematic
metaprogramming
mibbit
Mibbit
mkdir
modifiability
monomorphization
Monomorphization
monomorphized
MoveMessage
Mutex
namespace
namespaced
namespaces
nocapture
nomicon
Nomicon
NotFound
null's
OCaml
offsetof
OptionalFloatingPointNumber
OptionalNumber
OsStr
OsString
overread
parameterize
ParseIntError
PartialEq
PartialOrd
powi
preprocessing
Preprocessing
preprocessor
println
priv
proc
pthreads
QuitMessage
RAII
randcrate
READMEs
rect
Rectange
redeclaring
RefCell
repr
runtime
Rustacean
Rustaceans
rustc
rustdoc
rustup
semver
SemVer
shouldn
sizeof
someproject
someusername
SpreadsheetCell
sqrt
stackoverflow
stdin
Stdin
stdlib
stdout
steveklabnik's
struct
Struct
structs
struct's
Structs
subdirectories
subdirectory
submodule
submodules
Submodules
suboptimal
subtree
That'd
TODO
toml
TOML
tradeoff
TrafficLight
trpl
typeof
UFCS
unary
Unary
unoptimized
unsized
unsynchronized
USERPROFILE
usize
UsState
Versioning
wasn
whitespace
workspace
workspaces
Workspaces
wouldn
WriteMessage
yyyy

View File

@ -205,7 +205,7 @@ We've been showing a bunch of different possibilities that we could define in
our code for storing IP addresses of the two different kinds using an enum. It
turns out, though, that wanting to store IP addresses and encode which kind
they are is so common that the standard library has a definition we can use!
Let's look at how the standard libary defines `IpAddr`: it has the exact enum
Let's look at how the standard library defines `IpAddr`: it has the exact enum
and variants that we've defined and used, but it chose to embed the address
data inside the variants in the form of two different structs, which are
defined differently for each variant:

View File

@ -708,7 +708,7 @@ Overall, these are the rules for item visibility:
### Privacy Examples
Lets look at a few more examples to get some practice. Create a new libary
Lets look at a few more examples to get some practice. Create a new library
project and enter the code in Listing 7-5 into your new projects `src/lib.rs`:
Filename: src/lib.rs

78
spellcheck.sh Executable file
View File

@ -0,0 +1,78 @@
#!/bin/bash
# Checks project markdown files for spell errors
# Notes:
# This script needs dictionary file ($dict_filename) with project-specific
# valid words. If this file is missing, first invocation of a script generates
# a file of words considered typos at the moment. User should remove real typos
# from this file and leave only valid words. When script generates false
# positive after source modification, new valid word should be added
# to dictionary file.
# Default mode of this script is interactive. Each source file is scanned for
# typos. aspell opens window, suggesting fixes for each found typo. Original
# files with errors will be backed up to files with format "filename.md.bak".
# When running in CI, this script should be run in "list" mode (pass "list"
# as first argument). In this mode script scans all files and reports found
# errors. Exit code in this case depends on scan result:
# 1 if any errors found,
# 0 if all is clear.
# Script skips words with length less then or equal to 3. This helps to avoid
# some false positives.
# We can consider skipping source code in markdown files (```code```) to reduce
# rate of false positives, but then we lose ability to detect typos in code
# comments/strings etc.
shopt -s nullglob
dict_filename=dictionary.txt
markdown_sources=(./src/*.md)
mode="check"
# aspell repeatedly modifies personal dictionary for some purpose,
# so we should use a copy of our dictionary
dict_path="/tmp/$dict_filename"
if [[ "$1" == "list" ]]; then
mode="list"
fi
if [[ ! -f "$dict_filename" ]]; then
# Pre-check mode: generates dictionary of words aspell consider typos.
# After user validates that this file contains only valid words, we can
# look for typos using this dictionary and some default aspell dictionary.
echo "Scanning files to generate dictionary file '$dict_filename'."
echo "Please check it doesn't contain any spellings for correct results."
echo "personal_ws-1.1 en 0 utf-8" > "$dict_filename"
cat "${markdown_sources[@]}" | aspell --ignore 3 list | sort -u >> "$dict_filename"
elif [[ "$mode" == "list" ]]; then
# List (default) mode: scan all files, report errors
cp "$dict_filename" "$dict_path"
declare -i retval=0
for fname in "${markdown_sources[@]}"; do
command=$(aspell --ignore 3 --personal="$dict_path" "$mode" < "$fname")
if [[ -n "$command" ]]; then
for error in $command; do
# TODO: Find more correct way to get line number
# (ideally from aspell). Now it can make some false positives,
# because it is just a grep
grep --with-filename --line-number --color=always "$error" "$fname"
done
retval=1
fi
done
exit "$retval"
elif [[ "$mode" == "check" ]]; then
# Interactive mode: fix typos
cp "$dict_filename" "$dict_path"
for fname in "${markdown_sources[@]}"; do
aspell --ignore 3 --personal="$dict_path" "$mode" "$fname"
done
fi

View File

@ -224,7 +224,7 @@ We've been showing a bunch of different possibilities that we could define in
our code for storing IP addresses of the two different kinds using an enum. It
turns out, though, that wanting to store IP addresses and encode which kind
they are is so common that [the standard library has a definition we can
use!][IpAddr]<!-- ignore --> Let's look at how the standard libary defines
use!][IpAddr]<!-- ignore --> Let's look at how the standard library defines
`IpAddr`: it has the exact enum and variants that we've defined and used, but
it chose to embed the address data inside the variants in the form of two
different structs, which are defined differently for each variant:

View File

@ -215,7 +215,7 @@ Overall, these are the rules for item visibility:
### Privacy Examples
Lets look at a few more examples to get some practice. Create a new libary
Lets look at a few more examples to get some practice. Create a new library
project and enter the code in Listing 7-5 into your new projects *src/lib.rs*:
<figure>

View File

@ -219,7 +219,7 @@ don't think we should repeat it here as well, but we added a reference. /Carol
If you don't know at the time that you're writing a program the exhaustive set
of types the program will get at runtime to store in a vector, the enum
technique won't work. Insetad, you can use a trait object, which we'll cover in
technique won't work. Instead, you can use a trait object, which we'll cover in
Chapter 13.
Now that we've gone over some of the most common ways to use vectors, be sure
@ -233,7 +233,7 @@ in the book for space reasons? We might want to justify sending them out of the
book if we don't want to cover it here -->
<!-- Yes, there are many, many methods on Vec: https://doc.rust-lang.org/stable/std/vec/struct.Vec.html
Also there are occcasionally new methods available with new versions of the
Also there are occasionally new methods available with new versions of the
language, so there's no way we can be comprehensive here. We want the reader to
use the API documentation in these situations since the purpose of the online
docs is to be comprehensive and up to date. I personally wouldn't expect a book

View File

@ -95,7 +95,7 @@ in this short program where the error was, it would be nicer if we could have
Rust tell us what line in our program caused the error.
That's what the next line, the `note` is about. If we set the `RUST_BACKTRACE`
environment variable, we'll get a backtrace of exactly how the error happend.
environment variable, we'll get a backtrace of exactly how the error happened.
Let's try that. Listing 9-1 shows the output:
<figure>

View File

@ -2,7 +2,7 @@
One of the core tools a programming language gives you is the ability to deal
effectively with duplication of code. It's important to minimize the amount of
code that is duplicated throughout a program to make maintenace easier and
code that is duplicated throughout a program to make maintenance easier and
minimize logic errors. Maintenance will be easier if there's only one place
that you need to change the code if you change your mind about how the program
should work, rather than multiple places in the code. If your program's logic

View File

@ -36,7 +36,7 @@ We declare a trait with the `trait` keyword, then the trait's name. In this
case, our trait will describe types which can be printed. Inside of curly
braces, we declare a method signature, but instead of providing an
implementation inside curly braces, we put a semicolon after the signature. A
trait can have multiple methods in its body, with the method signatures listend one per line and each line ending in a semicolon.
trait can have multiple methods in its body, with the method signatures listened one per line and each line ending in a semicolon.
Implementing a trait for a particular type looks similar to implementing
methods on a type since it's also done with the `impl` keyword, but we specify

View File

@ -186,7 +186,7 @@ if left_val == right_val {
}
```
Let's take a look at a test that will fail becasue `hello` is not equal to
Let's take a look at a test that will fail because `hello` is not equal to
`world`. We've also added a custom error message, `greeting operation failed`:
<span class="filename">Filename: src/lib.rs</span>

View File

@ -17,8 +17,8 @@ modifiability. And indeed, it says
> Indeed, under the implementation strategy we outlined above, in which the
> compiler is unaware of threads, it is allowed to transform code subject only
> to sequential cor- rectness constraints and hence could generate the code
> con- taining a race.
> to sequential correctness constraints and hence could generate the code
> containing a race.
However, in Rust, this re-ordering can't happen: Rust won't let you alias x and
y between two threads without some sort of synchronization primitive. But this