From f93834259d0041189089b0ac13a64f5137849c93 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Wed, 11 Jul 2018 12:10:34 +0200 Subject: [PATCH] Remove Regex dependency --- Clean/Doc.icl | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Clean/Doc.icl b/Clean/Doc.icl index 3f2a490..2bec984 100644 --- a/Clean/Doc.icl +++ b/Clean/Doc.icl @@ -26,8 +26,6 @@ from Text import class Text(join,split,trim,rtrim), import Text.Language import Text.Parsers.Simple.ParserCombinators -import Regex - from Clean.Types import :: Type, :: TypeRestriction import qualified Clean.Types.Parse as T @@ -148,16 +146,20 @@ docBlockToDoc{|OBJECT|} fx doc = appFst OBJECT <$> fx doc docBlockToDoc{|MultiLineString|} (Left [s]) = Right (MultiLine $ trimMultiLine $ split "\n" s, []) -docBlockToDoc{|ParamDoc|} (Left [s]) = case match rgx (fromString s) of - [(_,_,groups):_] -> Right ( - { name = toString <$> lookup (NotNamed 0) groups - , description = case lookup (NotNamed 1) groups of - Just cs=:[_:_] -> Just (toString cs) - _ -> Nothing +docBlockToDoc{|ParamDoc|} (Left [s]) = case findName (fromString s) of + Just (name,rest) -> Right ( + { name = Just $ toString name + , description = case rest of + [] -> Nothing + _ -> Just $ toString rest }, []) - [] -> Right ({name=Nothing, description=Just s}, []) + _ -> Right ({name=Nothing, description=Just s}, []) where - rgx = regex ['^(\\w+):\\s*(.*)$'] + findName cs + # (name,cs) = span (\c -> isAlphanum c || c == '`') cs + | not (isEmpty name) && not (isEmpty cs) && hd cs == ':' + = Just (toString name, dropWhile isSpace (tl cs)) + = Nothing docBlockToDoc{|Type|} (Left []) = Left InternalNoDataError docBlockToDoc{|Type|} (Left ss) = case [v \\ Just v <- map ('T'.parseType o fromString) ss] of -- GitLab