Skip to content

Commit

Permalink
- Grouping of text for examples in Lexical Syntax chapter fixed
Browse files Browse the repository at this point in the history
- Style of examples elements changed to delineate grouped examples.
  • Loading branch information
iainmcgin committed Oct 19, 2012
1 parent f938a7c commit 7d50d8f
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 106 deletions.
210 changes: 105 additions & 105 deletions 03-lexical-syntax.md
Expand Up @@ -94,17 +94,17 @@ equivalents ‘=>’ and ‘<-’, are also reserved.


(@) Here are examples of identifiers: (@) Here are examples of identifiers:


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
x Object maxIndex p2p empty_? x Object maxIndex p2p empty_?
+ `yield` αρετη _y dot_product_* + `yield` αρετη _y dot_product_*
__system _MAX_LEN_ __system _MAX_LEN_
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


(@) Backquote-enclosed strings are a solution when one needs to (@) Backquote-enclosed strings are a solution when one needs to
access Java identifiers that are reserved words in Scala. For access Java identifiers that are reserved words in Scala. For
instance, the statement `Thread.yield()` is illegal, since instance, the statement `Thread.yield()` is illegal, since
`yield` is a reserved word in Scala. However, here's a `yield` is a reserved word in Scala. However, here's a
work-around: `` Thread.`yield`() ``{.scala} work-around: `` Thread.`yield`() ``{.scala}




Newline Characters Newline Characters
Expand Down Expand Up @@ -202,95 +202,95 @@ A single new line token is accepted
- after an annotation ([here](#user-defined-annotations)). - after an annotation ([here](#user-defined-annotations)).


(@) The following code contains four well-formed statements, each (@) The following code contains four well-formed statements, each
on two lines. The newline tokens between the two lines are not on two lines. The newline tokens between the two lines are not
treated as statement separators. treated as statement separators.


~~~~~~~~~~~~~~~~~~~~~~ {.scala} ~~~~~~~~~~~~~~~~~~~~~~ {.scala}
if (x > 0) if (x > 0)
x = x - 1 x = x - 1


while (x > 0) while (x > 0)
x = x / 2 x = x / 2


for (x <- 1 to 10) for (x <- 1 to 10)
println(x) println(x)


type type
IntList = List[Int] IntList = List[Int]
~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~


(@) The following code designates an anonymous class: (@) The following code designates an anonymous class:


~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.scala} ~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.scala}
new Iterator[Int] new Iterator[Int]
{ {
private var x = 0 private var x = 0
def hasNext = true def hasNext = true
def next = { x += 1; x } def next = { x += 1; x }
} }
~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~


With an additional newline character, the same code is interpreted as With an additional newline character, the same code is interpreted as
an object creation followed by a local block: an object creation followed by a local block:


~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.scala} ~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.scala}
new Iterator[Int] new Iterator[Int]


{ {
private var x = 0 private var x = 0
def hasNext = true def hasNext = true
def next = { x += 1; x } def next = { x += 1; x }
} }
~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~


(@) The following code designates a single expression: (@) The following code designates a single expression:


~~~~~~~~~~~~ {.scala} ~~~~~~~~~~~~ {.scala}
x < 0 || x < 0 ||
x > 10 x > 10
~~~~~~~~~~~~ ~~~~~~~~~~~~


With an additional newline character, the same code is interpreted as With an additional newline character, the same code is interpreted as
two expressions: two expressions:


~~~~~~~~~~~ {.scala} ~~~~~~~~~~~ {.scala}
x < 0 || x < 0 ||


x > 10 x > 10
~~~~~~~~~~~ ~~~~~~~~~~~


(@) The following code designates a single, curried function definition: (@) The following code designates a single, curried function definition:


~~~~~~~~~~~~~~~~~~~~~~~~~ {.scala} ~~~~~~~~~~~~~~~~~~~~~~~~~ {.scala}
def func(x: Int) def func(x: Int)
(y: Int) = x + y (y: Int) = x + y
~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~


With an additional newline character, the same code is interpreted as With an additional newline character, the same code is interpreted as
an abstract function definition and a syntactically illegal statement: an abstract function definition and a syntactically illegal statement:


~~~~~~~~~~~~~~~~~~~~~~~~~ {.scala} ~~~~~~~~~~~~~~~~~~~~~~~~~ {.scala}
def func(x: Int) def func(x: Int)


(y: Int) = x + y (y: Int) = x + y
~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~


