[PATCH] D41732: [Option] Add 'findNearest' method to catch typos
Brian Gesiak via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 4 10:07:02 PST 2018
modocache created this revision.
modocache added reviewers: yamaguchi, v.g.vassilev, teemperor, ruiu.
Add a method `OptTable::findNearest`, which allows users of OptTable to
check user input for misspelled options. In addition, have llvm-mt
check for misspelled options. For example, if a user invokes
`llvm-mt /oyt:foo`, the error message will indicate that while an
option named `/oyt:` does not exist, `/out:` does.
The method ports the functionality of the `LookupNearestOption` method
from LLVM CommandLine to libLLVMOption. This allows tools like Clang
and Swift, which do not use CommandLine, to use this functionality to
suggest similarly spelled options.
As room for future improvement, the new method as-is cannot yet properly suggest
nearby "joined" options -- that is, for an option string "-FozBar", where
"-Foo" is the correct option name and "Bar" is the value being passed along
with the misspelled option, this method will calculate an edit distance of 3,
by deleting "Bar" and changing "z" to "o". It should instead calculate an edit
distance of just 1, by changing "z" to "o" and recognizing "Bar" as a
value. This commit includes a disabled test that expresses this limitation.
Test Plan: `check-llvm`
https://reviews.llvm.org/D41732
Files:
include/llvm/Option/OptTable.h
lib/Option/OptTable.cpp
test/tools/llvm-mt/help.test
tools/llvm-mt/llvm-mt.cpp
unittests/Option/OptionParsingTest.cpp
unittests/Option/Opts.td
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41732.128627.patch
Type: text/x-patch
Size: 9031 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180104/d2314c76/attachment.bin>
More information about the llvm-commits
mailing list