-- | A model for Hydra labeled-BNF grammars

module Hydra.Impl.Haskell.Sources.Grammar where

import Hydra.All
import Hydra.Impl.Haskell.Dsl.Types as Types
import Hydra.Impl.Haskell.Dsl.Standard
import Hydra.Impl.Haskell.Sources.Core


hydraGrammarModule :: Module Meta
hydraGrammarModule :: Module Meta
hydraGrammarModule = forall m.
Namespace -> [Element m] -> [Module m] -> Maybe String -> Module m
Module Namespace
ns forall {m}. [Element m]
elements [] forall a b. (a -> b) -> a -> b
$
    forall a. a -> Maybe a
Just String
"A common API for BNF-based grammars"
  where
    ns :: Namespace
ns = String -> Namespace
Namespace String
"hydra/grammar"
    grammar :: String -> Type m
grammar = forall m. Namespace -> String -> Type m
nsref Namespace
ns
    def :: String -> Type m -> Element m
def = forall m. Namespace -> String -> Type m -> Element m
datatype Namespace
ns

    elements :: [Element m]
elements = [

      forall {m}. String -> Type m -> Element m
def String
"Constant" forall m. Type m
string,

      forall {m}. String -> Type m -> Element m
def String
"Grammar" forall a b. (a -> b) -> a -> b
$ forall m. Type m -> Type m
list forall a b. (a -> b) -> a -> b
$ forall {m}. String -> Type m
grammar String
"Production",

      forall {m}. String -> Type m -> Element m
def String
"Label" forall m. Type m
string,

      forall {m}. String -> Type m -> Element m
def String
"LabeledPattern" forall a b. (a -> b) -> a -> b
$ forall m. [FieldType m] -> Type m
record [
        String
"label"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
grammar String
"Label",
        String
"pattern"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
grammar String
"Pattern"],

      forall {m}. String -> Type m -> Element m
def String
"Pattern" forall a b. (a -> b) -> a -> b
$ forall m. [FieldType m] -> Type m
union [
        String
"nil"forall m. String -> Type m -> FieldType m
>: forall m. Type m
unit,
        String
"ignored"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
grammar String
"Pattern",
        String
"labeled"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
grammar String
"LabeledPattern",
        String
"constant"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
grammar String
"Constant",
        String
"regex"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
grammar String
"Regex",
        String
"nonterminal"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
grammar String
"Symbol",
        String
"sequence"forall m. String -> Type m -> FieldType m
>: forall m. Type m -> Type m
list forall a b. (a -> b) -> a -> b
$ forall {m}. String -> Type m
grammar String
"Pattern",
        String
"alternatives"forall m. String -> Type m -> FieldType m
>: forall m. Type m -> Type m
list forall a b. (a -> b) -> a -> b
$ forall {m}. String -> Type m
grammar String
"Pattern",
        String
"option"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
grammar String
"Pattern",
        String
"star"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
grammar String
"Pattern",
        String
"plus"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
grammar String
"Pattern"],

      forall {m}. String -> Type m -> Element m
def String
"Production" forall a b. (a -> b) -> a -> b
$ forall m. [FieldType m] -> Type m
record [
        String
"symbol"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
grammar String
"Symbol",
        String
"pattern"forall m. String -> Type m -> FieldType m
>: forall {m}. String -> Type m
grammar String
"Pattern"],

      forall {m}. String -> Type m -> Element m
def String
"Regex" forall m. Type m
string,

      forall {m}. String -> Type m -> Element m
def String
"Symbol" forall m. Type m
string]