module Parser.Parser (
Parse_error (..),
Parser',
Tokeniser',
Usage_error (..),
(<+>),
add_location,
add_token,
filter_parser,
fmap_filter_parser,
parse',
parse_brackets,
parse_default,
parse_file_path',
parse_list,
parse_location,
parse_many,
parse_non_empty_list,
parse_not,
parse_some,
parse_token,
parse_token',
parse_with_location) where
import Control.Lens.Combinators
import Control.Lens.Operators
import Control.Monad.Except
import Control.Monad.RWS.Strict
import Data.Generics.Labels ()
import GHC.Generics
import Parser.Locations
import Parser.Utilities
newtype Parser token output error t =
Parser {forall token output error t.
Parser token output error t
-> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
t
run_parser' :: RWST () output (Parser.Parser.State token) (ExceptT (Parse_error error) (Either Usage_error)) t}
type Parser' token error = Parser token () error
data Parse_error error = Filter_error error | Parse_error' Location
data State token = State {forall token. State token -> Tokens token
state_tokens :: Tokens token, forall token. State token -> Location
state_lookahead :: Location}
type Tokeniser' char_class token error = Parser char_class [With_location token] error
data Tokens token = Tokens [With_location token] Location
data Usage_error = Ambiguity | Attempt_to_recover_a_filter_error | Filter_error_encountered_in_parse_not
infixr 3 <+>
(<+>) :: Parser token output error t -> Parser token output error t -> Parser token output error t
Parser (RWST ()
-> State token
-> ExceptT
(Parse_error error) (Either Usage_error) (t, State token, output)
parse_0) <+> :: forall token output error t.
Parser token output error t
-> Parser token output error t -> Parser token output error t
<+> Parser (RWST ()
-> State token
-> ExceptT
(Parse_error error) (Either Usage_error) (t, State token, output)
parse_1) =
RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
t
-> Parser token output error t
forall token output error t.
RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
t
-> Parser token output error t
Parser
((()
-> State token
-> ExceptT
(Parse_error error) (Either Usage_error) (t, State token, output))
-> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
t
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST
(\ () State token
st ->
Either
Usage_error (Either (Parse_error error) (t, State token, output))
-> ExceptT
(Parse_error error) (Either Usage_error) (t, State token, output)
forall e (m :: * -> *) a. m (Either e a) -> ExceptT e m a
ExceptT
(do
(Location
lookahead_0, Maybe (t, Tokens token, output)
result_0) <- ExceptT
(Parse_error error) (Either Usage_error) (t, State token, output)
-> Either Usage_error (Location, Maybe (t, Tokens token, output))
forall error t token output.
ExceptT
(Parse_error error) (Either Usage_error) (t, State token, output)
-> Either Usage_error (Location, Maybe (t, Tokens token, output))
deconstruct_result (()
-> State token
-> ExceptT
(Parse_error error) (Either Usage_error) (t, State token, output)
parse_0 () State token
st)
(Location
lookahead_1, Maybe (t, Tokens token, output)
result_1) <- ExceptT
(Parse_error error) (Either Usage_error) (t, State token, output)
-> Either Usage_error (Location, Maybe (t, Tokens token, output))
forall error t token output.
ExceptT
(Parse_error error) (Either Usage_error) (t, State token, output)
-> Either Usage_error (Location, Maybe (t, Tokens token, output))
deconstruct_result (()
-> State token
-> ExceptT
(Parse_error error) (Either Usage_error) (t, State token, output)
parse_1 () State token
st)
(
Location
-> Maybe (t, Tokens token, output)
-> Either (Parse_error error) (t, State token, output)
forall t token output error.
Location
-> Maybe (t, Tokens token, output)
-> Either (Parse_error error) (t, State token, output)
construct_result (Location -> Location -> Location
forall a. Ord a => a -> a -> a
max Location
lookahead_0 Location
lookahead_1) (Maybe (t, Tokens token, output)
-> Either (Parse_error error) (t, State token, output))
-> Either Usage_error (Maybe (t, Tokens token, output))
-> Either
Usage_error (Either (Parse_error error) (t, State token, output))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
case (Maybe (t, Tokens token, output)
result_0, Maybe (t, Tokens token, output)
result_1) of
(Maybe (t, Tokens token, output)
Nothing, Maybe (t, Tokens token, output)
Nothing) -> Maybe (t, Tokens token, output)
-> Either Usage_error (Maybe (t, Tokens token, output))
forall a b. b -> Either a b
Right Maybe (t, Tokens token, output)
forall a. Maybe a
Nothing
(Maybe (t, Tokens token, output)
Nothing, Just (t, Tokens token, output)
_) -> Maybe (t, Tokens token, output)
-> Either Usage_error (Maybe (t, Tokens token, output))
forall a b. b -> Either a b
Right Maybe (t, Tokens token, output)
result_1
(Just (t, Tokens token, output)
_, Maybe (t, Tokens token, output)
Nothing) -> Maybe (t, Tokens token, output)
-> Either Usage_error (Maybe (t, Tokens token, output))
forall a b. b -> Either a b
Right Maybe (t, Tokens token, output)
result_0
(Just (t
_, Tokens token
tokens_0, output
_), Just (t
_, Tokens token
tokens_1, output
_)) ->
case Location -> Location -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (Tokens token -> Location
forall token. Tokens token -> Location
current_location Tokens token
tokens_0) (Tokens token -> Location
forall token. Tokens token -> Location
current_location Tokens token
tokens_1) of
Ordering
LT -> Maybe (t, Tokens token, output)
-> Either Usage_error (Maybe (t, Tokens token, output))
forall a b. b -> Either a b
Right Maybe (t, Tokens token, output)
result_1
Ordering
EQ -> Usage_error -> Either Usage_error (Maybe (t, Tokens token, output))
forall a b. a -> Either a b
Left Usage_error
Ambiguity
Ordering
GT -> Maybe (t, Tokens token, output)
-> Either Usage_error (Maybe (t, Tokens token, output))
forall a b. b -> Either a b
Right Maybe (t, Tokens token, output)
result_0))))
instance Monoid output => Applicative (Parser token output error) where
Parser RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
(a -> b)
parse_0 <*> :: forall a b.
Parser token output error (a -> b)
-> Parser token output error a -> Parser token output error b
<*> Parser RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
a
parse_1 = RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
b
-> Parser token output error b
forall token output error t.
RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
t
-> Parser token output error t
Parser (RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
(a -> b)
parse_0 RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
(a -> b)
-> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
a
-> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
b
forall a b.
RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
(a -> b)
-> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
a
-> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
a
parse_1)
pure :: forall a. a -> Parser token output error a
pure a
x = RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
a
-> Parser token output error a
forall token output error t.
RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
t
-> Parser token output error t
Parser (a
-> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
a
forall a.
a
-> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
a
forall (m :: * -> *) a. Monad m => a -> m a
return a
x)
instance Functor (Parser token output error) where
fmap :: forall a b.
(a -> b)
-> Parser token output error a -> Parser token output error b
fmap a -> b
f (Parser RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
a
parse_t) = RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
b
-> Parser token output error b
forall token output error t.
RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
t
-> Parser token output error t
Parser (a -> b
f (a -> b)
-> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
a
-> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
a
parse_t)
deriving instance Generic (Parser.Parser.State token)
instance Monoid output => Monad (Parser token output error) where
Parser RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
a
parse_t >>= :: forall a b.
Parser token output error a
-> (a -> Parser token output error b)
-> Parser token output error b
>>= a -> Parser token output error b
f = RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
b
-> Parser token output error b
forall token output error t.
RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
t
-> Parser token output error t
Parser (RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
a
parse_t RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
a
-> (a
-> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
b)
-> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
b
forall a b.
RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
a
-> (a
-> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
b)
-> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Parser token output error b
-> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
b
forall token output error t.
Parser token output error t
-> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
t
run_parser' (Parser token output error b
-> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
b)
-> (a -> Parser token output error b)
-> a
-> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> Parser token output error b
f)
deriving instance Show error => Show (Parse_error error)
deriving instance Show token => Show (Parser.Parser.State token)
deriving instance Show token => Show (Tokens token)
deriving instance Show Usage_error
add_location :: Monoid output => Parser token output error t -> Parser token output error (With_location t)
add_location :: forall output token error t.
Monoid output =>
Parser token output error t
-> Parser token output error (With_location t)
add_location Parser token output error t
parse_t = Location -> t -> With_location t
forall t. Location -> t -> With_location t
With_location (Location -> t -> With_location t)
-> Parser token output error Location
-> Parser token output error (t -> With_location t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser token output error Location
forall output token error.
Monoid output =>
Parser token output error Location
parse_location Parser token output error (t -> With_location t)
-> Parser token output error t
-> Parser token output error (With_location t)
forall a b.
Parser token output error (a -> b)
-> Parser token output error a -> Parser token output error b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser token output error t
parse_t
add_token :: Tokeniser' char_class token error token -> Tokeniser' char_class token error ()
add_token :: forall char_class token error.
Tokeniser' char_class token error token
-> Tokeniser' char_class token error ()
add_token Tokeniser' char_class token error token
tokenise =
do
Location
location <- Parser char_class [With_location token] error Location
forall output token error.
Monoid output =>
Parser token output error Location
parse_location
token
token <- Tokeniser' char_class token error token
tokenise
RWST
()
[With_location token]
(State char_class)
(ExceptT (Parse_error error) (Either Usage_error))
()
-> Tokeniser' char_class token error ()
forall token output error t.
RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
t
-> Parser token output error t
Parser ([With_location token]
-> RWST
()
[With_location token]
(State char_class)
(ExceptT (Parse_error error) (Either Usage_error))
()
forall w (m :: * -> *). MonadWriter w m => w -> m ()
tell [Location -> token -> With_location token
forall t. Location -> t -> With_location t
With_location Location
location token
token])
certain_token :: Eq token => token -> token -> Maybe ()
certain_token :: forall token. Eq token => token -> token -> Maybe ()
certain_token token
token token
token' =
do
() -> Bool -> Maybe ()
forall error (f :: * -> *).
MonadError error f =>
error -> Bool -> f ()
check () (token
token token -> token -> Bool
forall a. Eq a => a -> a -> Bool
== token
token')
() -> Maybe ()
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
construct_result ::
Location -> Maybe (t, Tokens token, output) -> Either (Parse_error error) (t, Parser.Parser.State token, output)
construct_result :: forall t token output error.
Location
-> Maybe (t, Tokens token, output)
-> Either (Parse_error error) (t, State token, output)
construct_result Location
lookahead Maybe (t, Tokens token, output)
result =
case Maybe (t, Tokens token, output)
result of
Maybe (t, Tokens token, output)
Nothing -> Parse_error error
-> Either (Parse_error error) (t, State token, output)
forall a b. a -> Either a b
Left (Location -> Parse_error error
forall error. Location -> Parse_error error
Parse_error' Location
lookahead)
Just (t
x, Tokens token
tokens, output
output) -> (t, State token, output)
-> Either (Parse_error error) (t, State token, output)
forall a b. b -> Either a b
Right (t
x, Tokens token -> Location -> State token
forall token. Tokens token -> Location -> State token
State Tokens token
tokens Location
lookahead, output
output)
current_location :: Tokens token -> Location
current_location :: forall token. Tokens token -> Location
current_location (Tokens [With_location token]
tokens Location
end_location) =
case [With_location token]
tokens of
[] -> Location
end_location
With_location Location
location token
_ : [With_location token]
_ -> Location
location
deconstruct_result ::
(
ExceptT (Parse_error error) (Either Usage_error) (t, Parser.Parser.State token, output) ->
Either Usage_error (Location, Maybe (t, Tokens token, output)))
deconstruct_result :: forall error t token output.
ExceptT
(Parse_error error) (Either Usage_error) (t, State token, output)
-> Either Usage_error (Location, Maybe (t, Tokens token, output))
deconstruct_result (ExceptT Either
Usage_error (Either (Parse_error error) (t, State token, output))
maybe_result) =
do
Either (Parse_error error) (t, State token, output)
result <- Either
Usage_error (Either (Parse_error error) (t, State token, output))
maybe_result
case Either (Parse_error error) (t, State token, output)
result of
Left Parse_error error
err ->
case Parse_error error
err of
Filter_error error
_ -> Usage_error
-> Either Usage_error (Location, Maybe (t, Tokens token, output))
forall a b. a -> Either a b
Left Usage_error
Attempt_to_recover_a_filter_error
Parse_error' Location
lookahead -> (Location, Maybe (t, Tokens token, output))
-> Either Usage_error (Location, Maybe (t, Tokens token, output))
forall a b. b -> Either a b
Right (Location
lookahead, Maybe (t, Tokens token, output)
forall a. Maybe a
Nothing)
Right (t
x, State Tokens token
tokens Location
lookahead, output
output) -> (Location, Maybe (t, Tokens token, output))
-> Either Usage_error (Location, Maybe (t, Tokens token, output))
forall a b. b -> Either a b
Right (Location
lookahead, (t, Tokens token, output) -> Maybe (t, Tokens token, output)
forall a. a -> Maybe a
Just (t
x, Tokens token
tokens, output
output))
filter_parser :: (Eq token, Monoid output) =>
(t -> Bool) -> (Location -> error) -> Parser token output error t -> Parser token output error t
filter_parser :: forall token output t error.
(Eq token, Monoid output) =>
(t -> Bool)
-> (Location -> error)
-> Parser token output error t
-> Parser token output error t
filter_parser t -> Bool
f Location -> error
err =
(t -> Either (Location -> error) t)
-> Parser token output error t -> Parser token output error t
forall token output t error u.
(Eq token, Monoid output) =>
(t -> Either (Location -> error) u)
-> Parser token output error t -> Parser token output error u
fmap_filter_parser
(\ t
x ->
do
(Location -> error) -> Bool -> Either (Location -> error) ()
forall error (f :: * -> *).
MonadError error f =>
error -> Bool -> f ()
check Location -> error
err (t -> Bool
f t
x)
t -> Either (Location -> error) t
forall a b. b -> Either a b
Right t
x)
fmap_filter_parser :: (Eq token, Monoid output) =>
(t -> Either (Location -> error) u) -> Parser token output error t -> Parser token output error u
fmap_filter_parser :: forall token output t error u.
(Eq token, Monoid output) =>
(t -> Either (Location -> error) u)
-> Parser token output error t -> Parser token output error u
fmap_filter_parser t -> Either (Location -> error) u
f Parser token output error t
parse_t =
do
Location
location <- Parser token output error Location
forall output token error.
Monoid output =>
Parser token output error Location
parse_location
t
x <- Parser token output error t
parse_t
case t -> Either (Location -> error) u
f t
x of
Left Location -> error
err -> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
u
-> Parser token output error u
forall token output error t.
RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
t
-> Parser token output error t
Parser (Parse_error error
-> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
u
forall a.
Parse_error error
-> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (error -> Parse_error error
forall error. error -> Parse_error error
Filter_error (Location -> error
err Location
location)))
Right u
y -> u -> Parser token output error u
forall a. a -> Parser token output error a
forall (m :: * -> *) a. Monad m => a -> m a
return u
y
get_tokens :: Monoid output => Parser token output error (Tokens token)
get_tokens :: forall output token error.
Monoid output =>
Parser token output error (Tokens token)
get_tokens =
do
Tokens token
tokens <- RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
(Tokens token)
-> Parser token output error (Tokens token)
forall token output error t.
RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
t
-> Parser token output error t
Parser (Getting (Tokens token) (State token) (Tokens token)
-> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
(Tokens token)
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use Getting (Tokens token) (State token) (Tokens token)
#state_tokens)
RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
()
-> Parser token output error ()
forall token output error t.
RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
t
-> Parser token output error t
Parser (ASetter (State token) (State token) Location Location
#state_lookahead ASetter (State token) (State token) Location Location
-> (Location -> Location)
-> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= Location -> Location -> Location
forall a. Ord a => a -> a -> a
max (Tokens token -> Location
forall token. Tokens token -> Location
current_location Tokens token
tokens))
Tokens token -> Parser token output error (Tokens token)
forall a. a -> Parser token output error a
forall (m :: * -> *) a. Monad m => a -> m a
return Tokens token
tokens
parse' :: forall char_class token error t .
(
(Char -> char_class) ->
(char_class -> Location -> Location) ->
Tokeniser' char_class token error () ->
Parser' token error t ->
(Location -> error) ->
String ->
Either Usage_error (Either error t))
parse' :: forall char_class token error t.
(Char -> char_class)
-> (char_class -> Location -> Location)
-> Tokeniser' char_class token error ()
-> Parser' token error t
-> (Location -> error)
-> String
-> Either Usage_error (Either error t)
parse' Char -> char_class
classify_char char_class -> Location -> Location
next_location Tokeniser' char_class token error ()
tokenise_t Parser' token error t
parse_t Location -> error
parse_error String
text =
ExceptT error (Either Usage_error) t
-> Either Usage_error (Either error t)
forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT
((Parse_error error -> error)
-> ExceptT (Parse_error error) (Either Usage_error) t
-> ExceptT error (Either Usage_error) t
forall (m :: * -> *) e e' a.
Functor m =>
(e -> e') -> ExceptT e m a -> ExceptT e' m a
withExceptT
Parse_error error -> error
transform_error
(do
let (Location
end_location, [With_location char_class]
text') = RWS () [With_location char_class] Location ()
-> () -> Location -> (Location, [With_location char_class])
forall r w s a. RWS r w s a -> r -> s -> (s, w)
execRWS (String -> RWS () [With_location char_class] Location ()
classify_chars String
text) () Location
init_location
((), [With_location token]
tokens) <- Tokeniser' char_class token error ()
-> Tokens char_class
-> ExceptT
(Parse_error error)
(Either Usage_error)
((), [With_location token])
forall output token error t.
Monoid output =>
Parser token output error t
-> Tokens token
-> ExceptT (Parse_error error) (Either Usage_error) (t, output)
run_parser Tokeniser' char_class token error ()
tokenise_t ([With_location char_class] -> Location -> Tokens char_class
forall token. [With_location token] -> Location -> Tokens token
Tokens [With_location char_class]
text' Location
end_location)
(t, ()) -> t
forall a b. (a, b) -> a
fst ((t, ()) -> t)
-> ExceptT (Parse_error error) (Either Usage_error) (t, ())
-> ExceptT (Parse_error error) (Either Usage_error) t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser' token error t
-> Tokens token
-> ExceptT (Parse_error error) (Either Usage_error) (t, ())
forall output token error t.
Monoid output =>
Parser token output error t
-> Tokens token
-> ExceptT (Parse_error error) (Either Usage_error) (t, output)
run_parser Parser' token error t
parse_t ([With_location token] -> Location -> Tokens token
forall token. [With_location token] -> Location -> Tokens token
Tokens [With_location token]
tokens Location
end_location)))
where
classify_chars :: String -> RWS () [With_location char_class] Location ()
classify_chars :: String -> RWS () [With_location char_class] Location ()
classify_chars String
text' =
case String
text' of
[] -> () -> RWS () [With_location char_class] Location ()
forall a.
a -> RWST () [With_location char_class] Location Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Char
c : String
text'' ->
do
Location
location <- RWST () [With_location char_class] Location Identity Location
forall s (m :: * -> *). MonadState s m => m s
get
let char_class :: char_class
char_class = Char -> char_class
classify_char Char
c
[With_location char_class]
-> RWS () [With_location char_class] Location ()
forall w (m :: * -> *). MonadWriter w m => w -> m ()
tell [Location -> char_class -> With_location char_class
forall t. Location -> t -> With_location t
With_location Location
location char_class
char_class]
(Location -> Location)
-> RWS () [With_location char_class] Location ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (char_class -> Location -> Location
next_location char_class
char_class)
String -> RWS () [With_location char_class] Location ()
classify_chars String
text''
transform_error :: Parse_error error -> error
transform_error :: Parse_error error -> error
transform_error Parse_error error
err =
case Parse_error error
err of
Filter_error error
err' -> error
err'
Parse_error' Location
location -> Location -> error
parse_error Location
location
parse_brackets :: (Eq token, Monoid output) => token -> token -> Parser token output error t -> Parser token output error t
parse_brackets :: forall token output error t.
(Eq token, Monoid output) =>
token
-> token
-> Parser token output error t
-> Parser token output error t
parse_brackets token
left_bracket token
right_bracket Parser token output error t
parse_t =
do
token -> Parser token output error ()
forall token output error.
(Eq token, Monoid output) =>
token -> Parser token output error ()
parse_token token
left_bracket
t
x <- Parser token output error t
parse_t
token -> Parser token output error ()
forall token output error.
(Eq token, Monoid output) =>
token -> Parser token output error ()
parse_token token
right_bracket
t -> Parser token output error t
forall a. a -> Parser token output error a
forall (m :: * -> *) a. Monad m => a -> m a
return t
x
parse_default :: Monoid output => Parser token output error t -> t -> Parser token output error t
parse_default :: forall output token error t.
Monoid output =>
Parser token output error t -> t -> Parser token output error t
parse_default Parser token output error t
parse_t t
x = t -> Parser token output error t
forall a. a -> Parser token output error a
forall (m :: * -> *) a. Monad m => a -> m a
return t
x Parser token output error t
-> Parser token output error t -> Parser token output error t
forall token output error t.
Parser token output error t
-> Parser token output error t -> Parser token output error t
<+> Parser token output error t
parse_t
parse_directory ::
Eq token => Parser' token error [Back] -> Parser' token error String -> token -> Parser' token error Directory
parse_directory :: forall token error.
Eq token =>
Parser' token error [Back]
-> Parser' token error String
-> token
-> Parser' token error Directory
parse_directory Parser' token error [Back]
parse_back Parser' token error String
parse_name token
slash_token =
[Back] -> [String] -> Directory
Directory ([Back] -> [String] -> Directory)
-> Parser' token error [Back]
-> Parser token () error ([String] -> Directory)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser' token error [Back]
parse_back Parser token () error ([String] -> Directory)
-> Parser token () error [String]
-> Parser token () error Directory
forall a b.
Parser token () error (a -> b)
-> Parser token () error a -> Parser token () error b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser' token error String -> Parser token () error [String]
forall output token error t.
Monoid output =>
Parser token output error t -> Parser token output error [t]
parse_many (Parser' token error String -> token -> Parser' token error String
forall token error t.
Eq token =>
Parser' token error t -> token -> Parser' token error t
parse_one_directory Parser' token error String
parse_name token
slash_token)
parse_element :: (Eq token, Monoid output) => token -> Parser token output error t -> Parser token output error t
parse_element :: forall token output error t.
(Eq token, Monoid output) =>
token -> Parser token output error t -> Parser token output error t
parse_element token
separator Parser token output error t
parse_t =
do
token -> Parser token output error ()
forall token output error.
(Eq token, Monoid output) =>
token -> Parser token output error ()
parse_token token
separator
Parser token output error t
parse_t
parse_end :: Monoid output => Parser token output error t -> Parser token output error t
parse_end :: forall output token error t.
Monoid output =>
Parser token output error t -> Parser token output error t
parse_end Parser token output error t
parse_t =
do
t
x <- Parser token output error t
parse_t
Parser token output error ()
forall output token error.
Monoid output =>
Parser token output error ()
parse_end'
t -> Parser token output error t
forall a. a -> Parser token output error a
forall (m :: * -> *) a. Monad m => a -> m a
return t
x
parse_end' :: Monoid output => Parser token output error ()
parse_end' :: forall output token error.
Monoid output =>
Parser token output error ()
parse_end' =
do
Tokens token
tokens <- Parser token output error (Tokens token)
forall output token error.
Monoid output =>
Parser token output error (Tokens token)
get_tokens
case Tokens token -> Bool
forall token. Tokens token -> Bool
tokens_ended Tokens token
tokens of
Bool
False -> Parser token output error ()
forall output token error t.
Monoid output =>
Parser token output error t
parse_error'
Bool
True -> () -> Parser token output error ()
forall a. a -> Parser token output error a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
parse_error' :: Monoid output => Parser token output error t
parse_error' :: forall output token error t.
Monoid output =>
Parser token output error t
parse_error' =
do
Location
lookahead <- RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
Location
-> Parser token output error Location
forall token output error t.
RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
t
-> Parser token output error t
Parser (Getting Location (State token) Location
-> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
Location
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use Getting Location (State token) Location
#state_lookahead)
RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
t
-> Parser token output error t
forall token output error t.
RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
t
-> Parser token output error t
Parser (Parse_error error
-> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
t
forall a.
Parse_error error
-> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (Location -> Parse_error error
forall error. Location -> Parse_error error
Parse_error' Location
lookahead))
parse_file_path' :: Eq token =>
(
Parser' token error [Back] ->
Parser' token error String ->
token ->
token ->
(String -> token) ->
String ->
Parser' token error File_path)
parse_file_path' :: forall token error.
Eq token =>
Parser' token error [Back]
-> Parser' token error String
-> token
-> token
-> (String -> token)
-> String
-> Parser' token error File_path
parse_file_path' Parser' token error [Back]
parse_back Parser' token error String
parse_name token
slash_token token
dot_token String -> token
name_token String
ext =
do
Directory
directory <- Parser' token error [Back]
-> Parser' token error String
-> token
-> Parser' token error Directory
forall token error.
Eq token =>
Parser' token error [Back]
-> Parser' token error String
-> token
-> Parser' token error Directory
parse_directory Parser' token error [Back]
parse_back Parser' token error String
parse_name token
slash_token
String
file_name <- Parser' token error String
parse_name
token -> Parser token () error ()
forall token output error.
(Eq token, Monoid output) =>
token -> Parser token output error ()
parse_token token
dot_token
token -> Parser token () error ()
forall token output error.
(Eq token, Monoid output) =>
token -> Parser token output error ()
parse_token (String -> token
name_token String
ext)
File_path -> Parser' token error File_path
forall a. a -> Parser token () error a
forall (m :: * -> *) a. Monad m => a -> m a
return (Directory -> String -> String -> File_path
File_path Directory
directory String
file_name String
ext)
parse_list :: (Eq token, Monoid output) => token -> Parser token output error t -> Parser token output error [t]
parse_list :: forall token output error t.
(Eq token, Monoid output) =>
token
-> Parser token output error t -> Parser token output error [t]
parse_list token
separator Parser token output error t
parse_t = Parser token output error [t]
-> [t] -> Parser token output error [t]
forall output token error t.
Monoid output =>
Parser token output error t -> t -> Parser token output error t
parse_default (token
-> Parser token output error t -> Parser token output error [t]
forall token output error t.
(Eq token, Monoid output) =>
token
-> Parser token output error t -> Parser token output error [t]
parse_non_empty_list token
separator Parser token output error t
parse_t) []
parse_location :: Monoid output => Parser token output error Location
parse_location :: forall output token error.
Monoid output =>
Parser token output error Location
parse_location = Tokens token -> Location
forall token. Tokens token -> Location
current_location (Tokens token -> Location)
-> Parser token output error (Tokens token)
-> Parser token output error Location
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
(Tokens token)
-> Parser token output error (Tokens token)
forall token output error t.
RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
t
-> Parser token output error t
Parser (Getting (Tokens token) (State token) (Tokens token)
-> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
(Tokens token)
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use Getting (Tokens token) (State token) (Tokens token)
#state_tokens)
parse_many :: Monoid output => Parser token output error t -> Parser token output error [t]
parse_many :: forall output token error t.
Monoid output =>
Parser token output error t -> Parser token output error [t]
parse_many Parser token output error t
parse_t = Parser token output error [t]
-> [t] -> Parser token output error [t]
forall output token error t.
Monoid output =>
Parser token output error t -> t -> Parser token output error t
parse_default (Parser token output error t -> Parser token output error [t]
forall output token error t.
Monoid output =>
Parser token output error t -> Parser token output error [t]
parse_some Parser token output error t
parse_t) []
parse_non_empty_list :: (Eq token, Monoid output) => token -> Parser token output error t -> Parser token output error [t]
parse_non_empty_list :: forall token output error t.
(Eq token, Monoid output) =>
token
-> Parser token output error t -> Parser token output error [t]
parse_non_empty_list token
separator Parser token output error t
parse_t = (:) (t -> [t] -> [t])
-> Parser token output error t
-> Parser token output error ([t] -> [t])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser token output error t
parse_t Parser token output error ([t] -> [t])
-> Parser token output error [t] -> Parser token output error [t]
forall a b.
Parser token output error (a -> b)
-> Parser token output error a -> Parser token output error b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser token output error t -> Parser token output error [t]
forall output token error t.
Monoid output =>
Parser token output error t -> Parser token output error [t]
parse_many (token -> Parser token output error t -> Parser token output error t
forall token output error t.
(Eq token, Monoid output) =>
token -> Parser token output error t -> Parser token output error t
parse_element token
separator Parser token output error t
parse_t)
parse_not :: Monoid output => Parser token output error t -> Parser token output error ()
parse_not :: forall output token error t.
Monoid output =>
Parser token output error t -> Parser token output error ()
parse_not (Parser (RWST ()
-> State token
-> ExceptT
(Parse_error error) (Either Usage_error) (t, State token, output)
parse_t)) =
RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
()
-> Parser token output error ()
forall token output error t.
RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
t
-> Parser token output error t
Parser
((()
-> State token
-> ExceptT
(Parse_error error) (Either Usage_error) ((), State token, output))
-> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
()
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST
(\ () State token
st ->
Either
Usage_error (Either (Parse_error error) ((), State token, output))
-> ExceptT
(Parse_error error) (Either Usage_error) ((), State token, output)
forall e (m :: * -> *) a. m (Either e a) -> ExceptT e m a
ExceptT
(do
Either (Parse_error error) (t, State token, output)
result <- ExceptT
(Parse_error error) (Either Usage_error) (t, State token, output)
-> Either
Usage_error (Either (Parse_error error) (t, State token, output))
forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT (()
-> State token
-> ExceptT
(Parse_error error) (Either Usage_error) (t, State token, output)
parse_t () State token
st)
case Either (Parse_error error) (t, State token, output)
result of
Left Parse_error error
err ->
case Parse_error error
err of
Filter_error error
_ -> Usage_error
-> Either
Usage_error (Either (Parse_error error) ((), State token, output))
forall a b. a -> Either a b
Left Usage_error
Filter_error_encountered_in_parse_not
Parse_error' Location
location -> Either (Parse_error error) ((), State token, output)
-> Either
Usage_error (Either (Parse_error error) ((), State token, output))
forall a b. b -> Either a b
Right (((), State token, output)
-> Either (Parse_error error) ((), State token, output)
forall a b. b -> Either a b
Right ((), State token
st {state_lookahead = location}, output
forall a. Monoid a => a
mempty))
Right (t
_, State Tokens token
_ Location
lookahead', output
_) -> Either (Parse_error error) ((), State token, output)
-> Either
Usage_error (Either (Parse_error error) ((), State token, output))
forall a b. b -> Either a b
Right (Parse_error error
-> Either (Parse_error error) ((), State token, output)
forall a b. a -> Either a b
Left (Location -> Parse_error error
forall error. Location -> Parse_error error
Parse_error' Location
lookahead')))))
parse_one_directory :: Eq token => Parser' token error t -> token -> Parser' token error t
parse_one_directory :: forall token error t.
Eq token =>
Parser' token error t -> token -> Parser' token error t
parse_one_directory Parser' token error t
parse_name token
slash_token =
do
t
directory <- Parser' token error t
parse_name
token -> Parser token () error ()
forall token output error.
(Eq token, Monoid output) =>
token -> Parser token output error ()
parse_token token
slash_token
t -> Parser' token error t
forall a. a -> Parser token () error a
forall (m :: * -> *) a. Monad m => a -> m a
return t
directory
parse_some :: Monoid output => Parser token output error t -> Parser token output error [t]
parse_some :: forall output token error t.
Monoid output =>
Parser token output error t -> Parser token output error [t]
parse_some Parser token output error t
parse_t = (:) (t -> [t] -> [t])
-> Parser token output error t
-> Parser token output error ([t] -> [t])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser token output error t
parse_t Parser token output error ([t] -> [t])
-> Parser token output error [t] -> Parser token output error [t]
forall a b.
Parser token output error (a -> b)
-> Parser token output error a -> Parser token output error b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser token output error t -> Parser token output error [t]
forall output token error t.
Monoid output =>
Parser token output error t -> Parser token output error [t]
parse_many Parser token output error t
parse_t
parse_token :: (Eq token, Monoid output) => token -> Parser token output error ()
parse_token :: forall token output error.
(Eq token, Monoid output) =>
token -> Parser token output error ()
parse_token token
token = (token -> Maybe ()) -> Parser token output error ()
forall output token t error.
Monoid output =>
(token -> Maybe t) -> Parser token output error t
parse_token' (token -> token -> Maybe ()
forall token. Eq token => token -> token -> Maybe ()
certain_token token
token)
parse_token' :: Monoid output => (token -> Maybe t) -> Parser token output error t
parse_token' :: forall output token t error.
Monoid output =>
(token -> Maybe t) -> Parser token output error t
parse_token' token -> Maybe t
f =
do
Tokens token
tokens <- Parser token output error (Tokens token)
forall output token error.
Monoid output =>
Parser token output error (Tokens token)
get_tokens
case (token -> Maybe t) -> Tokens token -> Maybe (t, Tokens token)
forall token t.
(token -> Maybe t) -> Tokens token -> Maybe (t, Tokens token)
take_token token -> Maybe t
f Tokens token
tokens of
Maybe (t, Tokens token)
Nothing -> Parser token output error t
forall output token error t.
Monoid output =>
Parser token output error t
parse_error'
Just (t
x, Tokens token
tokens') ->
do
RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
()
-> Parser token output error ()
forall token output error t.
RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
t
-> Parser token output error t
Parser (ASetter (State token) (State token) (Tokens token) (Tokens token)
#state_tokens ASetter (State token) (State token) (Tokens token) (Tokens token)
-> Tokens token
-> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Tokens token
tokens')
t -> Parser token output error t
forall a. a -> Parser token output error a
forall (m :: * -> *) a. Monad m => a -> m a
return t
x
parse_with_location :: Monoid output => Parser token output error t -> Parser token output error (With_location t)
parse_with_location :: forall output token error t.
Monoid output =>
Parser token output error t
-> Parser token output error (With_location t)
parse_with_location Parser token output error t
parse_t = Location -> t -> With_location t
forall t. Location -> t -> With_location t
With_location (Location -> t -> With_location t)
-> Parser token output error Location
-> Parser token output error (t -> With_location t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser token output error Location
forall output token error.
Monoid output =>
Parser token output error Location
parse_location Parser token output error (t -> With_location t)
-> Parser token output error t
-> Parser token output error (With_location t)
forall a b.
Parser token output error (a -> b)
-> Parser token output error a -> Parser token output error b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser token output error t
parse_t
run_parser :: Monoid output =>
Parser token output error t -> Tokens token -> ExceptT (Parse_error error) (Either Usage_error) (t, output)
run_parser :: forall output token error t.
Monoid output =>
Parser token output error t
-> Tokens token
-> ExceptT (Parse_error error) (Either Usage_error) (t, output)
run_parser Parser token output error t
parse_t Tokens token
tokens = RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
t
-> ()
-> State token
-> ExceptT (Parse_error error) (Either Usage_error) (t, output)
forall (m :: * -> *) r w s a.
Monad m =>
RWST r w s m a -> r -> s -> m (a, w)
evalRWST (Parser token output error t
-> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
t
forall token output error t.
Parser token output error t
-> RWST
()
output
(State token)
(ExceptT (Parse_error error) (Either Usage_error))
t
run_parser' (Parser token output error t -> Parser token output error t
forall output token error t.
Monoid output =>
Parser token output error t -> Parser token output error t
parse_end Parser token output error t
parse_t)) () (Tokens token -> Location -> State token
forall token. Tokens token -> Location -> State token
Parser.Parser.State Tokens token
tokens Location
init_location)
take_token :: (token -> Maybe t) -> Tokens token -> Maybe (t, Tokens token)
take_token :: forall token t.
(token -> Maybe t) -> Tokens token -> Maybe (t, Tokens token)
take_token token -> Maybe t
f (Tokens [With_location token]
tokens Location
end_location) =
case [With_location token]
tokens of
[] -> Maybe (t, Tokens token)
forall a. Maybe a
Nothing
With_location Location
_ token
token : [With_location token]
tokens' -> (t -> Tokens token -> (t, Tokens token))
-> Tokens token -> t -> (t, Tokens token)
forall a b c. (a -> b -> c) -> b -> a -> c
flip (,) ([With_location token] -> Location -> Tokens token
forall token. [With_location token] -> Location -> Tokens token
Tokens [With_location token]
tokens' Location
end_location) (t -> (t, Tokens token)) -> Maybe t -> Maybe (t, Tokens token)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> token -> Maybe t
f token
token
tokens_ended :: Tokens token -> Bool
tokens_ended :: forall token. Tokens token -> Bool
tokens_ended (Tokens [With_location token]
tokens Location
_) = [With_location token] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [With_location token]
tokens