on master help sign in
Make sure infixOp always eats characters
fcf5cefEvan Czaplicki
src/Parse/Primitives.hs+15−10
@@ -385,6 +385,7 @@ infixOp =
385 Parser $ \(State array offset length indent row col) cok cerr _ eerr ->
385 Parser $ \(State array offset length indent row col) cok cerr _ eerr ->
386 if length == 0 then
386 if length == 0 then
387 eerr (Error row col)
387 eerr (Error row col)
388+
388 else
389 else
389 case infixOpHelp array offset length row col of
390 case infixOpHelp array offset length row col of
390 Left err ->
391 Left err ->
@@ -392,21 +393,25 @@ infixOp =
392
393
393 Right ( newOffset, newLength, newCol ) ->
394 Right ( newOffset, newLength, newCol ) ->
394 let
395 let
395− !newSize =
396+ !size =
396 newOffset - offset
397 newOffset - offset
397
398
398 makeArray =
399 makeArray =
399− do mutableArray <- Text.new newSize
400+ do mutableArray <- Text.new size
400− Text.copyI mutableArray 0 array offset newSize
401+ Text.copyI mutableArray 0 array offset size
401 return mutableArray
402 return mutableArray
402 in
403 in
404+ if size == 0 then
405+ eerr (Error row col)
406+
407+ else
403− case Text.Text (Text.run makeArray) 0 newSize of
408+ case Text.Text (Text.run makeArray) 0 size of
404− "=" -> cerr (Error row col) -- "The = operator is reserved for defining variables. Maybe you want == instead? Or maybe you are defining a variable, but there is whitespace before it?"
409+ "=" -> cerr (Error row col) -- "The = operator is reserved for defining variables. Maybe you want == instead? Or maybe you are defining a variable, but there is whitespace before it?"
405− "->" -> cerr (Error row col) -- "Arrows are reserved for cases and anonymous functions. Maybe you want > or >= instead?"
410+ "->" -> cerr (Error row col) -- "Arrows are reserved for cases and anonymous functions. Maybe you want > or >= instead?"
406− "|" -> cerr (Error row col) -- "Vertical bars are reserved for use in union type declarations. Maybe you want || instead?"
411+ "|" -> cerr (Error row col) -- "Vertical bars are reserved for use in union type declarations. Maybe you want || instead?"
407− ":" -> cerr (Error row col) -- "A single colon is for type annotations. Maybe you want :: instead? Or maybe you are defining a type annotation, but there is whitespace before it?"
412+ ":" -> cerr (Error row col) -- "A single colon is for type annotations. Maybe you want :: instead? Or maybe you are defining a type annotation, but there is whitespace before it?"
408− "." -> cerr (Error row col) -- "Dots are for record access. They cannot float around on their own!"
413+ "." -> cerr (Error row col) -- "Dots are for record access. They cannot float around on their own!"
409− op -> cok op (State array newOffset newLength indent row newCol)
414+ op -> cok op (State array newOffset newLength indent row newCol)
410
415
411
416
412infixOpHelp :: Text.Array -> Int -> Int -> Int -> Int -> Either Error (Int, Int, Int)
417infixOpHelp :: Text.Array -> Int -> Int -> Int -> Int -> Either Error (Int, Int, Int)