Imagine you were defining a textual format for XForms [xf]:
Example XForm
style xform.css
model M
instance data data.xml
submission save put:data.xml replace:none
input name "What is your name?"
submit "OK"This is going to need definitions for CSS, URIs, XPath, and a lot more. Furthermore, it would be worth modularising it into several parts that are effectively independent, reflecting the model-view-controller aspect of XForms: the model, the content, and actions. This might result in a grammar like this (this is not a complete example).
The top-level:
+uses form from form.ixml
+uses content from content.ixml
xform>html: h, form, content.
@h>xmlns: +"http://www.w3.org/1999/xhtml".
Module form.ixml:
+shares form
+uses css from css.ixml;
model from model.ixml;
iri from iri.ixml;
s from xforms-basics.ixml
form>head: title, styling?, model*.
title: ~[" "; #a], ~[#a]+, -#a.
-styling: -"style", s, (style; stylelink).
stylelink>link: csstype, cssrel, href.
style: csstype, css.
@csstype>type: +"text/css".
@cssrel>rel: +"stylesheet".
@href: -iri, s.
Module model.ixml:
+shares model
+uses s, ref, xf from xforms-basics.ixml;
id, name from xml.ixml;
Action from action.ixml;
iri from iri.ixml
model: -"model", s, id, s, xf, -#a,
s, (instance; bind; submission; Action)+.
instance: -"instance", s, id, s, resource, s.
@resource: -iri.
bind: "bind", s, (id, s)?, ref, s, property*.
property: type {; readonly; relevant; required; etc}.
type: "type:", name, s.
submission: -"submission", s, id, s,
(method, -":", resource, s)?, replace?.
@method: "get"; "put".
@replace: -"replace:", name, s.
{etc}
Module content.ixml:
+shares content
+uses IDREF from xml.ixml;
xf, ref, string, s from xforms-basics.ixml
content>body: group.
group: xf, control*.
-control: input; submit {more}.
input: -"input", s, ref, label.
label: string.
submit: -"submit", s, subid?, label?.
@subid>submission: -"submission:", IDREF, s.and so on. Giving output like:
<html xmlns='http://www.w3.org/1999/xhtml'> <head> <title>Example XForm</title> <link type='text/css' rel='stylesheet' href='xform.css'/> <model id='M' xmlns='http://www.w3.org/2002/xforms'> <instance id='data' resource='data.xml'/> <submission id='save' method='put' resource='data.xml' replace='none'/> </model> </head> <body> <group xmlns='http://www.w3.org/2002/xforms'> <input ref='name'> <label>What is your name?</label> </input> <submit> <label>OK</label> </submit> </group> </body> </html>