Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick fix for #1158 #1166

Merged
merged 2 commits into from
Jan 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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