mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-22 19:22:50 -06:00
complete word completion in the shell. works for commands, flags, options, abstract syntax identifiers and NL strings
This commit is contained in:
@@ -26,3 +26,23 @@ data Argument
|
||||
= AExp Exp
|
||||
| ANoArg
|
||||
deriving (Eq,Ord,Show)
|
||||
|
||||
valIdOpts :: String -> String -> [Option] -> String
|
||||
valIdOpts flag def opts = case valOpts flag (VId def) opts of
|
||||
VId v -> v
|
||||
_ -> def
|
||||
|
||||
valIntOpts :: String -> Integer -> [Option] -> Int
|
||||
valIntOpts flag def opts = fromInteger $ case valOpts flag (VInt def) opts of
|
||||
VInt v -> v
|
||||
_ -> def
|
||||
|
||||
valOpts :: String -> Value -> [Option] -> Value
|
||||
valOpts flag def opts = case lookup flag flags of
|
||||
Just v -> v
|
||||
_ -> def
|
||||
where
|
||||
flags = [(f,v) | OFlag f v <- opts]
|
||||
|
||||
isOpt :: String -> [Option] -> Bool
|
||||
isOpt o opts = elem o [x | OOpt x <- opts]
|
||||
|
||||
@@ -64,26 +64,6 @@ commandHelp full (co,info) = unlines $ [
|
||||
"flags: " ++ unwords (flags info)
|
||||
] else []
|
||||
|
||||
valIdOpts :: String -> String -> [Option] -> String
|
||||
valIdOpts flag def opts = case valOpts flag (VId def) opts of
|
||||
VId v -> v
|
||||
_ -> def
|
||||
|
||||
valIntOpts :: String -> Integer -> [Option] -> Int
|
||||
valIntOpts flag def opts = fromInteger $ case valOpts flag (VInt def) opts of
|
||||
VInt v -> v
|
||||
_ -> def
|
||||
|
||||
valOpts :: String -> Value -> [Option] -> Value
|
||||
valOpts flag def opts = case lookup flag flags of
|
||||
Just v -> v
|
||||
_ -> def
|
||||
where
|
||||
flags = [(f,v) | OFlag f v <- opts]
|
||||
|
||||
isOpt :: String -> [Option] -> Bool
|
||||
isOpt o opts = elem o [x | OOpt x <- opts]
|
||||
|
||||
-- this list must be kept sorted by the command name!
|
||||
allCommands :: PGF -> Map.Map String CommandInfo
|
||||
allCommands pgf = Map.fromAscList [
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module GF.Command.Parse(readCommandLine) where
|
||||
module GF.Command.Parse(readCommandLine, pCommand) where
|
||||
|
||||
import PGF.ExprSyntax
|
||||
import GF.Command.Abstract
|
||||
|
||||
@@ -18,6 +18,8 @@ import System.Console.Readline
|
||||
|
||||
fetchCommand :: String -> IO (String)
|
||||
fetchCommand s = do
|
||||
setCompletionAppendCharacter Nothing
|
||||
setBasicQuoteCharacters ""
|
||||
res <- readline s
|
||||
case res of
|
||||
Nothing -> return "q"
|
||||
|
||||
Reference in New Issue
Block a user