jherve 1 год назад
Родитель
Сommit
24c7fc7d40
2 измененных файлов с 19 добавлено и 16 удалено
  1. 9 6
      src/LinkedIn/Profile/Utils.purs
  2. 10 10
      src/LinkedIn/UIElements/Parser.purs

+ 9 - 6
src/LinkedIn/Profile/Utils.purs

@@ -9,7 +9,7 @@ import Data.List (List)
 import Data.List as L
 import Data.List as L
 import Data.Maybe (Maybe(..))
 import Data.Maybe (Maybe(..))
 import LinkedIn.DetachedNode (DetachedNode(..))
 import LinkedIn.DetachedNode (DetachedNode(..))
-import LinkedIn.UIElements.Parser (uiElementP)
+import LinkedIn.UIElements.Parser (uiStringP)
 import LinkedIn.UIElements.Types (UIElement(..))
 import LinkedIn.UIElements.Types (UIElement(..))
 import Parsing (ParseError(..), initialPos, runParser)
 import Parsing (ParseError(..), initialPos, runParser)
 
 
@@ -37,9 +37,9 @@ maybeFindInMaybeNEL extract = case _ of
 
 
 -- TODO : should certainly use another type than ParseError here
 -- TODO : should certainly use another type than ParseError here
 toUIElement ∷ DetachedNode → Either ParseError UIElement
 toUIElement ∷ DetachedNode → Either ParseError UIElement
-toUIElement (DetachedElement {content}) = runParser content uiElementP
-toUIElement (DetachedComment str) = runParser str uiElementP
-toUIElement (DetachedText str) = runParser str uiElementP
+toUIElement (DetachedElement {content}) = wrapInUiElement content
+toUIElement (DetachedComment str) = wrapInUiElement str
+toUIElement (DetachedText str) = wrapInUiElement str
 
 
 toUIElement (DetachedSvgElement {id, dataTestIcon, tag: "svg"}) = case id <|> dataTestIcon of
 toUIElement (DetachedSvgElement {id, dataTestIcon, tag: "svg"}) = case id <|> dataTestIcon of
   Just i -> Right (UIIcon i)
   Just i -> Right (UIIcon i)
@@ -48,8 +48,11 @@ toUIElement (DetachedSvgElement _) = Left (ParseError "SVG element could not be
 
 
 toUIElement (DetachedLiIcon i) = Right (UIIcon i)
 toUIElement (DetachedLiIcon i) = Right (UIIcon i)
 
 
-toUIElement (DetachedButton {content, role}) =  map toButton $ runParser content uiElementP
+toUIElement (DetachedButton {content, role}) =  map toButton $ runParser content uiStringP
   where toButton ui = UIButton role ui
   where toButton ui = UIButton role ui
 
 
-toUIElement (DetachedA {content, href}) = map toLink $ runParser content uiElementP
+toUIElement (DetachedA {content, href}) = map toLink $ runParser content uiStringP
   where toLink ui = UILink href ui
   where toLink ui = UILink href ui
+
+wrapInUiElement ∷ String → Either ParseError UIElement
+wrapInUiElement string = map UIElement $ runParser string uiStringP

+ 10 - 10
src/LinkedIn/UIElements/Parser.purs

@@ -14,7 +14,7 @@ import Data.Map as M
 import Data.Maybe (Maybe(..))
 import Data.Maybe (Maybe(..))
 import Data.String.CodePoints (codePointFromChar)
 import Data.String.CodePoints (codePointFromChar)
 import Data.Tuple (Tuple(..))
 import Data.Tuple (Tuple(..))
-import LinkedIn.UIElements.Types (Duration(..), MonthYear(..), MonthYearOrToday(..), TimeSpan(..), UIElement(..))
+import LinkedIn.UIElements.Types (Duration(..), MonthYear(..), MonthYearOrToday(..), TimeSpan(..), UIElement(..), UIString(..))
 import Parsing (Parser, fail, runParser)
 import Parsing (Parser, fail, runParser)
 import Parsing.Combinators (choice, try)
 import Parsing.Combinators (choice, try)
 import Parsing.String (string, char, rest)
 import Parsing.String (string, char, rest)
@@ -128,20 +128,20 @@ stringWithoutCommaP = takeWhile (\c -> c /= codePointFromChar ',')
 stringWithoutMedianDotP :: Parser String String
 stringWithoutMedianDotP :: Parser String String
 stringWithoutMedianDotP = takeWhile (\c -> c /= codePointFromChar '·' && c /= codePointFromChar '•')
 stringWithoutMedianDotP = takeWhile (\c -> c /= codePointFromChar '·' && c /= codePointFromChar '•')
 
 
-uiElementP :: Parser String UIElement
-uiElementP = (try dotSeparatedP') <|> simpleUiElementP' where
+uiStringP :: Parser String UIString
+uiStringP = (try dotSeparatedP') <|> singleUiStringP where
   dotSeparatedP' = do
   dotSeparatedP' = do
     subStr <- stringWithoutMedianDotP
     subStr <- stringWithoutMedianDotP
     _ <- medianDotP
     _ <- medianDotP
     _ <- space
     _ <- space
     sub2Str <- rest
     sub2Str <- rest
-    case runParser subStr simpleUiElementP' of
-      Right sub -> case runParser sub2Str simpleUiElementP' of
-        Right sub2 -> pure $ UIDotSeparated sub sub2
+    case runParser subStr singleUiStringP of
+      Right sub -> case runParser sub2Str singleUiStringP of
+        Right sub2 -> pure $ UIStringDotSeparated sub sub2
         Left _ -> fail "not a sub"
         Left _ -> fail "not a sub"
       Left _ -> fail "not a sub"
       Left _ -> fail "not a sub"
 
 
-  simpleUiElementP' = (try durationP') <|> (try timeSpanP') <|> stringP'
-  durationP' = UIDuration <$> durationP
-  timeSpanP' = UITimeSpan <$> timeSpanP
-  stringP' = UIPlainText <$> rest
+  singleUiStringP = (try durationP') <|> (try timeSpanP') <|> plainP'
+  durationP' = UIStringDuration <$> durationP
+  timeSpanP' = UIStringTimeSpan <$> timeSpanP
+  plainP' = UIStringPlain <$> rest