module Hydra.Sources.Tier0.Grammar where
import qualified Data.List as L
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.Maybe as Y
import Hydra.Dsl.Annotations
import Hydra.Dsl.Bootstrap
import qualified Hydra.Dsl.Terms as Terms
import Hydra.Dsl.Types as Types
import Hydra.Sources.Core
hydraGrammarModule :: Module
hydraGrammarModule :: Module
hydraGrammarModule = Namespace
-> [Element] -> [Module] -> [Module] -> Maybe String -> Module
Module Namespace
ns [Element]
elements [Module
hydraCoreModule] [Module
hydraCoreModule] (Maybe String -> Module) -> Maybe String -> Module
forall a b. (a -> b) -> a -> b
$
String -> Maybe String
forall a. a -> Maybe a
Just String
"A common API for BNF-based grammars, specifying context-free languages"
where
ns :: Namespace
ns = String -> Namespace
Namespace String
"hydra/grammar"
grammar :: String -> Type
grammar = Namespace -> String -> Type
typeref Namespace
ns
def :: String -> Type -> Element
def = Namespace -> String -> Type -> Element
datatype Namespace
ns
elements :: [Element]
elements = [
String -> Type -> Element
def String
"Constant" (Type -> Element) -> Type -> Element
forall a b. (a -> b) -> a -> b
$
String -> Type -> Type
doc String
"A constant pattern"
Type
string,
String -> Type -> Element
def String
"Grammar" (Type -> Element) -> Type -> Element
forall a b. (a -> b) -> a -> b
$
String -> Type -> Type
doc String
"An enhanced Backus-Naur form (BNF) grammar" (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$
Type -> Type
list (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$ String -> Type
grammar String
"Production",
String -> Type -> Element
def String
"Label" (Type -> Element) -> Type -> Element
forall a b. (a -> b) -> a -> b
$
String -> Type -> Type
doc String
"A name for a pattern"
Type
string,
String -> Type -> Element
def String
"LabeledPattern" (Type -> Element) -> Type -> Element
forall a b. (a -> b) -> a -> b
$
String -> Type -> Type
doc String
"A pattern together with a name (label)" (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$
[FieldType] -> Type
record [
String
"label"String -> Type -> FieldType
>: String -> Type
grammar String
"Label",
String
"pattern"String -> Type -> FieldType
>: String -> Type
grammar String
"Pattern"],
String -> Type -> Element
def String
"Pattern" (Type -> Element) -> Type -> Element
forall a b. (a -> b) -> a -> b
$
String -> Type -> Type
doc String
"A pattern which matches valid expressions in the language" (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$
[FieldType] -> Type
union [
String
"nil"String -> Type -> FieldType
>: Type
unit,
String
"ignored"String -> Type -> FieldType
>: String -> Type
grammar String
"Pattern",
String
"labeled"String -> Type -> FieldType
>: String -> Type
grammar String
"LabeledPattern",
String
"constant"String -> Type -> FieldType
>: String -> Type
grammar String
"Constant",
String
"regex"String -> Type -> FieldType
>: String -> Type
grammar String
"Regex",
String
"nonterminal"String -> Type -> FieldType
>: String -> Type
grammar String
"Symbol",
String
"sequence"String -> Type -> FieldType
>: Type -> Type
list (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$ String -> Type
grammar String
"Pattern",
String
"alternatives"String -> Type -> FieldType
>: Type -> Type
list (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$ String -> Type
grammar String
"Pattern",
String
"option"String -> Type -> FieldType
>: String -> Type
grammar String
"Pattern",
String
"star"String -> Type -> FieldType
>: String -> Type
grammar String
"Pattern",
String
"plus"String -> Type -> FieldType
>: String -> Type
grammar String
"Pattern"],
String -> Type -> Element
def String
"Production" (Type -> Element) -> Type -> Element
forall a b. (a -> b) -> a -> b
$
String -> Type -> Type
doc String
"A BNF production" (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$
[FieldType] -> Type
record [
String
"symbol"String -> Type -> FieldType
>: String -> Type
grammar String
"Symbol",
String
"pattern"String -> Type -> FieldType
>: String -> Type
grammar String
"Pattern"],
String -> Type -> Element
def String
"Regex" (Type -> Element) -> Type -> Element
forall a b. (a -> b) -> a -> b
$
String -> Type -> Type
doc String
"A regular expression"
Type
string,
String -> Type -> Element
def String
"Symbol" (Type -> Element) -> Type -> Element
forall a b. (a -> b) -> a -> b
$
String -> Type -> Type
doc String
"A nonterminal symbol"
Type
string]