module Fun.Syntax where import Data.Either import Fun.Tree data SyntaxError = SyntaxError String syntaxBlock :: Block -> Either [SyntaxError] Block syntaxBlock (FunctionBlock decl defns) = Right $ FunctionBlock decl defns mergeSyntax :: [Either [SyntaxError] a] -> ([a] -> b) -> Either [SyntaxError] b mergeSyntax d c = case any isLeft d of True -> Left $ concat $ lefts d False -> Right $ c $ rights d syntaxProgram :: Program -> Either [SyntaxError] Program syntaxProgram (Program blocks) = mergeSyntax (map syntaxBlock blocks) Program syntaxTree :: Tree -> Either [SyntaxError] Tree syntaxTree (Tree programs) = mergeSyntax (map syntaxProgram programs) Tree