Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit cc9e402

Browse files
committed
Use between in some parser definitions
1 parent 5379f1c commit cc9e402

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

src/Expr.hs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Data.String (IsString (..))
88
import Data.Text (Text)
99
import qualified Data.Text as T
1010
import Text.Parsec (many, many1, optionMaybe, parse, sepBy,
11-
(<|>))
11+
(<|>), between)
1212
import Text.Parsec.Char (char, digit, letter, noneOf, spaces)
1313
import Text.Parsec.Error (ParseError)
1414
import Text.Parsec.Text (Parser)
@@ -58,11 +58,10 @@ number = do
5858

5959

6060
stringLiteral :: Parser Expr
61-
stringLiteral = do
62-
_ <- char '\''
63-
content <- many (noneOf "\'")
64-
_ <- char '\''
65-
pure $ StringLiteral $ T.pack content
61+
stringLiteral = StringLiteral . T.pack <$> string
62+
where
63+
singleQuote = char '\''
64+
string = between singleQuote singleQuote (many (noneOf "\'"))
6665

6766

6867
functionCall :: Parser Expr
@@ -71,11 +70,10 @@ functionCall = do
7170
args <- fromMaybe [] <$> optionMaybe functionArgs
7271
pure $ FunctionCall (Function name args)
7372
where
74-
functionArgs = do
75-
_ <- char '('
76-
args <- expr `sepBy` (char ',' >> spaces)
77-
_ <- char ')'
78-
pure args
73+
functionArgs = between open close (expr `sepBy` comma)
74+
open = char '('
75+
close = char ')'
76+
comma = char ',' >> spaces
7977

8078

8179
ident :: Parser Text

0 commit comments

Comments
 (0)