0 | module Text.WebIDL.Codegen.Definitions
3 | import Data.List.Elem
6 | import Text.WebIDL.Codegen.Args
7 | import Text.WebIDL.Codegen.Enum
8 | import Text.WebIDL.Codegen.Members
9 | import Text.WebIDL.Codegen.Rules
10 | import Text.WebIDL.Codegen.Types
11 | import public Text.WebIDL.Codegen.Util
19 | defImports : CGDomain -> String
22 | import Web.Internal.\{d.name}Prim
23 | import Web.Internal.Types
26 | typeImports : String
27 | typeImports = "import JS"
33 | extern : CGDomain -> String
36 | [ section "Interfaces" $
exts ext name d.ifaces
37 | , section "Dictionaries" $
exts extNoCast name d.dicts
38 | , section "Mixins" $
exts extNoCast name d.mixins
39 | , section "Callbacks" $
exts extNoCast name d.callbacks
43 | extNoCast : String -> String
45 | export data \{s} : Type where [external]
48 | ToFFI \{s} \{s} where toFFI = id
51 | FromFFI \{s} \{s} where fromFFI = Just
54 | ext : String -> String
55 | ext s = extNoCast s ++ "\n\n" ++ """
58 | safeCast = unsafeCastOnPrototypeName "\{s}"
62 | (f : String -> String)
63 | -> (a -> Identifier)
66 | exts f g = map (("\n" ++) . f) . sort . map (value . g)
72 | cbacks : (CGCallback -> List String) -> CGDomain -> String
73 | cbacks f = section "Callbacks" . map ns . sortBy (comparing name) . callbacks
74 | where ns : CGCallback -> String
75 | ns i = namespaced i.name (f i)
77 | callbacks : CGDomain -> String
78 | callbacks = cbacks go
79 | where go : CGCallback -> List String
80 | go cb = callback cb :: constants cb.constants
82 | primCallbacks : CGDomain -> String
83 | primCallbacks = cbacks (pure . primCallback)
89 | jsTypes : List CGDomain -> String
91 | let ifs := sortBy (comparing name) (ds >>= ifaces)
92 | dics := sortBy (comparing name) (ds >>= dicts)
93 | in section "Inheritance" $
94 | map (\i => jsType i.name i.super) ifs ++
95 | map (\d => jsType d.name d.super) dics
101 | ifaces' : (CGIface -> List String) -> CGDomain -> String
102 | ifaces' f = section "Interfaces" . map ns . sortBy (comparing name) . ifaces
105 | ns : CGIface -> String
106 | ns i = namespaced i.name (f i)
108 | ifaces : CGDomain -> String
109 | ifaces = ifaces' $
\(MkIface n s cs fs) => constants cs ++ functions fs
111 | primIfaces : CGDomain -> String
112 | primIfaces = ifaces' (primFunctions . functions)
118 | dicts' : (CGDict -> List String) -> CGDomain -> String
119 | dicts' f = section "Dictionaries" . map ns . sortBy (comparing name) . dicts
122 | ns : CGDict -> String
123 | ns d = namespaced d.name (f d)
125 | dicts : CGDomain -> String
126 | dicts = dicts' $
\(MkDict n s fs) => functions fs
128 | primDicts : CGDomain -> String
129 | primDicts = dicts' (primFunctions . functions)
135 | mixins' : (CGMixin -> List String) -> CGDomain -> String
136 | mixins' f = section "Mixins" . map ns . sortBy (comparing name) . mixins
139 | ns : CGMixin -> String
140 | ns m = namespaced m.name (f m)
142 | mixins : CGDomain -> String
143 | mixins = mixins' $
\(MkMixin n cs fs) => constants cs ++ functions fs
145 | primMixins : CGDomain -> String
146 | primMixins = mixins' (primFunctions . functions)
153 | typedefs : List CGDomain -> String
156 | module Web.Internal.Types
159 | import public Web.Internal.AnimationTypes as Types
160 | import public Web.Internal.ClipboardTypes as Types
161 | import public Web.Internal.CssTypes as Types
162 | import public Web.Internal.CssomviewTypes as Types
163 | import public Web.Internal.DomTypes as Types
164 | import public Web.Internal.FetchTypes as Types
165 | import public Web.Internal.FileTypes as Types
166 | import public Web.Internal.GeometryTypes as Types
167 | import public Web.Internal.HtmlTypes as Types
168 | import public Web.Internal.IndexedDBTypes as Types
169 | import public Web.Internal.MediasourceTypes as Types
170 | import public Web.Internal.MediastreamTypes as Types
171 | import public Web.Internal.PermissionsTypes as Types
172 | import public Web.Internal.ServiceworkerTypes as Types
173 | import public Web.Internal.StreamsTypes as Types
174 | import public Web.Internal.SvgTypes as Types
175 | import public Web.Internal.UIEventsTypes as Types
176 | import public Web.Internal.UrlTypes as Types
177 | import public Web.Internal.VisibilityTypes as Types
178 | import public Web.Internal.WebglTypes as Types
179 | import public Web.Internal.WebidlTypes as Types
180 | import public Web.Internal.XhrTypes as Types
183 | """ ++ "\n\n" ++ jsTypes ds
190 | types : CGDomain -> String
193 | module Web.Internal.\{d.name}Types
204 | primitives : CGDomain -> String
207 | module Web.Internal.\{d.name}Prim
210 | import Web.Internal.Types
221 | definitions : CGDomain -> String
224 | module Web.Raw.\{d.name}
230 | \{Definitions.ifaces d}
231 | \{Definitions.mixins d}
232 | \{Definitions.dicts d}
233 | \{Definitions.callbacks d}