aboutsummaryrefslogtreecommitdiff
path: root/src/Language
diff options
context:
space:
mode:
Diffstat (limited to 'src/Language')
-rw-r--r--src/Language/SimpleShell/Parser.hs6
-rw-r--r--src/Language/SimpleShell/Parser/Expr.hs18
2 files changed, 9 insertions, 15 deletions
diff --git a/src/Language/SimpleShell/Parser.hs b/src/Language/SimpleShell/Parser.hs
index be16c9f..d75602b 100644
--- a/src/Language/SimpleShell/Parser.hs
+++ b/src/Language/SimpleShell/Parser.hs
@@ -4,7 +4,6 @@ module Language.SimpleShell.Parser
( Parser
, lexeme
, symbol
- , commentFirstChars
, lookupVar
, lookupFun
, declareVars
@@ -51,17 +50,12 @@ initContext = Context
}
--- Must be kept in sync with 'commentFirstChars'.
sc :: Parser ()
sc = L.space
space1
(L.skipLineComment "//")
(L.skipBlockComment "/*" "*/")
--- | List of all characters that may start a comment.
-commentFirstChars :: [Char]
-commentFirstChars = "/"
-
lexeme :: Parser a -> Parser a
lexeme = L.lexeme sc
diff --git a/src/Language/SimpleShell/Parser/Expr.hs b/src/Language/SimpleShell/Parser/Expr.hs
index cabf522..0f2f6c9 100644
--- a/src/Language/SimpleShell/Parser/Expr.hs
+++ b/src/Language/SimpleShell/Parser/Expr.hs
@@ -15,7 +15,6 @@ import Language.SimpleShell.Parser
( Parser
, lexeme
, symbol
- , commentFirstChars
, lookupVar
, lookupFun
)
@@ -32,7 +31,7 @@ import Control.Monad (void)
import Control.Monad.Combinators (manyTill)
import Data.Foldable (asum)
import Data.Text (Text)
-import Text.Megaparsec (takeWhile1P, oneOf, many)
+import Text.Megaparsec (anySingleBut, many)
import Text.Megaparsec.Char (char)
import qualified Text.Megaparsec.Char.Lexer as L (charLiteral, decimal)
@@ -67,16 +66,17 @@ strongTermP_
-- * parentheses
-- * string literals
-- * comments
+ -- - Thus, `takeWhile1P` is dangerous.
+ -- * This is hardly the most efficient implementation.
+ -- * A more efficient implementation would use `takeWhile1P` to parse
+ -- large chunks of input, but--as noted above--that is dangerous;
+ -- i.e., non-trivial (albeit not really hard) to do correctly.
tok :: Parser ()
tok
- = void strLitP
- <|> symbol "(" *> void (many tok) <* symbol ")"
- <|> void (lexeme $ takeWhile1P Nothing isBoring)
- <|> void (lexeme $ oneOf commentFirstChars)
- where
- isBoring :: Char -> Bool
- isBoring = not . (`elem` "()\"" ++ commentFirstChars)
+ = strongTermP_
+ <|> void nameP -- function names; for efficiency only
+ <|> void (lexeme $ anySingleBut ')') -- operators (i.a.; catchall)
-- | Parse "strong" term with fixed type.