Skip to content

Commit 35ac8af

Browse files
committed
Get rid of Alternative instance for Parser
1 parent d5cbc41 commit 35ac8af

File tree

2 files changed

+27
-35
lines changed

2 files changed

+27
-35
lines changed

compiler/src/Parse/Expression.hs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ module Parse.Expression
66
where
77

88

9-
import Control.Monad (guard)
10-
119
import qualified AST.Source as Src
1210
import qualified Elm.Name as N
1311
import Parse.Primitives
@@ -300,34 +298,36 @@ exprHelp start (State ops expr args end pos) =
300298
spos <- W.whitespace
301299
hint (E.AfterOpExpr opName) (checkSpace spos)
302300
newStart <- getPosition
303-
hint (E.AfterOpExpr opName) $ oneOf $
304-
[ -- negative terms
305-
do guard ("-" == opName && end /= opStart && opEnd == newStart)
306-
rawTerm <- term
301+
hint (E.AfterOpExpr opName) $
302+
if "-" == opName && end /= opStart && opEnd == newStart
303+
then
304+
-- negative terms
305+
do rawTerm <- term
307306
newEnd <- getPosition
308307
newPos <- W.whitespace
309308
let arg = A.at opStart newEnd (Src.Negate rawTerm)
310309
exprHelp start (State ops expr (arg:args) newEnd newPos)
311-
312-
, -- term
313-
do newExpr <- possiblyNegativeTerm newStart
314-
newEnd <- getPosition
315-
newPos <- W.whitespace
316-
let newOps = (toCall expr args, op) : ops
317-
exprHelp start (State newOps newExpr [] newEnd newPos)
318-
319-
, -- final term
320-
do (newLast, newEnd, newPos) <-
321-
oneOf
322-
[ let_ newStart
323-
, case_ newStart
324-
, if_ newStart
325-
, function newStart
326-
]
327-
let newOps = (toCall expr args, op) : ops
328-
let finalExpr = A.at start newEnd (Src.Binops (reverse newOps) newLast)
329-
return ( finalExpr, newEnd, newPos )
330-
]
310+
else
311+
oneOf
312+
[ -- term
313+
do newExpr <- possiblyNegativeTerm newStart
314+
newEnd <- getPosition
315+
newPos <- W.whitespace
316+
let newOps = (toCall expr args, op) : ops
317+
exprHelp start (State newOps newExpr [] newEnd newPos)
318+
319+
, -- final term
320+
do (newLast, newEnd, newPos) <-
321+
oneOf
322+
[ let_ newStart
323+
, case_ newStart
324+
, if_ newStart
325+
, function newStart
326+
]
327+
let newOps = (toCall expr args, op) : ops
328+
let finalExpr = A.at start newEnd (Src.Binops (reverse newOps) newLast)
329+
return ( finalExpr, newEnd, newPos )
330+
]
331331

332332
, -- done
333333
let finalExpr = toCall expr args in

compiler/src/Parse/Primitives/Internals.hs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module Parse.Primitives.Internals
1212

1313

1414
import Prelude hiding (length)
15-
import qualified Control.Applicative as Applicative ( Applicative(..), Alternative(..) )
15+
import qualified Control.Applicative as Applicative (Applicative(..))
1616
import Control.Monad
1717
import qualified Data.ByteString.Internal as B
1818
import Foreign.ForeignPtr (ForeignPtr, withForeignPtr)
@@ -158,14 +158,6 @@ instance Applicative.Applicative Parser where
158158
(<*>) = ap
159159

160160

161-
instance Applicative.Alternative Parser where
162-
{-# INLINE empty #-}
163-
empty = allTheOptionsFailed
164-
165-
{-# INLINE (<|>) #-}
166-
(<|>) = oneOfHelp
167-
168-
169161
oneOf :: [Parser a] -> Parser a
170162
oneOf parsers =
171163
foldr oneOfHelp allTheOptionsFailed parsers

0 commit comments

Comments
 (0)