package papillon

Under maintenance.

summary

item :: Type= pat1:source1[test1] pat2:source2[test2] ... { ret } / ... ;

pat1:source1[test1]
read from source1 and pattern match with pat1 and test by test1
pat1:[test1]
read from char
pat1
read from char and not test
<test>
syntax sugar for 'c:[test c] { c }'

example code

arith.hs
{-# LANGUAGE QuasiQuotes, TypeFamilies #-}

import Text.Papillon
import Data.Char
import System.Environment

main :: IO ()
main = do
	arg : _ <- getArgs
	case expr $ parse arg of
		Right (r, _) -> print r
		Left _ -> putStrLn "parse error"

[papillon|

op1 :: Int -> Int -> Int
	= '*'			{ (*) }
	/ '/'			{ div }
	/ '%'			{ mod }
;
op2 :: Int -> Int -> Int
	= '+'			{ (+) }
	/ '-'			{ (-) }
;
factor :: Int
	= ds:<isDigit>+		{ read ds }
	/ '(' e:expr ')'	{ e }
;
term :: Int
	= f0:factor fs:(op:op1 f:factor { (`op` f) })*
				{ foldl (flip ($)) f0 fs }
;
expr :: Int
	= t0:term ts:(op:op2 t:term { (`op` t) })*
				{ foldl (flip ($)) t0 ts }
;

|]