mirror of
https://github.com/github/semantic.git
synced 2024-12-26 00:12:29 +03:00
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.
This commit is contained in:
parent
7e9701e436
commit
bf1aebf1f3
@ -1,4 +1,4 @@
|
|||||||
{-# LANGUAGE FlexibleContexts, TypeOperators #-}
|
{-# LANGUAGE DeriveFunctor, DerivingStrategies, FlexibleContexts, GeneralizedNewtypeDeriving, TypeOperators #-}
|
||||||
module Core.Parser
|
module Core.Parser
|
||||||
( core
|
( core
|
||||||
, lit
|
, lit
|
||||||
@ -12,18 +12,28 @@ module Core.Parser
|
|||||||
|
|
||||||
import Control.Applicative
|
import Control.Applicative
|
||||||
import Control.Effect.Carrier
|
import Control.Effect.Carrier
|
||||||
|
import Control.Monad
|
||||||
import Core.Core ((:<-) (..), Core)
|
import Core.Core ((:<-) (..), Core)
|
||||||
import qualified Core.Core as Core
|
import qualified Core.Core as Core
|
||||||
import Core.Name
|
import Core.Name
|
||||||
import qualified Data.Char as Char
|
import qualified Data.Char as Char
|
||||||
import Data.Foldable (foldl')
|
import Data.Foldable (foldl')
|
||||||
import Data.String
|
import Data.String
|
||||||
|
import Text.Parser.LookAhead (LookAheadParsing)
|
||||||
import qualified Text.Parser.Token as Token
|
import qualified Text.Parser.Token as Token
|
||||||
import qualified Text.Parser.Token.Highlight as Highlight
|
import qualified Text.Parser.Token.Highlight as Highlight
|
||||||
|
import qualified Text.Parser.Token.Style as Style
|
||||||
import Text.Trifecta hiding (ident)
|
import Text.Trifecta hiding (ident)
|
||||||
|
|
||||||
-- * Identifier styles and derived parsers
|
-- * 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 :: Char -> Bool
|
||||||
validIdentifierStart c = not (Char.isDigit c) && isSimpleCharacter c
|
validIdentifierStart c = not (Char.isDigit c) && isSimpleCharacter c
|
||||||
|
|
||||||
@ -48,7 +58,7 @@ identifier = choice [quote, plain] <?> "identifier" where
|
|||||||
-- * Parsers (corresponding to EBNF)
|
-- * Parsers (corresponding to EBNF)
|
||||||
|
|
||||||
core :: (TokenParsing m, Carrier sig t, Member Core sig, Monad m) => m (t Name)
|
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 :: (TokenParsing m, Carrier sig t, Member Core sig, Monad m) => m (t Name)
|
||||||
expr = ifthenelse <|> lambda <|> rec <|> load <|> assign
|
expr = ifthenelse <|> lambda <|> rec <|> load <|> assign
|
||||||
|
Loading…
Reference in New Issue
Block a user