I'm building a brainfuck compiler.
(我正在构建一个令人难以置信的编译器。)
The executable accepts two commands $ brainfuck compile ...
and $ brainfuck run
. (该可执行文件接受两个命令$ brainfuck compile ...
和$ brainfuck run
。)
I want the executable to auto complete when pressing tab. (我希望可执行文件在按Tab键时自动完成。)
Eg writing $ brainfuck com
and then pressing tab should generate $ brainfuck compile
. (例如,编写$ brainfuck com
,然后按Tab键将生成$ brainfuck compile
。)
data Command = Compile CompileArgs | Run RunArgs
deriving (Show)
main :: IO ()
main = execute =<< execParser opts
where
opts = info (helper <*> argsParser) fullDesc
execute :: Command -> IO ()
execute (Compile args) = compile args
execute (Run args) = run args
argsParser :: Parser Command
argsParser = subparser (compileCommand <> runCommand)
where
compileCommand = command "compile" $ info compileOptions $ progDesc "Compile brainfuck to an executable"
runCommand = command "run" $ info runOptions $ progDesc "Execute brainfuck code"
There is a section on optparse's github page here , but I don't really understand it.
(此处有关于optparse的github页面的部分,但我不太了解。)
The function completeWith :: Options.Applicative.Builder.Internal.HasCompleter f => [String] -> Mod fa
looks quite similar to command :: String -> ParserInfo a -> Mod CommandFields a
which I'm already using.
(函数completeWith :: Options.Applicative.Builder.Internal.HasCompleter f => [String] -> Mod fa
看上去与我已经在使用的command :: String -> ParserInfo a -> Mod CommandFields a
非常相似。)
So I figured I could use it and just combine them with <>
but it turns out that CommandFields
is not an instance of HasCompleter
. (所以我想我可以使用它,并将它们与<>
结合使用,但事实证明CommandFields
不是HasCompleter
的实例。)
How are you supposed to get the auto completion to work?
(您应该如何使自动完成工作?)
ask by The Hoff translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…