@@ -1,8 +1,9 @@
11{-# OPTIONS_GHC -Wall #-}
2−{-# LANGUAGE BangPatterns, UnboxedTuples, OverloadedStrings #-}
2+{-# LANGUAGE BangPatterns, OverloadedStrings #-}
33module Parse.Symbol
4− ( wildcard
5− , operator
4+ ( operator
5+ , BadOperator(..)
6+ , binopCharSet
67 )
78 where
89
@@ -15,38 +16,22 @@ import Foreign.Ptr (Ptr, plusPtr, minusPtr)
1516import GHC.Word (Word8)
1617
1718import Parse.Primitives (Parser, Row, Col)
18−import qualified Parse.Variable as Var
1919import qualified Parse.Primitives as P
20−import qualified Reporting.Error.Syntax as E
2120
2221
2322
24−-- UNDERSCORE
25−
26−
27−wildcard :: Parser E.Pattern ()
28−wildcard =
29− P.Parser $ \(P.State pos end indent row col) cok _ cerr eerr ->
30− if pos == end || P.unsafeIndex pos /= 0x5F {- _ -} then
31− eerr row col E.PStart
32− else
33− let
34− !newPos = plusPtr pos 1
35− !newCol = col + 1
36− in
37− if Var.getInnerWidth newPos end > 0 then
38− let (# _, badCol #) = Var.chompInnerChars newPos end newCol in
39− cerr row col (E.PWildcardNotVar (fromIntegral (badCol - col)))
40− else
41− let !newState = P.State newPos end indent row newCol in
42− cok () newState
43−
23+-- OPERATOR
4424
4525
46−-- OPERATOR
26+data BadOperator
27+ = BadDot
28+ | BadPipe
29+ | BadArrow
30+ | BadEquals
31+ | BadHasType
4732
4833
49−operator :: (Row -> Col -> x) -> (E.Operator -> Row -> Col -> x) -> Parser x Name.Name
34+operator :: (Row -> Col -> x) -> (BadOperator -> Row -> Col -> x) -> Parser x Name.Name
5035operator toExpectation toError =
5136 P.Parser $ \(P.State pos end indent row col) cok _ cerr eerr ->
5237 let !newPos = chompOps pos end in
@@ -55,11 +40,11 @@ operator toExpectation toError =
5540
5641 else
5742 case Name.fromPtr pos newPos of
58− "." -> cerr row col (toError E.OpDot)
59− "|" -> cerr row col (toError E.OpPipe)
60− "->" -> cerr row col (toError E.OpArrow)
61− "=" -> cerr row col (toError E.OpEquals)
62− ":" -> cerr row col (toError E.OpHasType)
43+ "." -> cerr row col (toError BadDot)
44+ "|" -> cerr row col (toError BadPipe)
45+ "->" -> cerr row col (toError BadArrow)
46+ "=" -> cerr row col (toError BadEquals)
47+ ":" -> cerr row col (toError BadHasType)
6348 op ->
6449 let
6550 !newCol = col + fromIntegral (minusPtr newPos pos)