Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Ailrun committed Jan 7, 2021
1 parent 57f28ff commit 82e7280
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions plugins/hls-eval-plugin/src/Ide/Plugin/Eval/Parse/Token.hs
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
{-# OPTIONS_GHC -Wwarn #-}

-- | Parse source code into a list of line Tokens.
module Ide.Plugin.Eval.Parse.Token(Token(..),TokenS,tokensFrom,unsafeContent,isStatement,isTextLine,isPropLine,isCodeLine,isBlockOpen,isBlockClose) where

import Control.Monad.Combinators (skipManyTill, many, optional, (<|>))
module Ide.Plugin.Eval.Parse.Token (
Token(..),
TokenS,
tokensFrom,
unsafeContent,
isStatement,
isTextLine,
isPropLine,
isCodeLine,
isBlockOpen,
isBlockClose
) where

import Control.Monad.Combinators (many, optional, skipManyTill,
(<|>))
import Data.Functor (($>))
import Data.List (foldl')
import Ide.Plugin.Eval.Parse.Parser (satisfy, Parser, alphaNumChar, char,
letterChar, runParser, space,
string, tillEnd)
import Ide.Plugin.Eval.Parse.Parser (Parser, alphaNumChar, char,
letterChar, runParser, satisfy,
space, string, tillEnd)
import Ide.Plugin.Eval.Types (Format (..), Language (..), Loc,
Located (Located))
import Maybes (fromJust, fromMaybe)
import Data.Functor ( ($>) )

type TParser = Parser Char (State, [TokenS])

Expand Down Expand Up @@ -60,7 +72,7 @@ isBlockOpen _ = False

isBlockClose :: Token s -> Bool
isBlockClose BlockClose = True
isBlockClose _ = False
isBlockClose _ = False

unsafeContent :: Token a -> a
unsafeContent = fromJust . contentOf
Expand All @@ -83,7 +95,7 @@ contentOf _ = Nothing
-}
tokensFrom :: String -> [Loc (Token String)]
tokensFrom = tokens . lines
tokensFrom = tokens . lines . filter (/= '\r')

{- |
>>> tokens ["-- |$setup >>> 4+7","x=11"]
Expand Down Expand Up @@ -135,9 +147,9 @@ tokens = concatMap (\(l, vs) -> map (Located l) vs) . zip [0 ..] . reverse . snd

-- | Parse a line of input
aline :: State -> TParser
aline InCode = optionStart <|> multi <|> singleOpen <|> codeLine
aline InCode = optionStart <|> multi <|> singleOpen <|> codeLine
aline InSingleComment = optionStart <|> multi <|> commentLine False <|> codeLine
aline InMultiComment = multiClose <|> commentLine True
aline InMultiComment = multiClose <|> commentLine True

multi :: TParser
multi = multiOpenClose <|> multiOpen
Expand Down

0 comments on commit 82e7280

Please sign in to comment.