1{-# OPTIONS_GHC -Wall -fno-warn-unused-do-bind #-}
2{-# LANGUAGE OverloadedStrings #-}
7 , try, deadend, hint, endOfFile
9 , getContext, 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 (A.Located E.Error) a
36 runAt 1 1 parser bytes
39runAt :: Int -> Int -> Parser a -> B.ByteString -> Either (A.Located 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 (A.A overallRegion (E.Parse 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.BadOp _ ((_, start) : _) ->
59 mkError (R.Region start pos) (Just (R.Region pos pos))
61 E.Theories ((_, start) : _) _ ->
62 mkError (R.Region start pos) (Just (R.Region pos pos))
65 mkError (R.Region pos pos) Nothing
73 = Ok a State E.ParseError
81try :: Parser a -> Parser a
83 Parser $ \state cok _ eok eerr ->
84 parser state cok eerr eok eerr
87deadend :: [E.Theory] -> Parser a
89 Parser $ \(State _ _ _ _ row col ctx) _ _ _ eerr ->
90 eerr (E.ParseError row col (E.Theories ctx thrys))
93hint :: E.Next -> Parser a -> Parser a
94hint next (Parser parser) =
95 Parser $ \state@(State _ _ _ _ row col ctx) cok cerr eok eerr ->
98 eok x s (expect row col ctx (E.Expecting next))
101 eerr (expect row col ctx (E.Expecting next))
103 parser state cok cerr eok' eerr'
106endOfFile :: Parser ()
108 Parser $ \state@(State _ offset terminal _ _ _ _) _ _ eok eerr ->
109 if offset < terminal then
119{-# INLINE getPosition #-}
120getPosition :: Parser R.Position
122 Parser $ \state@(State _ _ _ _ row col _) _ _ eok _ ->
123 eok (R.Position row col) state noError
126getIndent :: Parser Int
128 Parser $ \state@(State _ _ _ indent _ _ _) _ _ eok _ ->
129 eok indent state noError
134 Parser $ \state@(State _ _ _ _ _ col _) _ _ eok _ ->
135 eok col state noError
138getContext :: Parser E.ContextStack
140 Parser $ \state@(State _ _ _ _ _ _ ctx) _ _ eok _ ->
141 eok ctx state noError
144pushContext :: R.Position -> E.Context -> Parser ()
146 Parser $ \state@(State _ _ _ _ _ _ context) _ _ eok _ ->
147 eok () (state { _context = (ctx, pos) : context }) noError
150popContext :: a -> Parser a
152 Parser $ \state@(State _ _ _ _ _ _ context) _ _ eok _ ->
153 eok value (state { _context = tail context }) noError
156setIndent :: Int -> Parser ()
158 Parser $ \state _ _ eok _ ->
159 eok () (state { _indent = indent }) noError
167 Parser (a, R.Position, W.SPos)
174addLocation :: Parser a -> Parser (A.Located a)
176 do start <- getPosition
179 return (A.at start end value)
182inContext :: R.Position -> E.Context -> Parser a -> Parser a
183inContext pos ctx parser =
184 do pushContext pos ctx
189-- WHITESPACE VARIATIONS
194 checkSpace =<< W.whitespace
197noSpace :: R.Position -> W.SPos -> Parser ()
198noSpace pos (W.SPos spos) =
204checkSpace :: W.SPos -> Parser ()
205checkSpace (W.SPos (R.Position _ col)) =
206 do indent <- getIndent
207 if col > indent && col > 1
209 else deadend [E.BadSpace]
212checkAligned :: W.SPos -> Parser ()
213checkAligned (W.SPos (R.Position _ col)) =
214 do indent <- getIndent
217 else deadend [E.BadSpace]
220checkFreshLine :: W.SPos -> Parser ()
221checkFreshLine (W.SPos (R.Position _ col)) =
224 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