(@) The following code designates an attributed definition: (@) The following code designates an attributed definition:


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.scala} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.scala}
@serializable @serializable
protected class Data { ... } protected class Data { ... }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


With an additional newline character, the same code is interpreted as With an additional newline character, the same code is interpreted as
an attribute and a separate statement (which is syntactically an attribute and a separate statement (which is syntactically
illegal). illegal).


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.scala} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.scala}
@serializable @serializable


protected class Data { ... } protected class Data { ... }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




Literals Literals
Expand Down Expand Up @@ -350,9 +350,9 @@ is _pt_. The numeric ranges given by these types are:


(@) Here are some integer literals: (@) Here are some integer literals:


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0 21 0xFFFFFFFF 0777L 0 21 0xFFFFFFFF 0777L
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




### Floating Point Literals ### Floating Point Literals
Expand All @@ -379,15 +379,15 @@ whitespace character between the two tokens.


(@) Here are some floating point literals: (@) Here are some floating point literals:


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0.0 1e30f 3.14159f 1.0e-100 .1 0.0 1e30f 3.14159f 1.0e-100 .1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


(@) The phrase `1.toString`{.scala} parses as three different tokens: (@) The phrase `1.toString`{.scala} parses as three different tokens:
`1`{.scala}, `.`{.scala}, and `toString`{.scala}. On the `1`{.scala}, `.`{.scala}, and `toString`{.scala}. On the
other hand, if a space is inserted after the period, the phrase other hand, if a space is inserted after the period, the phrase
`1. toString`{.scala} parses as the floating point literal `1. toString`{.scala} parses as the floating point literal
`1.`{.scala} followed by the identifier `toString`{.scala}. `1.`{.scala} followed by the identifier `toString`{.scala}.




### Boolean Literals ### Boolean Literals
Expand All @@ -413,9 +413,9 @@ by an [escape sequence](#escape-sequences).
(@) Here are some character literals: (@) Here are some character literals:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'a' '\u0041' '\n' '\t' 'a' '\u0041' '\n' '\t'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Note that `'\u000A'` is _not_ a valid character literal because Note that `'\u000A'` is _not_ a valid character literal because
Unicode conversion is done before literal parsing and the Unicode Unicode conversion is done before literal parsing and the Unicode
Expand All @@ -440,10 +440,10 @@ class `String`{.scala}.


(@) Here are some string literals: (@) Here are some string literals:


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.scala} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.scala}
"Hello,\nWorld!" "Hello,\nWorld!"
"This string contains a \" character." "This string contains a \" character."
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


#### Multi-Line String Literals #### Multi-Line String Literals


Expand All @@ -462,19 +462,19 @@ of the escape sequences [here](#escape-sequences) are interpreted.


(@) Here is a multi-line string literal: (@) Here is a multi-line string literal:


~~~~~~~~~~~~~~~~~~~~~~~~ {.scala} ~~~~~~~~~~~~~~~~~~~~~~~~ {.scala}
"""the present string """the present string
spans three spans three
lines.""" lines."""
~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~


This would produce the string: This would produce the string:


~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~
the present string the present string
spans three spans three
lines. lines.
~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~


The Scala library contains a utility method `stripMargin` The Scala library contains a utility method `stripMargin`
which can be used to strip leading whitespace from multi-line strings. which can be used to strip leading whitespace from multi-line strings.
Expand Down Expand Up @@ -596,11 +596,11 @@ as text.
(@) The following value definition uses an XML literal with two embedded (@) The following value definition uses an XML literal with two embedded
Scala expressions Scala expressions


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.scala} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.scala}
val b = <book> val b = <book>
<title>The Scala Language Specification</title> <title>The Scala Language Specification</title>
<version>{scalaBook.version}</version> <version>{scalaBook.version}</version>
<authors>{scalaBook.authors.mkList("", ", ", "")}</authors> <authors>{scalaBook.authors.mkList("", ", ", "")}</authors>
</book> </book>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


8 changes: 7 additions & 1 deletion resources/style.css
Expand Up @@ -39,9 +39,15 @@ code {


/* examples */ /* examples */
ol[type="1"] { ol[type="1"] {
list-style-type: none;
margin-left: 0;
}

ol[type="1"] li {
margin-top: 1em;
padding: 1em;
background-color: #E5ECF9; background-color: #E5ECF9;
border: 1px dashed black; border: 1px dashed black;
list-style-type: none;
} }


ol[type="1"] li:before { ol[type="1"] li:before {
Expand Down

0 comments on commit 7d50d8f

Please sign in to comment.