# $Id$

start = publimeta


publimeta = element publimeta {
   publimeta.attributes,
   publimeta.content
}

publimeta.attributes =
   version.attribute
version.attribute = attribute version { "1.0" }

publimeta.content =
   metadatas


# =============================================================================
#                                    TOP LEVEL
# =============================================================================

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ metadatas ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

metadatas = element metadatas { metadatas.content }

metadatas.content =
   metadata+

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ metadata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

metadata = element metadata { metadata.attributes, metadata.content }

metadata.attributes =
   metadata.for.attribute
 & lang.attribute?
metadata.for.attribute = attribute for { xsd:NMTOKEN }
lang.attribute = attribute xml:lang { xsd:language }
   
metadata.content =
   (title, shorttitle?, subtitle*)?
 & identifier*
 & copyright*
 & collection?
 & contributors?
 & date?
 & keywordset?
 & subjectset?
 & abstract?
 & price*


# =============================================================================
#                                  METADATA LEVEL
# =============================================================================

# ~~~~~~~~~~~~~~~~~~~~~~~ title, shorttitle, subtitle ~~~~~~~~~~~~~~~~~~~~~~~~~

title = element title { title.content }
shorttitle = element shorttitle { title.content }
subtitle = element subtitle { title.content }

title.content = inlines

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ identifier ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# ~~~~~~ identifier
identifier = element identifier {
   (attribute type { "ean" }, for.attribute?, xsd:token {pattern = "\d{13}"})
 | (attribute type { "uri" }, for.attribute?, xsd:anyURI)
}

for.attribute = attribute for { xsd:NCName }

# ~~~~~~ identifier.ean
identifier.ean = element identifier {
   attribute type { "ean" }, for.attribute?, xsd:token {pattern = "\d{13}"}
}

# ~~~~~~ identifier.uri
identifier.uri = element identifier {
   attribute type { "uri" }, for.attribute?, xsd:anyURI
}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ copyright ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

copyright = element copyright { copyright.content }

copyright.content = inlines

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ collection ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

collection = element collection { collection.content }

collection.content = inlines

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ contributors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# ~~~~~~ contributors
contributors = element contributors { contributors.content }

contributors.content =
   contributor+

# ~~~~~~ contributor
contributor = element contributor { contributor.content }

contributor.content =
   identifier.uri?,
   (((firstname, secondname?)?, lastname) | label),
   address?,
   link?,
   role+

# ~~~~~~ firstname, secondname, lastname, label
firstname = element firstname { firstname.content }
secondname = element secondname { secondname.content }
lastname = element lastname { lastname.content }
label = element label { label.content }

firstname.content = inlines
secondname.content = inlines
lastname.content = inlines
label.content = inlines

# ~~~~~~ address
address = element address { address.content }

address.content = inlines

# ~~~~~~ role
role = element role { role.content }

role.content = "author" | "illustrator" | "publisher" | "packager"

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ keyword & subject ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# ~~~~~~ keywordset
keywordset = element keywordset { keywordset.content }

keywordset.content = keyword+

# ~~~~~~ keyword
keyword = element keyword { keyword.content }

keyword.content = mixed { sup*, sub* }

# ~~~~~~ subjectset
subjectset = element subjectset { subjectset.content }

subjectset.content = subject+

# ~~~~~~ subject
subject = element subject { subject.content }

subject.content = mixed { sup*, sub* }

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ abstract ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

abstract = element abstract { abstract.content }

abstract.content =
   p+

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ price ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

price = element price { price.attributes, price.content }

price.attributes =
   currency.attribute
 & excluding_tax.attribute
 & tax.attribute?
currency.attribute = attribute currency {
   "EUR" | "USD" | "GBP" | "CAD" | "CHF" | "JPY" | "MXN" | "KRW" | "BRL"
 | "INR" | "AUD" | "RUB" | "CNY" | "NOK" | "SEK" | "DKK" }
excluding_tax.attribute = attribute excluding-tax { xsd:boolean }
tax.attribute = attribute tax { xsd:float }

price.content = xsd:float
   

# =============================================================================
#                                 BLOCK LEVEL
# =============================================================================

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ p ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

p = element p { p.content }

p.content =
   inlines


# =============================================================================
#                                 INLINE LEVEL
# =============================================================================

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ inlines ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

inlines = mixed {
   sup*
 & sub*
 & date*
 & name*
 & highlight*
 & link*
}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ sub, sup ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

sup = element sup { inlines }

sub = element sub { inlines }

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ date ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

date = element date { date.attributes, date.content }

date.attributes =
   date.value.attribute
date.value.attribute = attribute value { xsd:date | xsd:gYearMonth | xsd:gYear }

date.content = mixed { sup* }

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ name ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

name = element name { name.attributes, name.content }

name.attributes =
   name.of.attribute?
name.of.attribute = attribute of {
   "person" | "company" | "book" | "newspaper" | "party" | "painting"
 | "movie" }

name.content = mixed { sup* }

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ highlight ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

highlight = element highlight { highlight.content }

highlight.content = inlines

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ link ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

link = element link { link.attributes, link.content }

link.attributes =
   uri.attribute
uri.attribute = attribute uri { xsd:anyURI }

link.content = mixed { sup* & sub* & date* & name* & highlight* }


# =============================================================================
#                               REMAP ATTRIBUTES
# =============================================================================

remap.attributes =
   as.attribute?
 & attributes.attribute?
 & transform.attribute?
as.attribute = attribute as { xsd:QName }
attributes.attribute =
   attribute attributes {list { (xsd:token {pattern = "\c+=\S+"})+ }}
transform.attribute = attribute transform { xsd:anyURI }
