From e55a21280d255399e9d1f1979f2035fc9ead8666 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Mon, 31 Jan 2022 23:26:13 +0200 Subject: Format strings with fmt --- src/parser.hs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/parser.hs') diff --git a/src/parser.hs b/src/parser.hs index 9a24fda..679f318 100644 --- a/src/parser.hs +++ b/src/parser.hs @@ -18,9 +18,8 @@ parseWord rawStr | "$" `isPrefixOf` rawStr = LLabel $ tail rawStr | otherwise = LSymbol rawStr -removeComments source = - let lines_ = lines source $> map (T.pack .> T.splitOn (T.pack "--") .> head .> T.unpack) - in unlines lines_ +removeComments = + lines .> map (T.pack .> T.splitOn (T.pack "--") .> head .> T.unpack) .> unlines processStringLiterals :: Maybe String -> Map String [LWord] -> String -> ExceptT LException IO (String, Map String [LWord]) processStringLiterals currentM refMap [] = case currentM of @@ -47,6 +46,8 @@ processStringLiterals currentM refMap (c : source) = case c of -- proceed normally processStringLiterals Nothing refMap source $> fmap (B.first (c :)) +internalNVar n = LLabel $ fmt "$__%%" [show n] + processSLInterpolations :: LWord -> ExceptT LException IO [LWord] processSLInterpolations strP@(LPhrase lChars) | "%%" `isInfixOf` chars = pure [LPhrase interpolated, LSymbol "unphrase"] @@ -57,17 +58,17 @@ processSLInterpolations strP@(LPhrase lChars) separatedByMarker = T.pack chars $> T.splitOn (T.pack "%%") .> map (T.unpack .> map LChar) labelIndices = [0 .. length separatedByMarker - 1 - 1] -- store n - 1 variables from stack - varStores = labelIndices $> map (\n -> [LLabel ("$__" ++ show n), LSymbol "!"]) .> reverse + varStores = labelIndices $> map (\n -> [internalNVar n, LSymbol "!"]) .> reverse part1 = concat varStores -- interleave the n substrings and n - 1 variable reads - symbolLookups = labelIndices $> map (\n -> [LLabel ("$__" ++ show n), LSymbol "@", LSymbol "unphrase"]) + symbolLookups = labelIndices $> map (\n -> [internalNVar n, LSymbol "@", LSymbol "unphrase"]) part2 = LSymbol "'[" : concat (mix separatedByMarker symbolLookups) ++ [LSymbol "']", LSymbol "phrase"] -- forget the temp variables used - varForgets = labelIndices $> map (\n -> [LLabel ("$__" ++ show n), LSymbol "forget"]) + varForgets = labelIndices $> map (\n -> [internalNVar n, LSymbol "forget"]) part3 = concat varForgets -- combine everything into one phrase interpolated = part1 ++ part2 ++ part3 -processSLInterpolations p = throwError $ LException $ "non-phrase in processSLInterpolations: " ++ show p +processSLInterpolations p = throwError $ LException $ fmt "non-phrase in processSLInterpolations: %%" [show p] parseSource source = do let woComments = source $> removeComments -- cgit v1.3