Skip to content

Commit

Permalink
⬆️
Browse files Browse the repository at this point in the history
  • Loading branch information
AlephAlpha committed Oct 11, 2023
1 parent 89f2f86 commit ff21fad
Show file tree
Hide file tree
Showing 6 changed files with 1,080 additions and 1,078 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ghc: ['9.0.1', '9.2.8', '9.4.7', '9.6.3']
ghc: ['9.0.1', '9.4.7', '9.6.3', '9.8.1']
steps:
- uses: actions/checkout@v4
- uses: haskell/actions/setup@v2
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Revision history for Nekomata

## 0.5.2.0 -- Unreleased

* Updated some dependencies.
* Fixed a bug in printing truncated results.

## 0.5.1.0 -- 2023-09-27

* New built-in functions: `\bifurcate`, `\divMod`, `\flatten`, `\histogram`, `\isBig`, `\isSmall`, `\over`, `\popCount`, `\rle`, `\unrle`.
Expand Down
4 changes: 2 additions & 2 deletions Nekomata.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ executable Nekomata
-- Other library packages from which modules are imported.
build-depends:
, base >=4.15 && <5
, bytestring ^>=0.11
, bytestring ^>=0.12
, containers ^>=0.6
, haskeline ^>=0.8
, Nekomata
Expand Down Expand Up @@ -154,5 +154,5 @@ test-suite Nekomata-test
-- Test dependencies.
build-depends:
, base >=4.15 && <5
, hspec ^>=2.10
, hspec ^>=2.11
, Nekomata
4 changes: 2 additions & 2 deletions app/Repl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ completionFromMap m f prefix = completing ++ completed
completing =
[ completing' name' short'
| name' <- Map.keys m
, tail prefix `isPrefixOf` name'
, drop 1 prefix `isPrefixOf` name'
, let short' = [f $ m ! name']
]
completed =
if not (null prefix) && last prefix == ' '
then case Map.lookup (tail $ init prefix) m of
then case Map.lookup (drop 1 $ init prefix) m of
Nothing -> []
Just b -> [completed' [f b]]
else []
Expand Down
13 changes: 5 additions & 8 deletions src/Nekomata/Eval.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,36 +76,33 @@ checkResult = hasValue initDecisions

-- | The result of a Nekomata evaluation, to be shown to the user
data Result
= All [String]
| Truncated [String]
= All Bool [String]
| First (Maybe String)
| Count Integer
| Check Bool
deriving (Eq)

instance Show Result where
show (All xs) = unwords xs
show (Truncated xs) = unwords xs ++ " ..."
show (All truncated xs) = unwords xs ++ if truncated then "..." else ""
show (First x) = fromMaybe "" x
show (Count n) = show n
show (Check b) = show b

-- | Show a Nekomata result separated by newlines
showResult :: Result -> [String]
showResult (All xs) = xs
showResult (Truncated xs) = xs
showResult (All truncated xs) = xs ++ ["..." | truncated]
showResult (First x) = [fromMaybe "" x]
showResult (Count n) = [show n]
showResult (Check b) = [show b]

-- | Truncate a list of strings to a given length
truncate' :: Int -> [String] -> Result
truncate' n xs =
let (ys, zs) = splitAt n xs in Truncated $ ys ++ ["..." | not (null zs)]
let (ys, zs) = splitAt n xs in All (not $ null zs) ys

-- | Get the result of a Nekomata evaluation according to the mode
toResult :: Mode -> Maybe Int -> TryData -> Result
toResult AllValues Nothing = All . allResults
toResult AllValues Nothing = All False . allResults
toResult AllValues (Just n) = truncate' n . allResults
toResult FirstValue _ = First . firstResult
toResult CountValues _ = Count . countResults
Expand Down
Loading

0 comments on commit ff21fad

Please sign in to comment.