summaryrefslogtreecommitdiff
path: root/Pancake/Command.hs
diff options
context:
space:
mode:
authordefanor <defanor@uberspace.net>2017-11-23 06:20:50 +0300
committerdefanor <defanor@uberspace.net>2017-11-23 06:20:50 +0300
commit07fa7ad1000f6ac6fd76fc9233c150bdbde2e67b (patch)
treec62b1466168392c3d04e1827b31b317428a6251c /Pancake/Command.hs
parentb6b3b20e30bf7e05a317522b7c5284a4f7b92223 (diff)
Allow user-defined digits and radices for reference numbering
Diffstat (limited to 'Pancake/Command.hs')
-rw-r--r--Pancake/Command.hs21
1 files changed, 15 insertions, 6 deletions
diff --git a/Pancake/Command.hs b/Pancake/Command.hs
index 97cb25c..44ac768 100644
--- a/Pancake/Command.hs
+++ b/Pancake/Command.hs
@@ -15,6 +15,9 @@ import Network.URI
import Text.Parsec
import Text.Parsec.String
import qualified Data.Map as M
+import Numeric
+import Data.List
+import Data.Maybe
import Pancake.Configuration
@@ -52,13 +55,19 @@ basicCommand = choice . map (\(s, c) -> try (string s <* eof) *> pure c) $
, ("?", ShowCurrent)
, ("", More)]
+pReference :: String -> Parser Int
+pReference digits = do
+ ds <- many1 (choice $ map char digits)
+ pure . fst . head $ readInt (length digits)
+ (`elem` digits) (fromJust . flip elemIndex digits) ds
+
-- | 'Follow' command parser.
-followRef :: Parser Command
-followRef = Follow . read <$> many1 digit <* eof
+followRef :: String -> Parser Command
+followRef digits = Follow <$> (optional (char '.') *> pReference digits <* eof)
-- | 'Show' command parser.
-showRef :: Parser Command
-showRef = char '?' *> (Show . read <$> many1 digit) <* eof
+showRef :: String -> Parser Command
+showRef digits = Show <$> (char '?' *> pReference digits <* eof)
-- | 'GoTo' command parser.
goTo :: Parser Command
@@ -82,8 +91,8 @@ command :: Config -> Parser Command
command c =
choice (map try
[ basicCommand <?> "basic command"
- , followRef <?> "follow ref"
- , showRef <?> "show ref"
+ , followRef (referenceDigits c) <?> "follow ref"
+ , showRef (referenceDigits c) <?> "show ref"
, shortcut (shortcuts c) <?> "shortcut"
, goTo <?> "go to"
])