Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore update lts #170

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mulang.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ library
language-javascript ,
language-python ,
aeson ,
inflections <= 0.2.0.1,
inflections ,
parsec ,
ParsecTools ,
split ,
Expand Down
8 changes: 7 additions & 1 deletion spec/TokenizerSpec.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module TokenizerSpec (spec) where

import Test.Hspec
import Text.Inflections.Tokenizer (snakeCase, camelCase, tokenize)
import Text.Inflections.Tokenizer (snakeCase, camelCase, tokenize, canTokenize)

spec :: Spec
spec = do
Expand All @@ -17,3 +17,9 @@ spec = do

it "can tokenize snake_case words with numbers" $ do
tokenize snakeCase "the_first_and_the_last_2" `shouldBe` ["the", "first", "and", "the", "last", "2"]

it "can tokenize snake_case words with numbers using a wrong case" $ do
tokenize camelCase "the_first_and_the_last_2" `shouldBe` []

it "can tokenize snake_case words with numbers using a wrong case" $ do
canTokenize camelCase "the_first_and_the_last_2" `shouldBe` False
19 changes: 9 additions & 10 deletions src/Text/Inflections/Tokenizer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@ module Text.Inflections.Tokenizer (

import Data.Char (toLower, isDigit, isLower)
import Data.Either (isRight)
import Data.Bifunctor (first)

import Text.Inflections
import Text.Inflections.Parse.Types
import Text.Parsec.Error (ParseError)
import Text.Inflections (parseCamelCase, parseSnakeCase)
import Text.Inflections (SomeWord, unSomeWord)
import Data.Text (pack, unpack)

import Control.Fallible

type CaseStyle = String -> Either Text.Parsec.Error.ParseError [Text.Inflections.Parse.Types.Word]
type CaseStyle = String -> Either String [SomeWord]

camelCase :: CaseStyle
camelCase = parseCamelCase [] . filter (not.isDigit)
camelCase = first show . parseCamelCase [] . pack . filter (not.isDigit)

snakeCase :: CaseStyle
snakeCase = parseSnakeCase []
snakeCase = first show . parseSnakeCase [] . pack

rubyCase :: CaseStyle
rubyCase word | (isLower.head) word = snakeCase baseWord
Expand All @@ -37,7 +38,5 @@ tokenize style s | Just words <- (wordsOrNothing . style) s = concatMap toToken
| otherwise = []
where toToken = return . map toLower


wordsOrNothing = fmap (concatMap c) . orNothing
where c (Word w) = [w]
c _ = []
wordsOrNothing = fmap (map c) . orNothing
where c t = unpack (unSomeWord id t)
3 changes: 1 addition & 2 deletions stack.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
resolver: lts-7.24
resolver: lts-9.1
packages:
- '.'
extra-deps:
# Using newest aeson, with no contents in tagged
# unions with nullary constructors
- aeson-1.2.1.0
- language-javascript-0.6.0.10
flags: {}
extra-package-dbs: []