summaryrefslogtreecommitdiff
path: root/12-xml-expressions-and-patterns.md
diff options
context:
space:
mode:
authorIain McGinniss <iainmcgin@gmail.com>2012-12-20 17:06:33 +0000
committerIain McGinniss <iainmcgin@gmail.com>2012-12-20 17:06:33 +0000
commit7066c700d831dd447a4023750a61f3ac1934547d (patch)
treee87cecb85f47cf859526ea8647f65d143e820ba2 /12-xml-expressions-and-patterns.md
parentdc958b2bdc81621f14cbf29bfa3081283a5f8830 (diff)
downloadscala-7066c700d831dd447a4023750a61f3ac1934547d.tar.gz
scala-7066c700d831dd447a4023750a61f3ac1934547d.tar.bz2
scala-7066c700d831dd447a4023750a61f3ac1934547d.zip
converted xml expressions and user defined annotations chapters
Diffstat (limited to '12-xml-expressions-and-patterns.md')
-rw-r--r--12-xml-expressions-and-patterns.md96
1 files changed, 50 insertions, 46 deletions
diff --git a/12-xml-expressions-and-patterns.md b/12-xml-expressions-and-patterns.md
index 2f6756b05f..631d244575 100644
--- a/12-xml-expressions-and-patterns.md
+++ b/12-xml-expressions-and-patterns.md
@@ -1,21 +1,23 @@
XML Expressions and Patterns
============================
-{\bf By Burak Emir}\bigskip\bigskip
-
+__By Burak Emir__ \
This chapter describes the syntactic structure of XML expressions and patterns.
It follows as closely as possible the XML 1.0 specification \cite{w3c:xml},
changes being mandated by the possibility of embedding Scala code fragments.
-\section{XML expressions}
+XML expressions
+---------------
+
XML expressions are expressions generated by the following production, where the
opening bracket `<' of the first element must be in a position to start the lexical
[XML mode](#xml-mode).
-\syntax\begin{lstlisting}
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.grammar}
XmlExpr ::= XmlContent {Element}
-\end{lstlisting}
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
Well-formedness constraints of the XML specification apply, which
means for instance that start tags and end tags must match, and
attributes may only be defined once, with the exception of constraints
@@ -28,14 +30,14 @@ are changed. Scala does not support declarations, CDATA
sections or processing instructions. Entity references are not
resolved at runtime.
-\syntax\begin{lstlisting}
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.grammar}
Element ::= EmptyElemTag
| STag Content ETag
-EmptyElemTag ::= `<' Name {S Attribute} [S] `/>'
+EmptyElemTag ::= ‘<’ Name {S Attribute} [S] ‘/>’
-STag ::= `<' Name {S Attribute} [S] `>'
-ETag ::= `</' Name [S] '>'
+STag ::= ‘<’ Name {S Attribute} [S] ‘>’
+ETag ::= ‘</’ Name [S] ‘>’
Content ::= [CharData] {Content1 [CharData]}
Content1 ::= XmlContent
| Reference
@@ -44,14 +46,14 @@ XmlContent ::= Element
| CDSect
| PI
| Comment
-\end{lstlisting}
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.grammar}
If an XML expression is a single element, its value is a runtime
representation of an XML node (an instance of a subclass of
-\lstinline@scala.xml.Node@). If the XML expression consists of more
+`scala.xml.Node`). If the XML expression consists of more
than one element, then its value is a runtime representation of a
sequence of XML nodes (an instance of a subclass of
-\lstinline@scala.Seq[scala.xml.Node]@).
+`scala.Seq[scala.xml.Node]`).
If an XML expression is an entity reference, CDATA section, processing
instructions or a comments, it is represented by an instance of the
@@ -59,61 +61,63 @@ corresponding Scala runtime class.
By default, beginning and trailing whitespace in element content is removed,
and consecutive occurrences of whitespace are replaced by a single space
-character \U{0020}. This behavior can be changed to preserve all whitespace
+character \\u0020. This behavior can be changed to preserve all whitespace
with a compiler option.
-\syntax\begin{lstlisting}
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.grammar}
Attribute ::= Name Eq AttValue
-AttValue ::= `"' {CharQ | CharRef} `"'
- | `'' {CharA | CharRef} `''
+AttValue ::= ‘"’ {CharQ | CharRef} ‘"’
+ | ‘'’ {CharA | CharRef} ‘'’
| ScalaExpr
ScalaExpr ::= Block
CharData ::= { CharNoRef } $\mbox{\rm\em without}$ {CharNoRef}`{'CharB {CharNoRef}
$\mbox{\rm\em and without}$ {CharNoRef}`]]>'{CharNoRef}
-\end{lstlisting}
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
XML expressions may contain Scala expressions as attribute values or
within nodes. In the latter case, these are embedded using a single opening
-brace `\{' and ended by a closing brace `\}'. To express a single opening braces
-within XML text as generated by CharData, it must be doubled. Thus, `\{\{'
-represents the XML text `\{' and does not introduce an embedded Scala
+brace ‘{’ and ended by a closing brace ‘}’. To express a single opening braces
+within XML text as generated by CharData, it must be doubled. Thus, ‘{{’
+represents the XML text ‘{’ and does not introduce an embedded Scala
expression.
-\syntax\begin{lstlisting}
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.grammar}
BaseChar, Char, Comment, CombiningChar, Ideographic, NameChar, S, Reference
- ::= $\mbox{\rm\em ``as in W3C XML''}$
+ ::= $\mbox{\rm\em “as in W3C XML”}$
-Char1 ::= Char $\mbox{\rm\em without}$ `<' | `&'
-CharQ ::= Char1 $\mbox{\rm\em without}$ `"'
-CharA ::= Char1 $\mbox{\rm\em without}$ `''
-CharB ::= Char1 $\mbox{\rm\em without}$ '{'
+Char1 ::= Char $\mbox{\rm\em without}$ ‘<’ | ‘&’
+CharQ ::= Char1 $\mbox{\rm\em without}$ ‘"’
+CharA ::= Char1 $\mbox{\rm\em without}$ ‘'’
+CharB ::= Char1 $\mbox{\rm\em without}$ ‘{’
Name ::= XNameStart {NameChar}
-XNameStart ::= `_' | BaseChar | Ideographic
- $\mbox{\rm\em (as in W3C XML, but without }$ `:'
+XNameStart ::= ‘_’ | BaseChar | Ideographic
+ $\mbox{\rm\em (as in W3C XML, but without }$ ‘:’
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+XML patterns
+------------
-\end{lstlisting}
-\section{XML patterns}\label{sec:xml-pats}
XML patterns are patterns generated by the following production, where
-the opening bracket `<' of the element patterns must be in a position
+the opening bracket ‘<’ of the element patterns must be in a position
to start the lexical [XML mode](#xml-mode).
-\syntax\begin{lstlisting}
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.grammar}
XmlPattern ::= ElementPattern
-\end{lstlisting}%{ElementPattern}
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
Well-formedness constraints of the XML specification apply.
-An XML pattern has to be a single element pattern. It %expects the type of , and
+An XML pattern has to be a single element pattern. It
matches exactly those runtime
representations of an XML tree
-that have the same structure as described by the pattern. %If an XML pattern
-%consists of more than one element, then it expects the type of sequences
-%of runtime representations of XML trees, and matches every sequence whose
-%elements match the sequence described by the pattern.
-XML patterns may contain Scala patterns(\sref{sec:pattern-match}).
+that have the same structure as described by the pattern.
+XML patterns may contain [Scala patterns](#pattern-matching-expressions).
Whitespace is treated the same way as in XML expressions. Patterns
that are entity references, CDATA sections, processing
@@ -122,16 +126,16 @@ the same.
By default, beginning and trailing whitespace in element content is removed,
and consecutive occurrences of whitespace are replaced by a single space
-character \U{0020}. This behavior can be changed to preserve all whitespace
+character \\u0020. This behavior can be changed to preserve all whitespace
with a compiler option.
-\syntax\begin{lstlisting}
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.grammar}
ElemPattern ::= EmptyElemTagP
| STagP ContentP ETagP
-EmptyElemTagP ::= `<' Name [S] `/>'
-STagP ::= `<' Name [S] `>'
-ETagP ::= `</' Name [S]`>'
+EmptyElemTagP ::= ‘<’ Name [S] ‘/>’
+STagP ::= ‘<’ Name [S] ‘>’
+ETagP ::= ‘</’ Name [S] ‘>’
ContentP ::= [CharData] {(ElemPattern|ScalaPatterns) [CharData]}
ContentP1 ::= ElemPattern
| Reference
@@ -139,6 +143,6 @@ ContentP1 ::= ElemPattern
| PI
| Comment
| ScalaPatterns
-ScalaPatterns ::= `{' Patterns `}'
-\end{lstlisting}
+ScalaPatterns ::= ‘{’ Patterns ‘}’
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~