aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEinhard Leichtfuß <alguien@respiranto.de>2025-05-19 02:26:06 +0200
committerEinhard Leichtfuß <alguien@respiranto.de>2025-05-19 02:26:06 +0200
commitd5cdf6e40b070ad82418d698bc408dc08c175d2e (patch)
tree685312674c41a332c60a253269e527f59d19258e
parentcfb2f44ef931201bb152133b8a4f79fcd51e25b4 (diff)
Add lexeme parser
-rw-r--r--src/Language/SimpleShell/Parser.hs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/Language/SimpleShell/Parser.hs b/src/Language/SimpleShell/Parser.hs
index fdbeaf9..1f65456 100644
--- a/src/Language/SimpleShell/Parser.hs
+++ b/src/Language/SimpleShell/Parser.hs
@@ -1,5 +1,8 @@
+{-# LANGUAGE OverloadedStrings #-}
+
module Language.SimpleShell.Parser
( Parser
+ , lexeme
, lookupVar
, lookupFun
, initContext
@@ -18,6 +21,13 @@ import Data.Text (Text, unpack)
import Data.Void (Void)
import Text.Megaparsec (Parsec)
import qualified Text.Megaparsec as MP (parseTest)
+import Text.Megaparsec.Char (space1)
+import qualified Text.Megaparsec.Char.Lexer as L
+ ( lexeme
+ , space
+ , skipLineComment
+ , skipBlockComment
+ )
type Parser = ReaderT Context (Parsec Void Text)
@@ -34,6 +44,15 @@ initContext = Context
}
+sc :: Parser ()
+sc = L.space
+ space1
+ (L.skipLineComment "//")
+ (L.skipBlockComment "/*" "*/")
+
+lexeme = L.lexeme sc
+
+
lookupVar :: VarName -> Parser SimpleType
lookupVar varname = do
mt <- Map.lookup varname . ctxVars <$> ask