From f88d78d60bad406ce775d29ec5891d8c46974119 Mon Sep 17 00:00:00 2001 From: Einhard Leichtfuß Date: Wed, 21 May 2025 11:51:00 +0200 Subject: Rename auxiliary parser modules --- src/Language/SimpleShell/Parser/Common/Lexeme.hs | 40 ++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/Language/SimpleShell/Parser/Common/Lexeme.hs (limited to 'src/Language/SimpleShell/Parser/Common/Lexeme.hs') diff --git a/src/Language/SimpleShell/Parser/Common/Lexeme.hs b/src/Language/SimpleShell/Parser/Common/Lexeme.hs new file mode 100644 index 0000000..c0a6fd6 --- /dev/null +++ b/src/Language/SimpleShell/Parser/Common/Lexeme.hs @@ -0,0 +1,40 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE FlexibleContexts #-} + +module Language.SimpleShell.Parser.Common.Lexeme + ( lexeme + , symbol + , commentFirstChars + ) +where + + +import Control.Monad (void) +import Data.Text (Text) +import Text.Megaparsec (MonadParsec) +import Text.Megaparsec.Char (space1) +import qualified Text.Megaparsec.Char.Lexer as L + ( lexeme + , symbol + , space + , skipLineComment + , skipBlockComment + ) + + +-- Must be kept in sync with 'commentFirstChars'. +sc :: (MonadParsec e Text m) => m () +sc = L.space + space1 + (L.skipLineComment "//") + (L.skipBlockComment "/*" "*/") + +-- | List of all characters that may start a comment. +commentFirstChars :: [Char] +commentFirstChars = "/" + +lexeme :: (MonadParsec e Text m) => m a -> m a +lexeme = L.lexeme sc + +symbol :: (MonadParsec e Text m) => Text -> m () +symbol = void . L.symbol sc -- cgit v1.2.3