on master help sign in
Get rid of Alternative instance for Parser
commit35ac8af60cff89753bf8834843d2a67668522acf authorEvan Czaplicki <evancz@users.noreply.github.com> dateWed 10 Oct 2018, 20:24 (8 years ago) parentd5cbc41
2 files changed+27−35
compiler/src/Parse/Expression.hs+26−26 compiler/src/Parse/Primitives/Internals.hs+1−9
compiler/src/Parse/Expression.hs+26−26
@@ -6,8 +6,6 @@ module Parse.Expression
66 where
77
88
9−import Control.Monad (guard)
10−
119import qualified AST.Source as Src
1210import qualified Elm.Name as N
1311import 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+1−9
@@ -12,7 +12,7 @@ module Parse.Primitives.Internals
1212
1313
1414import Prelude hiding (length)
15−import qualified Control.Applicative as Applicative ( Applicative(..), Alternative(..) )
15+import qualified Control.Applicative as Applicative (Applicative(..))
1616import Control.Monad
1717import qualified Data.ByteString.Internal as B
1818import 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−
169161oneOf :: [Parser a] -> Parser a
170162oneOf parsers =
171163 foldr oneOfHelp allTheOptionsFailed parsers