{-# LANGUAGE DeriveGeneric #-}

module MirageSyntax where

import Data.Aeson (ToJSON)
import GHC.Generics (Generic)

data Grammar = Grammar [Nonterminal] deriving forall x. Rep Grammar x -> Grammar
forall x. Grammar -> Rep Grammar x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Grammar x -> Grammar
$cfrom :: forall x. Grammar -> Rep Grammar x
Generic

instance ToJSON Grammar

data Nonterminal = Nonterminal
  String       -- ^ The name of this nonterminal.
  [String]     -- ^ The names of the parameters.
  [Attribute]  -- ^ The inherited attributes.
  [Attribute]  -- ^ The synthesized attributes.
  [Production] -- ^ The production rules with this nonterminal on the left hand side.
  deriving forall x. Rep Nonterminal x -> Nonterminal
forall x. Nonterminal -> Rep Nonterminal x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Nonterminal x -> Nonterminal
$cfrom :: forall x. Nonterminal -> Rep Nonterminal x
Generic

instance ToJSON Nonterminal

data Attribute = Attribute
  String -- ^ The name of this attribute.
  Type   -- ^ The type of this attribute.
  deriving forall x. Rep Attribute x -> Attribute
forall x. Attribute -> Rep Attribute x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Attribute x -> Attribute
$cfrom :: forall x. Attribute -> Rep Attribute x
Generic

instance ToJSON Attribute

data Production = Production
  String  -- ^ The name of this production rule.
  [Child] -- ^ The children of this rule; the right hand side.
  [Rule]  -- ^ The attribute rules of this production.
  deriving forall x. Rep Production x -> Production
forall x. Production -> Rep Production x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Production x -> Production
$cfrom :: forall x. Production -> Rep Production x
Generic

instance ToJSON Production

data Child = Child
  String -- ^ The name of this child.
  Type   -- ^ The type of this child.
  deriving forall x. Rep Child x -> Child
forall x. Child -> Rep Child x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Child x -> Child
$cfrom :: forall x. Child -> Rep Child x
Generic

instance ToJSON Child

data Rule = Rule
  [Address] -- ^ Targets of this rule; the left hand side.
  [Address] -- ^ Sources of this rule; the right hand side.
  Bool      -- ^ Whether this rule is defined explicitly by the user.
  String    -- ^ The origin of this rule; which source file contains this rule?
  String    -- ^ A pretty printed representation of this rule.
  deriving forall x. Rep Rule x -> Rule
forall x. Rule -> Rep Rule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Rule x -> Rule
$cfrom :: forall x. Rule -> Rep Rule x
Generic

instance ToJSON Rule

data Type
  = Haskell String -- ^ A plain Haskell type.
  | NT             -- ^ An attribute grammar nonterminal
      String       -- ^ The name of the nonterminal
      [String]     -- ^ The arguments of this nonterminal; must always be plain Haskell values.
  | Self           -- ^ Refers to the nonterminal in which this type is used.
  deriving forall x. Rep Type x -> Type
forall x. Type -> Rep Type x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Type x -> Type
$cfrom :: forall x. Type -> Rep Type x
Generic

instance ToJSON Type

data Address = Address
  String -- ^ The part before the dot: 'lhs', 'loc', or the name of a child.
  String -- ^ The attribute name
  deriving forall x. Rep Address x -> Address
forall x. Address -> Rep Address x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Address x -> Address
$cfrom :: forall x. Address -> Rep Address x
Generic

instance ToJSON Address