summaryrefslogtreecommitdiff
path: root/spec/10-xml-expressions-and-patterns.md
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2014-03-28 16:45:45 -0700
committerAdriaan Moors <adriaan.moors@typesafe.com>2014-03-28 17:40:57 -0700
commit0b48dc203e0e789646841880f49cd8ae08f6412d (patch)
treefd0bed2defecbe4d3d79cb8154d2343095fc2add /spec/10-xml-expressions-and-patterns.md
parent0f1dcc41cb445eac182c8101a3e0c95594b0f95e (diff)
downloadscala-0b48dc203e0e789646841880f49cd8ae08f6412d.tar.gz
scala-0b48dc203e0e789646841880f49cd8ae08f6412d.tar.bz2
scala-0b48dc203e0e789646841880f49cd8ae08f6412d.zip
Number files like chapters. Consolidate toc & preface.
Aside from the consolidation of title & preface in index.md, this commit was produced as follows: ``` cd spec/ g mv 03-lexical-syntax.md 01-lexical-syntax.md g mv 04-identifiers-names-and-scopes.md 02-identifiers-names-and-scopes.md g mv 05-types.md 03-types.md g mv 06-basic-declarations-and-definitions.md 04-basic-declarations-and-definitions.md g mv 07-classes-and-objects.md 05-classes-and-objects.md g mv 08-expressions.md 06-expressions.md g mv 09-implicit-parameters-and-views.md 07-implicit-parameters-and-views.md g mv 10-pattern-matching.md 08-pattern-matching.md g mv 11-top-level-definitions.md 09-top-level-definitions.md g mv 12-xml-expressions-and-patterns.md 10-xml-expressions-and-patterns.md g mv 13-user-defined-annotations.md 11-user-defined-annotations.md g mv 14-the-scala-standard-library.md 12-the-scala-standard-library.md g mv 15-syntax-summary.md 13-syntax-summary.md g mv 16-references.md 14-references.md perl -pi -e 's/03-lexical-syntax/01-lexical-syntax/g' *.md perl -pi -e 's/04-identifiers-names-and-scopes/02-identifiers-names-and-scopes/g' *.md perl -pi -e 's/05-types/03-types/g' *.md perl -pi -e 's/06-basic-declarations-and-definitions/04-basic-declarations-and-definitions/g' *.md perl -pi -e 's/07-classes-and-objects/05-classes-and-objects/g' *.md perl -pi -e 's/08-expressions/06-expressions/g' *.md perl -pi -e 's/09-implicit-parameters-and-views/07-implicit-parameters-and-views/g' *.md perl -pi -e 's/10-pattern-matching/08-pattern-matching/g' *.md perl -pi -e 's/11-top-level-definitions/09-top-level-definitions/g' *.md perl -pi -e 's/12-xml-expressions-and-patterns/10-xml-expressions-and-patterns/g' *.md perl -pi -e 's/13-user-defined-annotations/11-user-defined-annotations/g' *.md perl -pi -e 's/14-the-scala-standard-library/12-the-scala-standard-library/g' *.md perl -pi -e 's/15-syntax-summary/13-syntax-summary/g' *.md perl -pi -e 's/16-references/14-references/g' *.md ```
Diffstat (limited to 'spec/10-xml-expressions-and-patterns.md')
-rw-r--r--spec/10-xml-expressions-and-patterns.md147
1 files changed, 147 insertions, 0 deletions
diff --git a/spec/10-xml-expressions-and-patterns.md b/spec/10-xml-expressions-and-patterns.md
new file mode 100644
index 0000000000..d8c45ecf85
--- /dev/null
+++ b/spec/10-xml-expressions-and-patterns.md
@@ -0,0 +1,147 @@
+---
+title: XML Expressions and Patterns
+layout: default
+chapter: 10
+---
+
+# XML Expressions and Patterns
+
+__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,
+changes being mandated by the possibility of embedding Scala code fragments.
+
+## 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](01-lexical-syntax.html#xml-mode).
+
+```ebnf
+XmlExpr ::= XmlContent {Element}
+```
+
+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
+related to entity resolution.
+
+The following productions describe Scala's extensible markup language,
+designed as close as possible to the W3C extensible markup language
+standard. Only the productions for attribute values and character data are changed.
+Scala does not support declarations, CDATA sections or processing instructions.
+Entity references are not resolved at runtime.
+
+```ebnf
+Element ::= EmptyElemTag
+ | STag Content ETag
+
+EmptyElemTag ::= ‘<’ Name {S Attribute} [S] ‘/>’
+
+STag ::= ‘<’ Name {S Attribute} [S] ‘>’
+ETag ::= ‘</’ Name [S] ‘>’
+Content ::= [CharData] {Content1 [CharData]}
+Content1 ::= XmlContent
+ | Reference
+ | ScalaExpr
+XmlContent ::= Element
+ | CDSect
+ | PI
+ | Comment
+```
+
+If an XML expression is a single element, its value is a runtime
+representation of an XML node (an instance of a subclass of
+`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
+`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
+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 `\u0020`. This behavior can be changed to preserve all whitespace
+with a compiler option.
+
+```ebnf
+Attribute ::= Name Eq AttValue
+
+AttValue ::= ‘"’ {CharQ | CharRef} ‘"’
+ | ‘'’ {CharA | CharRef} ‘'’
+ | ScalaExpr
+
+ScalaExpr ::= Block
+
+CharData ::= { CharNoRef } $\mbox{\rm\em without}$ {CharNoRef}`{'CharB {CharNoRef}
+ $\mbox{\rm\em and without}$ {CharNoRef}`]]>'{CharNoRef}
+```
+
+<!-- {% raw %} stupid liquid borks on the double brace below; brace yourself, liquid! -->
+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 expression.
+<!-- {% endraw %} -->
+
+```ebnf
+BaseChar, Char, Comment, CombiningChar, Ideographic, NameChar, S, Reference
+ ::= $\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}$ ‘{’
+
+Name ::= XNameStart {NameChar}
+
+XNameStart ::= ‘_’ | BaseChar | Ideographic
+ $\mbox{\rm\em (as in W3C XML, but without }$ ‘:’
+```
+
+## XML patterns
+
+XML patterns are patterns generated by the following production, where
+the opening bracket `<` of the element patterns must be in a position
+to start the lexical [XML mode](01-lexical-syntax.html#xml-mode).
+
+```ebnf
+XmlPattern ::= ElementPattern
+```
+
+Well-formedness constraints of the XML specification apply.
+
+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.
+XML patterns may contain [Scala patterns](08-pattern-matching.html#pattern-matching-expressions).
+
+Whitespace is treated the same way as in XML expressions.
+
+By default, beginning and trailing whitespace in element content is removed,
+and consecutive occurrences of whitespace are replaced by a single space
+character `\u0020`. This behavior can be changed to preserve all whitespace
+with a compiler option.
+
+```ebnf
+ElemPattern ::= EmptyElemTagP
+ | STagP ContentP ETagP
+
+EmptyElemTagP ::= ‘<’ Name [S] ‘/>’
+STagP ::= ‘<’ Name [S] ‘>’
+ETagP ::= ‘</’ Name [S] ‘>’
+ContentP ::= [CharData] {(ElemPattern|ScalaPatterns) [CharData]}
+ContentP1 ::= ElemPattern
+ | Reference
+ | CDSect
+ | PI
+ | Comment
+ | ScalaPatterns
+ScalaPatterns ::= ‘{’ Patterns ‘}’
+```
+