diff --git a/src/Builder/Elm/Outline.elm b/src/Builder/Elm/Outline.elm index 8a6145dd3..8b9c9b426 100644 --- a/src/Builder/Elm/Outline.elm +++ b/src/Builder/Elm/Outline.elm @@ -527,10 +527,10 @@ boundParser bound tooLong = col + len in if len < bound then - Ok (P.POk P.Consumed (String.slice pos end src) (P.State src end end indent row newCol)) + P.Cok (String.slice pos end src) (P.State src end end indent row newCol) else - Err (P.PErr P.Consumed row newCol (\_ _ -> tooLong)) + P.Cerr row newCol (\_ _ -> tooLong) srcDirEncoder : SrcDir -> Encode.Value diff --git a/src/Compiler/Elm/Constraint.elm b/src/Compiler/Elm/Constraint.elm index ee7d5ca06..4fffd5cc0 100644 --- a/src/Compiler/Elm/Constraint.elm +++ b/src/Compiler/Elm/Constraint.elm @@ -241,10 +241,10 @@ parser = P.Parser <| \((P.State _ _ _ _ row col) as state) -> if V.compare lower higher == LT then - Ok (P.POk P.Empty (Range lower loOp hiOp higher) state) + P.Eok (Range lower loOp hiOp higher) state else - Err (P.PErr P.Empty row col (\_ _ -> InvalidRange lower higher)) + P.Eerr row col (\_ _ -> InvalidRange lower higher) ) ) ) diff --git a/src/Compiler/Elm/Docs.elm b/src/Compiler/Elm/Docs.elm index 0df6831e4..03a1c7271 100644 --- a/src/Compiler/Elm/Docs.elm +++ b/src/Compiler/Elm/Docs.elm @@ -438,7 +438,7 @@ chompUntilDocs = newState = P.State src newPos end indent newRow newCol in - Ok (P.POk P.Consumed isDocs newState) + P.Cok isDocs newState ) diff --git a/src/Compiler/Elm/Kernel.elm b/src/Compiler/Elm/Kernel.elm index aa3218ff9..584ec4cea 100644 --- a/src/Compiler/Elm/Kernel.elm +++ b/src/Compiler/Elm/Kernel.elm @@ -141,10 +141,10 @@ parseChunks vtable enums fields = chompChunks vtable enums fields src pos end row col pos [] in if newPos == end then - Ok (P.POk P.Consumed chunks (P.State src newPos end indent newRow newCol)) + P.Cok chunks (P.State src newPos end indent newRow newCol) else - Err (P.PErr P.Consumed row col toError) + P.Cerr row col toError ) diff --git a/src/Compiler/Elm/ModuleName.elm b/src/Compiler/Elm/ModuleName.elm index 9c59c8d0a..924b175b6 100644 --- a/src/Compiler/Elm/ModuleName.elm +++ b/src/Compiler/Elm/ModuleName.elm @@ -118,13 +118,13 @@ parser = newState = P.State src newPos end indent row newCol in - Ok (P.POk P.Consumed (String.slice pos newPos src) newState) + P.Cok (String.slice pos newPos src) newState else if col == newCol then - Err (P.PErr P.Empty row newCol Tuple.pair) + P.Eerr row newCol Tuple.pair else - Err (P.PErr P.Consumed row newCol Tuple.pair) + P.Cerr row newCol Tuple.pair ) diff --git a/src/Compiler/Elm/Package.elm b/src/Compiler/Elm/Package.elm index 4b168f8ab..ac9668ee8 100644 --- a/src/Compiler/Elm/Package.elm +++ b/src/Compiler/Elm/Package.elm @@ -289,7 +289,7 @@ parseName isGoodStart isGoodInner = P.Parser <| \(P.State src pos end indent row col) -> if pos >= end then - Err (P.PErr P.Empty row col Tuple.pair) + P.Eerr row col Tuple.pair else let @@ -298,7 +298,7 @@ parseName isGoodStart isGoodInner = P.unsafeIndex src pos in if not (isGoodStart word) then - Err (P.PErr P.Empty row col Tuple.pair) + P.Eerr row col Tuple.pair else let @@ -319,10 +319,10 @@ parseName isGoodStart isGoodInner = newState = P.State src newPos end indent row newCol in - Ok (P.POk P.Consumed (String.slice pos newPos src) newState) + P.Cok (String.slice pos newPos src) newState else - Err (P.PErr P.Consumed row newCol Tuple.pair) + P.Cerr row newCol Tuple.pair isLower : Char -> Bool diff --git a/src/Compiler/Elm/Version.elm b/src/Compiler/Elm/Version.elm index 17a6c4e97..a4079bc31 100644 --- a/src/Compiler/Elm/Version.elm +++ b/src/Compiler/Elm/Version.elm @@ -181,7 +181,7 @@ numberParser = P.Parser <| \(P.State src pos end indent row col) -> if pos >= end then - Err (P.PErr P.Empty row col Tuple.pair) + P.Eerr row col Tuple.pair else let @@ -195,7 +195,7 @@ numberParser = newState = P.State src (pos + 1) end indent row (col + 1) in - Ok (P.POk P.Consumed 0 newState) + P.Cok 0 newState else if isDigit word then let @@ -206,10 +206,10 @@ numberParser = newState = P.State src newPos end indent row (col + (newPos - pos)) in - Ok (P.POk P.Consumed total newState) + P.Cok total newState else - Err (P.PErr P.Empty row col Tuple.pair) + P.Eerr row col Tuple.pair chompWord16 : String -> Int -> Int -> Int -> ( Int, Int ) diff --git a/src/Compiler/Generate/JavaScript/Builder.elm b/src/Compiler/Generate/JavaScript/Builder.elm index 3e3e43d76..c0911fc90 100644 --- a/src/Compiler/Generate/JavaScript/Builder.elm +++ b/src/Compiler/Generate/JavaScript/Builder.elm @@ -275,7 +275,7 @@ makeLevel level oldTabs = oldTabs else - String.repeat (String.length oldTabs * 2) "\t" + oldTabs ++ oldTabs in Level (String.left level tabs) (\_ -> makeLevel (level + 1) tabs) diff --git a/src/Compiler/Json/Decode.elm b/src/Compiler/Json/Decode.elm index 431160056..1afe64024 100644 --- a/src/Compiler/Json/Decode.elm +++ b/src/Compiler/Json/Decode.elm @@ -709,13 +709,13 @@ pString start = newState = P.State src newPos end indent newRow newCol in - Ok (P.POk P.Consumed snp newState) + P.Cok snp newState BadString problem -> - Err (P.PErr P.Consumed newRow newCol (StringProblem problem)) + P.Cerr newRow newCol (StringProblem problem) else - Err (P.PErr P.Empty row col start) + P.Eerr row col start type StringStatus @@ -838,7 +838,7 @@ spaces = eatSpaces src pos end row col in if pos == newPos then - Ok (P.POk P.Empty () state) + P.Eok () state else let @@ -846,7 +846,7 @@ spaces = newState = P.State src newPos end indent newRow newCol in - Ok (P.POk P.Consumed () newState) + P.Cok () newState eatSpaces : String -> Int -> Int -> Row -> Col -> ( Int, Row, Col ) @@ -882,7 +882,7 @@ pInt = P.Parser <| \(P.State src pos end indent row col) -> if pos >= end then - Err (P.PErr P.Empty row col Start) + P.Eerr row col Start else let @@ -891,7 +891,7 @@ pInt = P.unsafeIndex src pos in if not (isDecimalDigit word) then - Err (P.PErr P.Empty row col Start) + P.Eerr row col Start else if word == '0' then let @@ -910,16 +910,16 @@ pInt = P.unsafeIndex src pos1 in if isDecimalDigit word1 then - Err (P.PErr P.Consumed row (col + 1) NoLeadingZeros) + P.Cerr row (col + 1) NoLeadingZeros else if word1 == '.' then - Err (P.PErr P.Consumed row (col + 1) NoFloats) + P.Cerr row (col + 1) NoFloats else - Ok (P.POk P.Consumed (Int 0) newState) + P.Cok (Int 0) newState else - Ok (P.POk P.Consumed (Int 0) newState) + P.Cok (Int 0) newState else let @@ -937,10 +937,10 @@ pInt = newState = P.State src newPos end indent row (col + len) in - Ok (P.POk P.Consumed (Int n) newState) + P.Cok (Int n) newState BadIntEnd -> - Err (P.PErr P.Consumed row (col + len) NoFloats) + P.Cerr row (col + len) NoFloats type IntStatus diff --git a/src/Compiler/Parse/Declaration.elm b/src/Compiler/Parse/Declaration.elm index 972175d76..164a85db2 100644 --- a/src/Compiler/Parse/Declaration.elm +++ b/src/Compiler/Parse/Declaration.elm @@ -141,15 +141,26 @@ chompMatchingName expectedName = in P.Parser <| \((P.State _ _ _ _ sr sc) as state) -> - Result.andThen - (\(P.POk status name ((P.State _ _ _ _ er ec) as newState)) -> + case parserL state of + P.Cok name ((P.State _ _ _ _ er ec) as newState) -> if expectedName == name then - Ok (P.POk status (A.At (A.Region (A.Position sr sc) (A.Position er ec)) name) newState) + P.Cok (A.At (A.Region (A.Position sr sc) (A.Position er ec)) name) newState else - Err (P.PErr status sr sc (E.DeclDefNameMatch name)) - ) - (parserL state) + P.Cerr sr sc (E.DeclDefNameMatch name) + + P.Eok name ((P.State _ _ _ _ er ec) as newState) -> + if expectedName == name then + P.Eok (A.At (A.Region (A.Position sr sc) (A.Position er ec)) name) newState + + else + P.Eerr sr sc (E.DeclDefNameMatch name) + + P.Cerr r c t -> + P.Cerr r c t + + P.Eerr r c t -> + P.Eerr r c t diff --git a/src/Compiler/Parse/Expression.elm b/src/Compiler/Parse/Expression.elm index fe5b60ed5..6e16b712e 100644 --- a/src/Compiler/Parse/Expression.elm +++ b/src/Compiler/Parse/Expression.elm @@ -814,15 +814,26 @@ chompMatchingName expectedName = in P.Parser <| \((P.State _ _ _ _ sr sc) as state) -> - Result.andThen - (\(P.POk status name ((P.State _ _ _ _ er ec) as newState)) -> + case parserL state of + P.Cok name ((P.State _ _ _ _ er ec) as newState) -> if expectedName == name then - Ok (P.POk status (A.At (A.Region (A.Position sr sc) (A.Position er ec)) name) newState) + P.Cok (A.At (A.Region (A.Position sr sc) (A.Position er ec)) name) newState else - Err (P.PErr status sr sc (E.DefNameMatch name)) - ) - (parserL state) + P.Cerr sr sc (E.DefNameMatch name) + + P.Eok name ((P.State _ _ _ _ er ec) as newState) -> + if expectedName == name then + P.Eok (A.At (A.Region (A.Position sr sc) (A.Position er ec)) name) newState + + else + P.Eerr sr sc (E.DefNameMatch name) + + P.Cerr r c t -> + P.Cerr r c t + + P.Eerr r c t -> + P.Eerr r c t diff --git a/src/Compiler/Parse/Keyword.elm b/src/Compiler/Parse/Keyword.elm index ffb822598..db71d5972 100644 --- a/src/Compiler/Parse/Keyword.elm +++ b/src/Compiler/Parse/Keyword.elm @@ -192,10 +192,10 @@ subscription_ toError = s = P.State src pos12 end indent row (col + 12) in - Ok (P.POk P.Consumed () s) + P.Cok () s else - Err (P.PErr P.Empty row col toError) + P.Eerr row col toError @@ -222,10 +222,10 @@ k2 w1 w2 toError = s = P.State src pos2 end indent row (col + 2) in - Ok (P.POk P.Consumed () s) + P.Cok () s else - Err (P.PErr P.Empty row col toError) + P.Eerr row col toError k3 : Char -> Char -> Char -> (Row -> Col -> x) -> Parser x () @@ -249,10 +249,10 @@ k3 w1 w2 w3 toError = s = P.State src pos3 end indent row (col + 3) in - Ok (P.POk P.Consumed () s) + P.Cok () s else - Err (P.PErr P.Empty row col toError) + P.Eerr row col toError k4 : Char -> Char -> Char -> Char -> (Row -> Col -> x) -> Parser x () @@ -277,10 +277,10 @@ k4 w1 w2 w3 w4 toError = s = P.State src pos4 end indent row (col + 4) in - Ok (P.POk P.Consumed () s) + P.Cok () s else - Err (P.PErr P.Empty row col toError) + P.Eerr row col toError k5 : Char -> Char -> Char -> Char -> Char -> (Row -> Col -> x) -> Parser x () @@ -306,10 +306,10 @@ k5 w1 w2 w3 w4 w5 toError = s = P.State src pos5 end indent row (col + 5) in - Ok (P.POk P.Consumed () s) + P.Cok () s else - Err (P.PErr P.Empty row col toError) + P.Eerr row col toError k6 : Char -> Char -> Char -> Char -> Char -> Char -> (Row -> Col -> x) -> Parser x () @@ -336,10 +336,10 @@ k6 w1 w2 w3 w4 w5 w6 toError = s = P.State src pos6 end indent row (col + 6) in - Ok (P.POk P.Consumed () s) + P.Cok () s else - Err (P.PErr P.Empty row col toError) + P.Eerr row col toError k7 : Char -> Char -> Char -> Char -> Char -> Char -> Char -> (Row -> Col -> x) -> Parser x () @@ -367,10 +367,10 @@ k7 w1 w2 w3 w4 w5 w6 w7 toError = s = P.State src pos7 end indent row (col + 7) in - Ok (P.POk P.Consumed () s) + P.Cok () s else - Err (P.PErr P.Empty row col toError) + P.Eerr row col toError k8 : Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> (Row -> Col -> x) -> Parser x () @@ -399,7 +399,7 @@ k8 w1 w2 w3 w4 w5 w6 w7 w8 toError = s = P.State src pos8 end indent row (col + 8) in - Ok (P.POk P.Consumed () s) + P.Cok () s else - Err (P.PErr P.Empty row col toError) + P.Eerr row col toError diff --git a/src/Compiler/Parse/Number.elm b/src/Compiler/Parse/Number.elm index f8a9bcfa5..abd5642fd 100644 --- a/src/Compiler/Parse/Number.elm +++ b/src/Compiler/Parse/Number.elm @@ -41,7 +41,7 @@ number toExpectation toError = P.Parser <| \(P.State src pos end indent row col) -> if pos >= end then - Err (P.PErr P.Empty row col toExpectation) + P.Eerr row col toExpectation else let @@ -50,7 +50,7 @@ number toExpectation toError = String.uncons (String.dropLeft pos src) |> Maybe.map Tuple.first |> Maybe.withDefault ' ' in if not (isDecimalDigit word) then - Err (P.PErr P.Empty row col toExpectation) + P.Eerr row col toExpectation else let @@ -69,7 +69,7 @@ number toExpectation toError = newCol = col + (newPos - pos) in - Err (P.PErr P.Consumed row newCol (toError problem)) + P.Cerr row newCol (toError problem) OkInt newPos n -> let @@ -85,7 +85,7 @@ number toExpectation toError = newState = P.State src newPos end indent row newCol in - Ok (P.POk P.Consumed integer newState) + P.Cok integer newState OkFloat newPos -> let @@ -110,7 +110,7 @@ number toExpectation toError = newState = P.State src newPos end indent row newCol in - Ok (P.POk P.Consumed float newState) + P.Cok float newState @@ -349,7 +349,7 @@ precedence toExpectation = P.Parser <| \(P.State src pos end indent row col) -> if pos >= end then - Err (P.PErr P.Empty row col toExpectation) + P.Eerr row col toExpectation else let @@ -358,11 +358,9 @@ precedence toExpectation = String.uncons (String.dropLeft pos src) |> Maybe.map Tuple.first |> Maybe.withDefault ' ' in if isDecimalDigit word then - Ok - (P.POk P.Consumed - (Char.toCode word - Char.toCode '0') - (P.State src (pos + 1) end indent row (col + 1)) - ) + P.Cok + (Char.toCode word - Char.toCode '0') + (P.State src (pos + 1) end indent row (col + 1)) else - Err (P.PErr P.Empty row col toExpectation) + P.Eerr row col toExpectation diff --git a/src/Compiler/Parse/Pattern.elm b/src/Compiler/Parse/Pattern.elm index 034566781..64099b49d 100644 --- a/src/Compiler/Parse/Pattern.elm +++ b/src/Compiler/Parse/Pattern.elm @@ -80,7 +80,7 @@ termHelp syntaxVersion start = String.fromFloat float |> String.length in - Err (P.PErr P.Consumed row (col - width) (E.PFloat width)) + P.Cerr row (col - width) (E.PFloat width) ) ) , String.string E.PStart E.PString @@ -99,7 +99,7 @@ wildcard syntaxVersion = P.Parser <| \(P.State src pos end indent row col) -> if pos == end || P.unsafeIndex src pos /= '_' then - Err (P.PErr P.Empty row col E.PStart) + P.Eerr row col E.PStart else let @@ -118,7 +118,7 @@ wildcard syntaxVersion = ( badPos, badCol ) = Var.chompInnerChars src newPos end newCol in - Err (P.PErr P.Consumed row col (E.PWildcardNotVar (Name.fromPtr src pos badPos) (badCol - col))) + P.Cerr row col (E.PWildcardNotVar (Name.fromPtr src pos badPos) (badCol - col)) SV.Guida -> let @@ -130,7 +130,7 @@ wildcard syntaxVersion = Name.fromPtr src newPos lowerPos in if Var.isReservedWord name then - Err (P.PErr P.Consumed row col (E.PWildcardReservedWord (Name.fromPtr src newPos lowerPos) (lowerCol - col))) + P.Cerr row col (E.PWildcardReservedWord (Name.fromPtr src newPos lowerPos) (lowerCol - col)) else let @@ -138,7 +138,7 @@ wildcard syntaxVersion = newState = P.State src lowerPos end indent row lowerCol in - Ok (P.POk P.Consumed name newState) + P.Cok name newState else let @@ -146,7 +146,7 @@ wildcard syntaxVersion = newState = P.State src newPos end indent row newCol in - Ok (P.POk P.Consumed "" newState) + P.Cok "" newState diff --git a/src/Compiler/Parse/Primitives.elm b/src/Compiler/Parse/Primitives.elm index a10a47fee..1a65b4fb4 100644 --- a/src/Compiler/Parse/Primitives.elm +++ b/src/Compiler/Parse/Primitives.elm @@ -1,12 +1,10 @@ module Compiler.Parse.Primitives exposing ( Col - , PErr(..) - , POk(..) + , PStep(..) , Parser(..) , Row , Snippet(..) , State(..) - , Status(..) , Step(..) , addEnd , addLocation @@ -43,20 +41,14 @@ import Utils.Crash exposing (crash) type Parser x a - = Parser (State -> Result (PErr x) (POk a)) + = Parser (State -> PStep x a) -type POk a - = POk Status a State - - -type PErr x - = PErr Status Row Col (Row -> Col -> x) - - -type Status - = Consumed - | Empty +type PStep x a + = Cok a State + | Eok a State + | Cerr Row Col (Row -> Col -> x) + | Eerr Row Col (Row -> Col -> x) type State @@ -80,11 +72,18 @@ fmap : (a -> b) -> Parser x a -> Parser x b fmap f (Parser parser) = Parser (\state -> - Result.map - (\(POk status a s) -> - POk status (f a) s - ) - (parser state) + case parser state of + Cok a s -> + Cok (f a) s + + Eok a s -> + Eok (f a) s + + Cerr r c t -> + Cerr r c t + + Eerr r c t -> + Eerr r c t ) @@ -100,12 +99,12 @@ oneOf toError parsers = ) -oneOfHelp : State -> (Row -> Col -> x) -> List (Parser x a) -> Result (PErr x) (POk a) +oneOfHelp : State -> (Row -> Col -> x) -> List (Parser x a) -> PStep x a oneOfHelp state toError parsers = case parsers of (Parser parser) :: remainingParsers -> case parser state of - Err (PErr Empty _ _ _) -> + Eerr _ _ _ -> oneOfHelp state toError remainingParsers result -> @@ -116,7 +115,7 @@ oneOfHelp state toError parsers = (State _ _ _ _ row col) = state in - Err (PErr Empty row col toError) + Eerr row col toError @@ -128,15 +127,15 @@ oneOfWithFallback parsers fallback = Parser (\state -> oowfHelp state parsers fallback) -oowfHelp : State -> List (Parser x a) -> a -> Result (PErr x) (POk a) +oowfHelp : State -> List (Parser x a) -> a -> PStep x a oowfHelp state parsers fallback = case parsers of [] -> - Ok (POk Empty fallback state) + Eok fallback state (Parser parser) :: remainingParsers -> case parser state of - Err (PErr Empty _ _ _) -> + Eerr _ _ _ -> oowfHelp state remainingParsers fallback result -> @@ -149,20 +148,37 @@ oowfHelp state parsers fallback = pure : a -> Parser x a pure value = - Parser (\state -> Ok (POk Empty value state)) + Parser (\state -> Eok value state) bind : (a -> Parser x b) -> Parser x a -> Parser x b bind callback (Parser parserA) = Parser (\state -> - Result.andThen - (\(POk _ a s) -> + case parserA state of + Cok a s -> + case callback a of + Parser parserB -> + case parserB s of + Eok a_ s_ -> + Cok a_ s_ + + Eerr r c t -> + Cerr r c t + + result -> + result + + Eok a s -> case callback a of Parser parserB -> parserB s - ) - (parserA state) + + Cerr r c t -> + Cerr r c t + + Eerr r c t -> + Eerr r c t ) @@ -178,10 +194,16 @@ fromByteString (Parser parser) toBadEnd src = State src 0 (String.length src) 0 1 1 in case parser initialState of - Ok (POk _ a state) -> + Cok a state -> toOk toBadEnd a state - Err (PErr _ row col toError) -> + Eok a state -> + toOk toBadEnd a state + + Cerr row col toError -> + toErr row col toError + + Eerr row col toError -> toErr row col toError @@ -221,10 +243,16 @@ fromSnippet (Parser parser) toBadEnd (Snippet { fptr, offset, length, offRow, of State fptr offset (offset + length) 0 offRow offCol in case parser initialState of - Ok (POk _ a state) -> + Cok a state -> + toOk toBadEnd a state + + Eok a state -> toOk toBadEnd a state - Err (PErr _ row col toError) -> + Cerr row col toError -> + toErr row col toError + + Eerr row col toError -> toErr row col toError @@ -236,7 +264,7 @@ getPosition : Parser x A.Position getPosition = Parser (\((State _ _ _ _ row col) as state) -> - Ok (POk Empty (A.Position row col) state) + Eok (A.Position row col) state ) @@ -245,11 +273,17 @@ addLocation (Parser parser) = Parser (\((State _ _ _ _ sr sc) as state) -> case parser state of - Ok (POk status a ((State _ _ _ _ er ec) as s)) -> - Ok (POk status (A.At (A.Region (A.Position sr sc) (A.Position er ec)) a) s) + Cok a ((State _ _ _ _ er ec) as s) -> + Cok (A.At (A.Region (A.Position sr sc) (A.Position er ec)) a) s + + Eok a ((State _ _ _ _ er ec) as s) -> + Eok (A.At (A.Region (A.Position sr sc) (A.Position er ec)) a) s + + Cerr r c t -> + Cerr r c t - Err err -> - Err err + Eerr r c t -> + Eerr r c t ) @@ -257,7 +291,7 @@ addEnd : A.Position -> a -> Parser x (A.Located a) addEnd start value = Parser (\((State _ _ _ _ row col) as state) -> - Ok (POk Empty (A.at start (A.Position row col) value) state) + Eok (A.at start (A.Position row col) value) state ) @@ -270,11 +304,14 @@ withIndent (Parser parser) = Parser (\(State src pos end oldIndent row col) -> case parser (State src pos end col row col) of - Ok (POk status a (State s p e _ r c)) -> - Ok (POk status a (State s p e oldIndent r c)) + Cok a (State s p e _ r c) -> + Cok a (State s p e oldIndent r c) - Err err -> - Err err + Eok a (State s p e _ r c) -> + Eok a (State s p e oldIndent r c) + + err -> + err ) @@ -283,11 +320,14 @@ withBacksetIndent backset (Parser parser) = Parser (\(State src pos end oldIndent row col) -> case parser (State src pos end (col - backset) row col) of - Ok (POk status a (State s p e _ r c)) -> - Ok (POk status a (State s p e oldIndent r c)) + Cok a (State s p e _ r c) -> + Cok a (State s p e oldIndent r c) + + Eok a (State s p e _ r c) -> + Eok a (State s p e oldIndent r c) - Err err -> - Err err + err -> + err ) @@ -298,31 +338,60 @@ withBacksetIndent backset (Parser parser) = inContext : (x -> Row -> Col -> y) -> Parser y start -> Parser x a -> Parser y a inContext addContext (Parser parserStart) (Parser parserA) = Parser - (\state -> + (\((State _ _ _ _ row col) as state) -> case parserStart state of - Ok (POk _ _ okState) -> - case parserA okState of - Ok res -> - Ok res + Cok _ s -> + case parserA s of + Cok a s_ -> + Cok a s_ + + Eok a s_ -> + Cok a s_ - Err (PErr status r c tx) -> - Err (PErr status r c (addContext (tx r c))) + Cerr r c tx -> + Cerr row col (addContext (tx r c)) - Err err -> - Err err + Eerr r c tx -> + Cerr row col (addContext (tx r c)) + + Eok _ s -> + case parserA s of + Cok a s_ -> + Cok a s_ + + Eok a s_ -> + Eok a s_ + + Cerr r c tx -> + Cerr row col (addContext (tx r c)) + + Eerr r c tx -> + Eerr row col (addContext (tx r c)) + + Cerr r c t -> + Cerr r c t + + Eerr r c t -> + Eerr r c t ) specialize : (x -> Row -> Col -> y) -> Parser x a -> Parser y a specialize addContext (Parser parser) = Parser - (\state -> + (\((State _ _ _ _ row col) as state) -> case parser state of - Ok res -> - Ok res + Cok a s -> + Cok a s + + Eok a s -> + Eok a s + + Cerr r c tx -> + Cerr row col (addContext (tx r c)) - Err (PErr status r c tx) -> - Err (PErr status r c (addContext (tx r c))) + Eerr r c tx -> + Eerr row col (addContext (tx r c)) ) @@ -340,10 +409,10 @@ word1 word toError = newState = State src (pos + 1) end indent row (col + 1) in - Ok (POk Consumed () newState) + Cok () newState else - Err (PErr Empty row col toError) + Eerr row col toError ) @@ -356,16 +425,16 @@ word2 w1 w2 toError = pos1 = pos + 1 in - if pos < end && unsafeIndex src pos == w1 && unsafeIndex src pos1 == w2 then + if pos1 < end && unsafeIndex src pos == w1 && unsafeIndex src pos1 == w2 then let newState : State newState = State src (pos + 2) end indent row (col + 2) in - Ok (POk Consumed () newState) + Cok () newState else - Err (PErr Empty row col toError) + Eerr row col toError ) @@ -445,7 +514,7 @@ loop : (state -> Parser x (Step state a)) -> state -> Parser x a loop callback loopState = Parser (\state -> - loopHelp callback state loopState (\a s -> Ok (POk Empty a s)) (\row col toError -> Err (PErr Empty row col toError)) + loopHelp callback state loopState Eok Eerr ) @@ -453,31 +522,27 @@ loopHelp : (state -> Parser x (Step state a)) -> State -> state - -> (a -> State -> Result (PErr x) (POk a)) - -> (Row -> Col -> (Row -> Col -> x) -> Result (PErr x) (POk a)) - -> Result (PErr x) (POk a) + -> (a -> State -> PStep x a) + -> (Row -> Col -> (Row -> Col -> x) -> PStep x a) + -> PStep x a loopHelp callback state loopState eok eerr = case callback loopState of Parser parser -> case parser state of - Ok (POk Consumed (Loop newLoopState) newState) -> - loopHelp callback - newState - newLoopState - (\a s -> Ok (POk Consumed a s)) - (\row col toError -> Err (PErr Consumed row col toError)) + Cok (Loop newLoopState) newState -> + loopHelp callback newState newLoopState Cok Cerr - Ok (POk Consumed (Done a) newState) -> - Ok (POk Consumed a newState) + Cok (Done a) newState -> + Cok a newState - Ok (POk Empty (Loop newLoopState) newState) -> + Eok (Loop newLoopState) newState -> loopHelp callback newState newLoopState eok eerr - Ok (POk Empty (Done a) newState) -> + Eok (Done a) newState -> eok a newState - Err (PErr Consumed r c t) -> - Err (PErr Consumed r c t) + Cerr r c t -> + Cerr r c t - Err (PErr Empty r c t) -> + Eerr r c t -> eerr r c t diff --git a/src/Compiler/Parse/Shader.elm b/src/Compiler/Parse/Shader.elm index 1e7cc4423..7e6f046aa 100644 --- a/src/Compiler/Parse/Shader.elm +++ b/src/Compiler/Parse/Shader.elm @@ -77,13 +77,13 @@ parseBlock = newState = P.State src (newPos + 2) end indent newRow (newCol + 2) in - Ok (P.POk P.Consumed block newState) + P.Cok block newState Unending -> - Err (P.PErr P.Consumed row col E.EndlessShader) + P.Cerr row col E.EndlessShader else - Err (P.PErr P.Empty row col E.Start) + P.Eerr row col E.Start type Status @@ -172,7 +172,7 @@ failure : Row -> Col -> String -> Parser E.Expr a failure row col msg = P.Parser <| \_ -> - Err (P.PErr P.Consumed row col (E.ShaderProblem msg)) + P.Cerr row col (E.ShaderProblem msg) diff --git a/src/Compiler/Parse/Space.elm b/src/Compiler/Parse/Space.elm index 223abf7ac..e45c4a414 100644 --- a/src/Compiler/Parse/Space.elm +++ b/src/Compiler/Parse/Space.elm @@ -41,13 +41,13 @@ chomp toError = newState = P.State src newPos end indent newRow newCol in - Ok (P.POk P.Consumed () newState) + P.Cok () newState HasTab -> - Err (P.PErr P.Consumed newRow newCol (toError E.HasTab)) + P.Cerr newRow newCol (toError E.HasTab) EndlessMultiComment -> - Err (P.PErr P.Consumed newRow newCol (toError E.EndlessMultiComment)) + P.Cerr newRow newCol (toError E.EndlessMultiComment) @@ -59,10 +59,10 @@ checkIndent (A.Position endRow endCol) toError = P.Parser <| \((P.State _ _ _ indent _ col) as state) -> if col > indent && col > 1 then - Ok (P.POk P.Empty () state) + P.Eok () state else - Err (P.PErr P.Empty endRow endCol toError) + P.Eerr endRow endCol toError checkAligned : (Int -> Int -> Int -> x) -> P.Parser x () @@ -70,10 +70,10 @@ checkAligned toError = P.Parser <| \((P.State _ _ _ indent row col) as state) -> if col == indent then - Ok (P.POk P.Empty () state) + P.Eok () state else - Err (P.PErr P.Empty row col (toError indent)) + P.Eerr row col (toError indent) checkFreshLine : (Row -> Col -> x) -> P.Parser x () @@ -81,10 +81,10 @@ checkFreshLine toError = P.Parser <| \((P.State _ _ _ _ row col) as state) -> if col == 1 then - Ok (P.POk P.Empty () state) + P.Eok () state else - Err (P.PErr P.Empty row col toError) + P.Eerr row col toError @@ -107,16 +107,16 @@ chompAndCheckIndent toSpaceError toIndentError = newState = P.State src newPos end indent newRow newCol in - Ok (P.POk P.Consumed () newState) + P.Cok () newState else - Err (P.PErr P.Consumed row col toIndentError) + P.Cerr row col toIndentError HasTab -> - Err (P.PErr P.Consumed newRow newCol (toSpaceError E.HasTab)) + P.Cerr newRow newCol (toSpaceError E.HasTab) EndlessMultiComment -> - Err (P.PErr P.Consumed newRow newCol (toSpaceError E.EndlessMultiComment)) + P.Cerr newRow newCol (toSpaceError E.EndlessMultiComment) @@ -336,13 +336,13 @@ docComment toExpectation toSpaceError = newState = P.State src newPos end indent newRow newCol in - Ok (P.POk P.Consumed comment newState) + P.Cok comment newState MultiTab -> - Err (P.PErr P.Consumed newRow newCol (toSpaceError E.HasTab)) + P.Cerr newRow newCol (toSpaceError E.HasTab) MultiEndless -> - Err (P.PErr P.Consumed row col (toSpaceError E.EndlessMultiComment)) + P.Cerr row col (toSpaceError E.EndlessMultiComment) else - Err (P.PErr P.Empty row col toExpectation) + P.Eerr row col toExpectation diff --git a/src/Compiler/Parse/String.elm b/src/Compiler/Parse/String.elm index d35b764fa..c29b3c1bd 100644 --- a/src/Compiler/Parse/String.elm +++ b/src/Compiler/Parse/String.elm @@ -18,13 +18,13 @@ character toExpectation toError = Parser (\(P.State src pos end indent row col) -> if pos >= end || P.unsafeIndex src pos /= '\'' then - Err (P.PErr P.Empty row col toExpectation) + P.Eerr row col toExpectation else case chompChar src (pos + 1) end row (col + 1) 0 placeholder of Good newPos newCol numChars mostRecent -> if numChars /= 1 then - Err (P.PErr P.Consumed row col (toError (E.CharNotString (newCol - col)))) + P.Cerr row col (toError (E.CharNotString (newCol - col))) else let @@ -36,13 +36,13 @@ character toExpectation toError = char = ES.fromChunks src [ mostRecent ] in - Ok (P.POk P.Consumed char newState) + P.Cok char newState CharEndless newCol -> - Err (P.PErr P.Consumed row newCol (toError E.CharEndless)) + P.Cerr row newCol (toError E.CharEndless) CharEscape r c escape -> - Err (P.PErr P.Consumed r c (toError (E.CharEscape escape))) + P.Cerr r c (toError (E.CharEscape escape)) ) @@ -144,13 +144,13 @@ string toExpectation toError = newState = P.State src newPos end indent newRow newCol in - Ok (P.POk P.Consumed utf8 newState) + P.Cok utf8 newState SRErr r c x -> - Err (P.PErr P.Consumed r c (toError x)) + P.Cerr r c (toError x) else - Err (P.PErr P.Empty row col toExpectation) + P.Eerr row col toExpectation ) diff --git a/src/Compiler/Parse/Symbol.elm b/src/Compiler/Parse/Symbol.elm index 326b12b4e..23d0589df 100644 --- a/src/Compiler/Parse/Symbol.elm +++ b/src/Compiler/Parse/Symbol.elm @@ -35,24 +35,24 @@ operator toExpectation toError = chompOps src pos end in if pos == newPos then - Err (P.PErr P.Empty row col toExpectation) + P.Eerr row col toExpectation else case String.slice pos newPos src of "." -> - Err (P.PErr P.Empty row col (toError BadDot)) + P.Eerr row col (toError BadDot) "|" -> - Err (P.PErr P.Consumed row col (toError BadPipe)) + P.Cerr row col (toError BadPipe) "->" -> - Err (P.PErr P.Consumed row col (toError BadArrow)) + P.Cerr row col (toError BadArrow) "=" -> - Err (P.PErr P.Consumed row col (toError BadEquals)) + P.Cerr row col (toError BadEquals) ":" -> - Err (P.PErr P.Consumed row col (toError BadHasType)) + P.Cerr row col (toError BadHasType) op -> let @@ -64,7 +64,7 @@ operator toExpectation toError = newState = P.State src newPos end indent row newCol in - Ok (P.POk P.Consumed op newState) + P.Cok op newState chompOps : String -> Int -> Int -> Int diff --git a/src/Compiler/Parse/Variable.elm b/src/Compiler/Parse/Variable.elm index 6d1f27c7c..2a5b8464c 100644 --- a/src/Compiler/Parse/Variable.elm +++ b/src/Compiler/Parse/Variable.elm @@ -33,7 +33,7 @@ upper toError = chompUpper src pos end col in if newPos == pos then - Err (P.PErr P.Empty row col toError) + P.Eerr row col toError else let @@ -41,7 +41,7 @@ upper toError = name = Name.fromPtr src pos newPos in - Ok (P.POk P.Consumed name (P.State src newPos end indent row newCol)) + P.Cok name (P.State src newPos end indent row newCol) @@ -57,7 +57,7 @@ lower toError = chompLower src pos end col in if newPos == pos then - Err (P.PErr P.Empty row col toError) + P.Eerr row col toError else let @@ -66,7 +66,7 @@ lower toError = Name.fromPtr src pos newPos in if isReservedWord name then - Err (P.PErr P.Empty row col toError) + P.Eerr row col toError else let @@ -74,7 +74,7 @@ lower toError = newState = P.State src newPos end indent row newCol in - Ok (P.POk P.Consumed name newState) + P.Cok name newState isReservedWord : Name.Name -> Bool @@ -115,7 +115,7 @@ moduleName toError = chompUpper src pos end col in if pos == pos1 then - Err (P.PErr P.Empty row col toError) + P.Eerr row col toError else let @@ -133,10 +133,10 @@ moduleName toError = newState = P.State src newPos end indent row newCol in - Ok (P.POk P.Consumed name newState) + P.Cok name newState Bad -> - Err (P.PErr P.Consumed row newCol toError) + P.Cerr row newCol toError type ModuleNameStatus @@ -183,7 +183,7 @@ foreignUpper toError = foreignUpperHelp src pos end col in if upperStart == upperEnd then - Err (P.PErr P.Empty row newCol toError) + P.Eerr row newCol toError else let @@ -208,7 +208,7 @@ foreignUpper toError = in Qualified home name in - Ok (P.POk P.Consumed upperName newState) + P.Cok upperName newState foreignUpperHelp : String -> Int -> Int -> Col -> ( Int, Int, Col ) @@ -240,7 +240,7 @@ foreignAlpha toError = foreignAlphaHelp src pos end col in if alphaStart == alphaEnd then - Err (P.PErr P.Empty row newCol toError) + P.Eerr row newCol toError else let @@ -254,10 +254,10 @@ foreignAlpha toError = in if alphaStart == pos then if isReservedWord name then - Err (P.PErr P.Empty row col toError) + P.Eerr row col toError else - Ok (P.POk P.Consumed (Src.Var varType name) newState) + P.Cok (Src.Var varType name) newState else let @@ -265,7 +265,7 @@ foreignAlpha toError = home = Name.fromPtr src pos (alphaStart + -1) in - Ok (P.POk P.Consumed (Src.VarQual varType home name) newState) + P.Cok (Src.VarQual varType home name) newState foreignAlphaHelp : String -> Int -> Int -> Col -> ( ( Int, Int ), ( Col, Src.VarType ) ) diff --git a/src/Text/PrettyPrint/ANSI/Leijen.elm b/src/Text/PrettyPrint/ANSI/Leijen.elm index 4c0237c99..2b3d6bd95 100644 --- a/src/Text/PrettyPrint/ANSI/Leijen.elm +++ b/src/Text/PrettyPrint/ANSI/Leijen.elm @@ -310,15 +310,20 @@ hang = hcat : List Doc -> Doc hcat docs = + hcatHelp docs empty + + +hcatHelp : List Doc -> Doc -> Doc +hcatHelp docs acc = case docs of [] -> - empty + acc [ doc ] -> doc doc :: ds -> - P.append doc (hcat ds) + hcatHelp ds (P.append doc acc) hsep : List Doc -> Doc