:: Error = PositionalError Int Int String | Error String
:: Parser a b = Parser ([a] -> (Either Error b, [a]))
\end{CleanCode}
+ \pause
+ \item Result is either Error or \texttt{b}, not a \texttt{[b]} as
+ described Hutton \& Meijer \footnote{G. Hutton and E. Meijer.
+ Monadic parser combinators. 1996.}
\pause
\item Matches longest left-most parser
\pause
\begin{frame}[fragile]
\frametitle{\textsc{YARD} Combinators}
- \begin{CleanCode}
-instance Functor (Parser a)
-instance Applicative (Parser a)
-instance Monad (Parser a)
-instance Alternative (Parser a)
-
-runParser :: (Parser a b) [a] -> (Either Error b, [a])
-(<?>) :: (Parser a b) Error -> Parser a b
+ \framesubtitle{Designed to be minimal, just 14 parsers/combinators}
+ YARD is designed to be minimal and defines just 14 primitives:
+ \begin{columns}[t]
+ \begin{column}{0.5\textwidth}
+ \begin{CleanCode}
+top :: Parser a a
+peek :: Parser a a
fail :: Parser a b
+eof :: Parser a Void
+(until) :: (Parser a b)
+ (Parser a c)
+ -> Parser a [b]
+satisfy :: (a -> Bool)
+ -> Parser a a
+check :: (a -> Bool)
+ -> Parser a a
+item :: a -> Parser a a
+list :: [a] -> Parser a [a]
+ \end{CleanCode}
+ \end{column}
+ \begin{column}{0.5\textwidth}
+ \begin{CleanCode}
+(>>=) :: (Parser a b)
+ (b -> Parser a c)
+ -> Parser a c
+(<|>) :: (Parser a b)
+ (Parser a b)
+ -> Parser a b
+some :: (Parser a b)
+ -> Parser a [b]
+many :: (Parser a b)
+ -> Parser a [b]
+optional :: (Parser a b)
+ -> Parser a (Maybe b)
+ \end{CleanCode}
+ \end{column}
+ \end{columns}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{\textsc{YARD} Combinators}
+ \framesubtitle{Designed to be minimal, just \textbf{7} parsers/combinators}
+ Actually, scrap that, just \textbf{7} primitives:
+ \begin{columns}[t]
+ \begin{column}{0.5\textwidth}
+ \begin{CleanCode}
top :: Parser a a
peek :: Parser a a
-satisfy :: (a -> Bool) -> Parser a a
-check :: (a -> Bool) -> Parser a a
-(until) infix 2 :: (Parser a b) (Parser a c) -> Parser a [b]
-item :: a -> Parser a a | Eq a
-list :: [a] -> Parser a [a] | Eq a
+fail :: Parser a b
eof :: Parser a Void
- \end{CleanCode}
+ \end{CleanCode}
+ \end{column}
+ \begin{column}{0.5\textwidth}
+ \begin{CleanCode}
+(>>=) :: (Parser a b)
+ (b -> Parser a c)
+ -> Parser a c
+(<|>) :: (Parser a b)
+ (Parser a b)
+ -> Parser a b
+ \end{CleanCode}
+ \end{column}
+ \end{columns}
+ All others can be (and are) derived from these. e.g.
+ \begin{lstlisting}
+satisfy :: (a -> Bool) -> Parser a a
+satisfy f = top >>= \c -> if (f c) (return c) fail
+ \end{lstlisting}
\end{frame}
\section{Design choices}