1{-# LANGUAGE OverloadedStrings #-}
2
3-- | This module implmeents a 'Formatter' for Scheme syntax definitions.
4module SchemeDoc.Format.Syntax (Syntax, mkSyntax) where
5
6import qualified Data.Text as T
7import SchemeDoc.Format.Types
8import SchemeDoc.Format.Util
9import SchemeDoc.Types
10
11-- | A R7RS syntax definition.
12newtype Syntax = Syntax
13 { name :: T.Text
14 -- ^ Name of the syntax definition
15 }
16 deriving (Eq, Show)
17
18instance Formatable Syntax where
19 -- For syntax definitions, usage instruction should be
20 -- provided in the accompanying documentation comment.
21 fmt (Syntax keyword) desc =
22 mkDeclaration keyword desc $ \n ->
23 do
24 component "syntax " n
25 fromMkd desc
26
27-- | Parse a Scheme syntax definition
28--
29-- > <syntax definition> →
30-- > (define-syntax <keyword> <transformer spec>)
31mkSyntax :: Sexp -> Maybe Syntax
32mkSyntax (List (Id "define-syntax" : Id keyword : _)) =
33 Just $ Syntax keyword
34mkSyntax _ = Nothing