1{-# OPTIONS_GHC -Wall -fno-warn-unused-do-bind #-}
2{-# LANGUAGE OverloadedStrings #-}
7 , try, deadend, hint, endOfFile
9 , pushContext, popContext
10 , getIndent, setIndent
13 , addLocation, inContext
14 , spaces, noSpace, checkSpace, checkAligned, checkFreshLine
19import Prelude hiding (length)
20import qualified Data.ByteString.Internal as B
22import Parse.Primitives.Internals (Parser(..), State(..), expect, noError)
23import qualified Parse.Primitives.Internals as I
24import qualified Parse.Primitives.Whitespace as W
25import qualified Reporting.Annotation as A
26import qualified Reporting.Error.Syntax as E
27import qualified Reporting.Region as R
34run :: Parser a -> B.ByteString -> Either E.Error a
36 runAt 1 1 parser bytes
39runAt :: Int -> Int -> Parser a -> B.ByteString -> Either E.Error a
40runAt startRow startColumn (Parser parser) (B.PS fp offset length) =
41 case parser (State fp offset (offset + length) 0 startRow startColumn []) Ok Err Ok Err of
45 Err (E.ParseError row col problem) ->
47 pos = R.Position row col
48 mkError overallRegion subRegion =
49 Left (E.Parse overallRegion subRegion problem)
53 mkError (R.Region pos (R.Position row endCol)) Nothing
55 E.BadEscape width _ ->
56 mkError (R.Region pos (R.Position row (col + width))) Nothing
58 E.BadUnderscore badCol ->
59 mkError (R.Region pos (R.Position row badCol)) Nothing
61 E.BadOp _ ((_, start) : _) ->
62 mkError (R.Region start pos) (Just (R.Region pos pos))
64 E.Theories ((_, start) : _) _ ->
65 mkError (R.Region start pos) (Just (R.Region pos pos))
68 mkError (R.Region pos pos) Nothing
76 = Ok a State E.ParseError
84try :: Parser a -> Parser a
86 Parser $ \state cok _ eok eerr ->
87 parser state cok eerr eok eerr
90deadend :: [E.Theory] -> Parser a
92 Parser $ \(State _ _ _ _ row col ctx) _ _ _ eerr ->
93 eerr (E.ParseError row col (E.Theories ctx thrys))
96hint :: E.Next -> Parser a -> Parser a
97hint next (Parser parser) =
98 Parser $ \state@(State _ _ _ _ row col ctx) cok cerr eok eerr ->
101 eok x s (expect row col ctx (E.Expecting next))
104 eerr (expect row col ctx (E.Expecting next))
106 parser state cok cerr eok' eerr'
109endOfFile :: Parser ()
111 Parser $ \state@(State _ offset terminal _ _ _ _) _ _ eok eerr ->
112 if offset < terminal then
122{-# INLINE getPosition #-}
123getPosition :: Parser R.Position
125 Parser $ \state@(State _ _ _ _ row col _) _ _ eok _ ->
126 eok (R.Position row col) state noError
129getIndent :: Parser Int
131 Parser $ \state@(State _ _ _ indent _ _ _) _ _ eok _ ->
132 eok indent state noError
137 Parser $ \state@(State _ _ _ _ _ col _) _ _ eok _ ->
138 eok col state noError
141pushContext :: R.Position -> E.Context -> Parser ()
143 Parser $ \state@(State _ _ _ _ _ _ context) _ _ eok _ ->
144 eok () (state { _context = (ctx, pos) : context }) noError
147popContext :: a -> Parser a
149 Parser $ \state@(State _ _ _ _ _ _ context) _ _ eok _ ->
150 eok value (state { _context = tail context }) noError
153setIndent :: Int -> Parser ()
155 Parser $ \state _ _ eok _ ->
156 eok () (state { _indent = indent }) noError
164 Parser (a, R.Position, W.SPos)
171addLocation :: Parser a -> Parser (A.Located a)
173 do start <- getPosition
176 return (A.at start end value)
179inContext :: R.Position -> E.Context -> Parser a -> Parser a
180inContext pos ctx parser =
181 do pushContext pos ctx
186-- WHITESPACE VARIATIONS
191 checkSpace =<< W.whitespace
194noSpace :: R.Position -> W.SPos -> Parser ()
195noSpace pos (W.SPos spos) =
201checkSpace :: W.SPos -> Parser ()
202checkSpace (W.SPos (R.Position _ col)) =
203 do indent <- getIndent
204 if col > indent && col > 1
206 else deadend [E.BadSpace]
209checkAligned :: W.SPos -> Parser ()
210checkAligned (W.SPos (R.Position _ col)) =
211 do indent <- getIndent
214 else deadend [E.BadSpace]
217checkFreshLine :: W.SPos -> Parser ()
218checkFreshLine (W.SPos (R.Position _ col)) =
221 else deadend [E.BadSpace]
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list