diff --git a/src/Lexer.hs b/src/Lexer.hs index a6614ab..3af7799 100644 --- a/src/Lexer.hs +++ b/src/Lexer.hs @@ -3,6 +3,8 @@ module Lexer where import Research import Text.Megaparsec import Text.Megaparsec.Char + +import Control.Monad (void) import Data.Void import qualified Data.Set as Set @@ -21,6 +23,7 @@ data LToken | LOpenBracket | LCloseBracket | LNewline + | LComment String deriving (Show, Eq, Ord) keywordT :: Lexer LToken @@ -72,8 +75,16 @@ closeBracket = char ']' *> pure LCloseBracket lnewline :: Lexer LToken lnewline = char '\n' *> pure LNewline +comment :: Lexer LToken +comment = do + string "--" + content <- many (satisfy (/= '\n')) + optional (char '\n') + pure (LComment content) + + sc :: Lexer () -sc = skipMany (char ' ' <|> char '\t') +sc = skipMany (void (char ' ') <|> void (char '\t') <|> void comment) saplingLexer :: Lexer [LToken] saplingLexer = many (sc *> choice diff --git a/src/REPL.hs b/src/REPL.hs index db2b66f..cfeb7e9 100644 --- a/src/REPL.hs +++ b/src/REPL.hs @@ -5,11 +5,10 @@ import Lexer import Parser import Research -import Control.Monad (void) import Data.List (intercalate) import qualified Data.Map as Map import System.Console.Haskeline -import System.IO (hFlush, stdout) +import System.IO (hFlush, stdout) repl :: Map.Map String T -> IO () repl env = runInputT defaultSettings (loop env)