~jojo/Carth

fe104f251f232a134b292ef0efcb2da1abf163b3 — JoJo 1 year, 1 month ago 1c5bc90
Replace Parse.parseTokenTreeOrRest with Lex.tokentree in Err
2 files changed, 5 insertions(+), 17 deletions(-)

M src/Err.hs
M src/Parse.hs
M src/Err.hs => src/Err.hs +4 -4
@@ 2,13 2,15 @@

module Err (module Err, TypeErr(..), GenErr(..)) where

import Text.Megaparsec (match)

import Misc
import SrcPos
import TypeAst
import qualified Parsed
import Inferred
import Pretty
import Parse
import Lex
import Gen




@@ 108,9 110,7 @@ posd (pos@(SrcPos f lineN colN)) msg = do
                ice $ "col num in SourcePos is greater than " ++ "num of cols in src line"
        lineNS = show lineN'
        pad = length lineNS + 1
        s = either (\e -> ice ("posd: msg=|" ++ msg ++ "|,err=|" ++ show e ++ "|"))
                   id
                   (parseTokenTreeOrRest rest)
        s = either (const rest) fst (parse' (match tokentree) "" rest)
    putStrLn $ unlines
        [ prettySrcPos pos ++ ": Error:"
        , indent pad ++ "|"

M src/Parse.hs => src/Parse.hs +1 -13
@@ 7,14 7,13 @@
--       If a parser has a variant with a "ns_" prefix, that variant does not
--       consume succeding space, while the unprefixed variant does.

module Parse (Parser, Source, parse, parse', parseTokenTreeOrRest, toplevels) where
module Parse (Parser, Source, parse, parse', toplevels) where

import Control.Monad
import Data.Char (isMark, isPunctuation, isSymbol, isUpper)
import Data.Functor
import Data.Maybe
import Control.Applicative (liftA2)
import qualified Text.Megaparsec as Mega
import Text.Megaparsec hiding (parse, match)
import Text.Megaparsec.Char hiding (space, space1)
import qualified Text.Megaparsec.Char as Char


@@ 88,17 87,6 @@ parseModule filepath dir m visiteds nexts =
                    Left e -> pure (Left e)
                    Right r -> advance r

-- | For use in module TypeErr to get the length of the tokentree to draw a
--   squiggly line under it.
parseTokenTreeOrRest :: Source -> Either String String
parseTokenTreeOrRest = parse' tokenTreeOrRest ""
  where
    tokenTreeOrRest = fmap fst (Mega.match (try ns_tokenTree <|> (restOfInput $> ())))
    ns_tokenTree = choice
        [ns_strlit $> (), ns_ident $> (), ns_num $> (), ns_parens (many tokenTree) $> ()]
    tokenTree = andSkipSpaceAfter ns_tokenTree
    restOfInput = many Mega.anySingle

toplevels :: Parser ([Import], [Def], [TypeDef], [Extern])
toplevels = do
    space