1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
#
# Spell check a LaTeX file
#
open build/Common
open parse/LaTeX/Parse
private.tab = $" "
#
# Read a file of words
#
Dict. =
extends $(Map)
misspelled = $(Map)
add-misspelled(word, loc) =
if $(not $(misspelled.mem $(word)))
misspelled = $(misspelled.add $(word), $(loc))
export
return $(this)
check(word, loc) =
if $(not $(this.mem $(word)))
lword = $(uncapitalize $(word))
if $(not $(this.mem $(lword)))
add-misspelled($(word), $(loc))
else
value $(this)
else
value $(this)
print-misspelled() =
has-misspelled = $(gt $(misspelled.length), 0)
if $(has-misspelled)
eprintln($"The following words are misspelled:")
misspelled.map(word, loc) =>
eprintln($(tab)$(word) : $(loc.to-string))
value $(has-misspelled)
private.load-files(words, filenames) =
foreach(filename => ..., $(filenames))
export
if $(file-exists $(filename))
print($"--- Loading dictionary $(filename)... ")
inx = $(fopen $(filename), r)
while true
try
word = $(input-line $(inx))
words = $(words.add $(word), true)
default
break()
close($(inx))
println($"(done)")
value $(words)
#
# Load the dictionaries
#
private.HOME = $(getenv HOME, /)
private.FILES[] =
/usr/dict/words
/usr/share/dict/words
/opt/share/dict/words
$(HOME)/.words
$(ROOT)/.words
.STATIC: :exists: $(FILES)
WORDS = $(load-files $(Dict), $(FILES))
#
# Spell checker
#
load-dictionaries() =
WORDS.mem(_)
WORDS = $(load-files $(WORDS), $(ROOT)/.spelling)
export
Shell. +=
spell(argv) =
foreach(filename => ..., $(argv))
prog = $(parse-tex-file $(filename))
words = $(prog.spell-check $(WORDS))
if $(words.print-misspelled)
exit(1)
|