From bf1aebf1f32bb69b7eaa772540ad34d9cff9133e Mon Sep 17 00:00:00 2001 From: Patrick Thomson Date: Wed, 23 Oct 2019 15:27:13 -0400 Subject: [PATCH] Add comments to Core. I went with the Haskell comment style (`--` for line comments, `{- -}` for block comments, allowing nested multiline comments. This can be changed pretty easily. --- semantic-core/src/Core/Parser.hs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/semantic-core/src/Core/Parser.hs b/semantic-core/src/Core/Parser.hs index 34e417364..a8144bc4f 100644 --- a/semantic-core/src/Core/Parser.hs +++ b/semantic-core/src/Core/Parser.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE FlexibleContexts, TypeOperators #-} +{-# LANGUAGE DeriveFunctor, DerivingStrategies, FlexibleContexts, GeneralizedNewtypeDeriving, TypeOperators #-} module Core.Parser ( core , lit @@ -12,18 +12,28 @@ module Core.Parser import Control.Applicative import Control.Effect.Carrier +import Control.Monad import Core.Core ((:<-) (..), Core) import qualified Core.Core as Core import Core.Name import qualified Data.Char as Char import Data.Foldable (foldl') import Data.String +import Text.Parser.LookAhead (LookAheadParsing) import qualified Text.Parser.Token as Token import qualified Text.Parser.Token.Highlight as Highlight +import qualified Text.Parser.Token.Style as Style import Text.Trifecta hiding (ident) -- * Identifier styles and derived parsers +newtype CoreParser m a = CoreParser { runCoreParser :: m a } + deriving stock Functor + deriving newtype (Alternative, Applicative, CharParsing, DeltaParsing, Errable, LookAheadParsing, Monad, MonadPlus, Parsing) + +instance TokenParsing m => TokenParsing (CoreParser m) where + someSpace = Style.buildSomeSpaceParser (void (satisfy Char.isSpace)) Style.haskellCommentStyle + validIdentifierStart :: Char -> Bool validIdentifierStart c = not (Char.isDigit c) && isSimpleCharacter c @@ -48,7 +58,7 @@ identifier = choice [quote, plain] "identifier" where -- * Parsers (corresponding to EBNF) core :: (TokenParsing m, Carrier sig t, Member Core sig, Monad m) => m (t Name) -core = expr +core = runCoreParser expr expr :: (TokenParsing m, Carrier sig t, Member Core sig, Monad m) => m (t Name) expr = ifthenelse <|> lambda <|> rec <|> load <|> assign