diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2022-01-31 22:49:36 +0200 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2022-01-31 22:49:36 +0200 |
| commit | b235c2887ed60a8fd48263f6c53e90ee7e2073fd (patch) | |
| tree | 2a47ec5bc38ef95b65b130d277e6ba41dc9f2213 /src/parser.hs | |
| parent | 7390af67e18e6d17934541dd3c2d6d46cfad84d0 (diff) | |
Some general refactoring
Diffstat (limited to 'src/parser.hs')
| -rw-r--r-- | src/parser.hs | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/src/parser.hs b/src/parser.hs index e1bea13..9a24fda 100644 --- a/src/parser.hs +++ b/src/parser.hs @@ -22,13 +22,11 @@ removeComments source = let lines_ = lines source $> map (T.pack .> T.splitOn (T.pack "--") .> head .> T.unpack) in unlines lines_ -processStringLiterals = processStringLiterals' Nothing M.empty - -processStringLiterals' :: Maybe String -> Map String [LWord] -> String -> ExceptT LException IO (String, Map String [LWord]) -processStringLiterals' currentM refMap [] = case currentM of +processStringLiterals :: Maybe String -> Map String [LWord] -> String -> ExceptT LException IO (String, Map String [LWord]) +processStringLiterals currentM refMap [] = case currentM of Just _ -> throwError $ LException "nonterminated string literal" Nothing -> pure ([], refMap) -processStringLiterals' currentM refMap (c : source) = case c of +processStringLiterals currentM refMap (c : source) = case c of '"' -> case currentM of Just str -> do -- string literal ends @@ -36,18 +34,18 @@ processStringLiterals' currentM refMap (c : source) = case c of let strP = str $> map LChar .> LPhrase interpolated <- processSLInterpolations strP let newRefMap = M.insert hash interpolated refMap - (resSource, resRefMap) <- processStringLiterals' Nothing newRefMap source + (resSource, resRefMap) <- processStringLiterals Nothing newRefMap source pure ("##" ++ hash ++ resSource, resRefMap) Nothing -> -- string literal starts - processStringLiterals' (Just "") refMap source + processStringLiterals (Just "") refMap source other -> case currentM of Just str -> -- add char to current string literal - processStringLiterals' (Just $ str ++ [c]) refMap source + processStringLiterals (Just $ str ++ [c]) refMap source Nothing -> -- proceed normally - processStringLiterals' Nothing refMap source $> fmap (B.first (c :)) + processStringLiterals Nothing refMap source $> fmap (B.first (c :)) processSLInterpolations :: LWord -> ExceptT LException IO [LWord] processSLInterpolations strP@(LPhrase lChars) @@ -73,5 +71,5 @@ processSLInterpolations p = throwError $ LException $ "non-phrase in processSLIn parseSource source = do let woComments = source $> removeComments - (woStringLiterals, stringLiteralRefMap) <- processStringLiterals woComments - pure (woStringLiterals $> words .> map parseWord, stringLiteralRefMap) + (woStringLiterals, stringLiteralRefMap) <- processStringLiterals Nothing M.empty woComments + pure (woStringLiterals $> words .> map parseWord, stringLiteralRefMap)
\ No newline at end of file |
