Skip to content

Commit

Permalink
Implement failure in a less hackish way
Browse files Browse the repository at this point in the history
  • Loading branch information
emmabastas committed Jul 24, 2021
1 parent 092ebd1 commit 8d325a8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
17 changes: 12 additions & 5 deletions elm-format-lib/src/Parse/Helpers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import qualified Parse.State as State
import Parse.Comments
import Parse.IParser
import Parse.Whitespace
import qualified Parse.Primitives as EP
import qualified Reporting.Annotation as A
import qualified Reporting.Error.Syntax as Syntax
import qualified Reporting.Region as R
Expand Down Expand Up @@ -511,12 +512,18 @@ commentedKeyword elmVersion word parser =

-- ODD COMBINATORS

-- Behaves the same as `Parse.ParsecAdapter.fail` except that the consumed
-- continuation is called instead of the empty continuation.
failure :: String -> IParser String
failure msg = do
inp <- getInput
setInput ('x':inp)
_ <- anyToken
fail msg
failure msg =
EP.Parser $ \s _ _ cerr _ ->
let
(EP.Parser p) = fail msg
in
-- This looks really unsound, but `p` which was created with `fail` will
-- only ever call the empty error continuation (which in this case
-- re-routes to the consumed error continuation)
p s undefined undefined undefined cerr


until :: IParser a -> IParser b -> IParser b
Expand Down
19 changes: 0 additions & 19 deletions elm-format-lib/src/Parse/ParsecAdapter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ module Parse.ParsecAdapter
, skipMany
, runParserT
, getPosition
, getInput
, setInput
, getState
, updateState
-- Text.Parsec.Pos
Expand Down Expand Up @@ -311,23 +309,6 @@ getPosition =
return $ newPos sourceName row col


-- TODO: Figure out why this function is never reached by the test suite.
--
-- This function is needed for elm-format to compile, but leaving it undefined
-- doesn't cause any of the tests to fail.
-- Is there missing coverage in the test suite? Or is this function required by
-- dead code?
--
-- `setInput` is in the same situation.
getInput :: Parser String
getInput = undefined


-- TODO: See `getInput`
setInput :: String -> Parser ()
setInput = undefined


getState :: Parser State
getState =
do (EP.State _ _ _ _ _ _ _ newline) <- getParserState
Expand Down

0 comments on commit 8d325a8

Please # to comment.