Skip to content

Commit abd0895

Browse files
committed
Fix #6: automatic section numbering.
Add chapter number to YAML, which is replace in numbering.css. Use CSS counters for chapters, sections, subsections | examples. Examples are detected by looking at the H3 element's id, which redcarpet derives from the heading's title. It must start with "Example:", and the whole title is suppressed by a little javascript, so we can make Examples look like in the pdf. For example, `### Example:` becomes `Example 3.2.10`, if it's the 10th example in Section 3.2.
1 parent 5997e32 commit abd0895

17 files changed

+468
-330
lines changed

03-lexical-syntax.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Lexical Syntax
33
layout: default
4-
tag: lexical
4+
chapter: 1
55
---
66

77
# Lexical Syntax
@@ -100,15 +100,15 @@ _ : = => <- <: <% >: # @
100100
The Unicode operators `\u21D2 $\Rightarrow$` and `\u2190 $\leftarrow$`, which have the ASCII
101101
equivalents `=>` and `<-`, are also reserved.
102102

103-
###### Example: here are some identifiers:
103+
### Example:
104104

105105
```
106106
x Object maxIndex p2p empty_?
107107
+ `yield` αρετη _y dot_product_*
108108
__system _MAX_LEN_
109109
```
110110

111-
###### Example: backquote-enclosed strings
111+
### Example:
112112
When one needs to access Java identifiers that are reserved words in Scala, use backquote-enclosed strings.
113113
For instance, the statement `Thread.yield()` is illegal, since
114114
`yield` is a reserved word in Scala. However, here's a
@@ -207,7 +207,7 @@ A single new line token is accepted
207207
- in front of a [parameter clause](06-basic-declarations-and-definitions.html#function-declarations-and-definitions), and
208208
- after an [annotation](13-user-defined-annotations.html#user-defined-annotations).
209209

210-
###### Example: four well-formed statements, each on two lines
210+
### Example:
211211

212212
The newline tokens between the two lines are not
213213
treated as statement separators.
@@ -226,7 +226,7 @@ type
226226
IntList = List[Int]
227227
```
228228

229-
###### Example: an anonymous class
229+
### Example:
230230

231231
```
232232
new Iterator[Int]
@@ -250,7 +250,7 @@ new Iterator[Int]
250250
}
251251
```
252252

253-
###### Example: a single expression
253+
### Example:
254254

255255
```
256256
x < 0 ||
@@ -266,7 +266,7 @@ two expressions:
266266
x > 10
267267
```
268268

269-
###### Example: a single, curried function definition
269+
### Example:
270270

271271
```
272272
def func(x: Int)
@@ -282,7 +282,7 @@ def func(x: Int)
282282
(y: Int) = x + y
283283
```
284284

285-
###### Example: an attributed definition
285+
### Example:
286286

287287
```
288288
@serializable
@@ -356,7 +356,7 @@ is _pt_. The numeric ranges given by these types are:
356356
|`Char` | $0$ to $2^{16}-1$ |
357357

358358

359-
###### Example: some integer literals
359+
### Example:
360360

361361
```
362362
0 21 0xFFFFFFFF -42L
@@ -385,18 +385,18 @@ If a floating point literal in a program is followed by a token
385385
starting with a letter, there must be at least one intervening
386386
whitespace character between the two tokens.
387387

388-
###### Example: some floating point literals
388+
### Example:
389389

390390
```
391391
0.0 1e30f 3.14159f 1.0e-100 .1
392392
```
393393

394-
###### Example: tokenizing
394+
### Example:
395395

396396
The phrase `1.toString` parses as three different tokens:
397397
the integer literal `1`, a `.`, and the identifier `toString`.
398398

399-
###### Example: invalid floating point literal
399+
### Example:
400400

401401
`1.` is not a valid floating point literal because the mandatory digit after the `.` is missing.
402402

@@ -420,7 +420,7 @@ A character literal is a single character enclosed in quotes.
420420
The character is either a printable unicode character or is described
421421
by an [escape sequence](#escape-sequences).
422422

423-
###### Example: some character literals
423+
### Example:
424424

425425
```
426426
'a' '\u0041' '\n' '\t'
@@ -447,7 +447,7 @@ contains a double quote character, it must be escaped,
447447
i.e. `"\""`. The value of a string literal is an instance of
448448
class `String`.
449449

450-
###### Example: some string literals
450+
### Example:
451451

452452
```
453453
"Hello,\nWorld!"
@@ -469,7 +469,7 @@ must not necessarily be printable; newlines or other
469469
control characters are also permitted. Unicode escapes work as everywhere else, but none
470470
of the escape sequences [here](#escape-sequences) are interpreted.
471471

472-
###### Example: a multi-line string literal:
472+
### Example:
473473

474474
```
475475
"""the present string
@@ -600,7 +600,7 @@ The scanner switches from XML mode to Scala mode if either
600600
Note that no Scala tokens are constructed in XML mode, and that comments are interpreted
601601
as text.
602602

603-
###### Example: XML literals
603+
### Example:
604604

605605
The following value definition uses an XML literal with two embedded
606606
Scala expressions:

04-identifiers-names-and-scopes.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: Identifiers, Names and Scopes
33
layout: default
4+
chapter: 2
45
---
56

67
# Identifiers, Names and Scopes
@@ -70,7 +71,7 @@ namespace as the identifier. It is an error if $T$ is not a [value type](05-type
7071
The type of $e.x$ is the member type of the referenced entity in $T$.
7172

7273

73-
###### Example: bindings
74+
### Example:
7475

7576
Assume the following two definitions of a objects named `X` in packages `P` and `Q`.
7677

05-types.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: Types
33
layout: default
4+
chapter: 3
45
---
56

67
# Types
@@ -148,7 +149,7 @@ A qualified type designator has the form `p.t` where `p` is
148149
a [path](#paths) and _t_ is a type name. Such a type designator is
149150
equivalent to the type projection `p.type#t`.
150151

151-
###### Example: fully qualified type designators
152+
### Example:
152153

153154
Some type designators and their expansions are listed below. We assume
154155
a local type parameter $t$, a value `maintable`
@@ -181,7 +182,7 @@ well-formed if each actual type parameter
181182
_conforms to its bounds_, i.e. $\sigma L_i <: T_i <: \sigma U_i$ where $\sigma$ is the
182183
substitution $[ a_1 := T_1 , \ldots , a_n := T_n ]$.
183184

184-
###### Example: parameterized types
185+
### Example:
185186
Given the partial type definitions:
186187

187188
```
@@ -205,7 +206,7 @@ F[List, Int]
205206
G[S, String]
206207
```
207208

208-
###### Example: ill-formed types
209+
### Example:
209210

210211
Given the [above type definitions](example-parameterized-types),
211212
the following types are ill-formed:
@@ -261,7 +262,7 @@ An annotated type $T$ `$a_1 , \ldots , a_n$`
261262
attaches [annotations](13-user-defined-annotations.html#user-defined-annotations)
262263
$a_1 , \ldots , a_n$ to the type $T$.
263264

264-
###### Example: annotated type
265+
### Example:
265266

266267
The following type adds the `@suspendable` annotation to the type `String`:
267268

@@ -309,7 +310,7 @@ A compound type may also consist of just a refinement
309310
`{ $R$ }` with no preceding component types. Such a type is
310311
equivalent to `AnyRef{ R }`.
311312

312-
###### Example: structural refinement in a method's parameter type
313+
### Example:
313314

314315
The following example shows how to declare and use a method which
315316
a parameter type that contains a refinement with structural declarations.
@@ -509,7 +510,7 @@ or [tuple types](#tuple-types).
509510
Their expansion is then the expansion in the equivalent parameterized
510511
type.
511512

512-
###### Example: existential types
513+
### Example:
513514

514515
Assume the class definitions
515516

@@ -533,15 +534,15 @@ An alternative formulation of the first type above using wildcard syntax is:
533534
Ref[_ <: java.lang.Number]
534535
```
535536

536-
###### Example: abbreviating an existential type with the underscore
537+
### Example:
537538

538539
The type `List[List[_]]` is equivalent to the existential type
539540

540541
```
541542
List[List[t] forSome { type t }] .
542543
```
543544

544-
###### Example: existential type equivalence
545+
### Example:
545546

546547
Assume a covariant type
547548

@@ -670,7 +671,7 @@ same name, we model
670671
671672
An overloaded type consisting of type alternatives $T_1 \commadots T_n (n \geq 2)$ is denoted internally $T_1 \overload \ldots \overload T_n$.
672673
673-
###### Example: The definitions
674+
### Example:
674675
```
675676
def println: Unit
676677
def println(s: String): Unit = $\ldots$
@@ -688,7 +689,7 @@ println: => Unit $\overload$
688689
[A] (A) (A => String) Unit
689690
```
690691
691-
###### Example: The definitions
692+
### Example:
692693
```
693694
def f(x: T): T = $\ldots$
694695
val f = 0

06-basic-declarations-and-definitions.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: Basic Declarations and Definitions
33
layout: default
4+
chapter: 4
45
---
56

67
# Basic Declarations and Definitions
@@ -573,7 +574,7 @@ abstract class Sequence[+A] {
573574
}
574575
```
575576

576-
###### Example: Here is a case where a contravariant type parameter is useful.
577+
### Example:
577578

578579
```
579580
abstract class OutputChannel[-A] {

07-classes-and-objects.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: Classes and Objects
33
layout: default
4+
chapter: 5
45
---
56

67
# Classes and Objects
@@ -377,7 +378,7 @@ it is possible to add new defaults (if the corresponding parameter in the
377378
superclass does not have a default) or to override the defaults of the
378379
superclass (otherwise).
379380

380-
###### Example: compound types
381+
### Example:
381382

382383
Consider the definitions:
383384

@@ -759,7 +760,7 @@ which when applied to parameters conforming to types $\mathit{ps}$
759760
initializes instances of type `$c$[$\mathit{tps}\,$]` by evaluating the template
760761
$t$.
761762
762-
###### Example: private constructor
763+
### Example:
763764
The following example illustrates `val` and `var` parameters of a class `C`:
764765
765766
```
@@ -1009,7 +1010,7 @@ it is not statically known at the time the trait is defined.
10091010
If $D$ is not a trait, then its actual supertype is simply its
10101011
least proper supertype (which is statically known).
10111012
1012-
###### Example: `Comparable`
1013+
### Example:
10131014
The following trait defines the property
10141015
of being comparable to objects of some type. It contains an abstract
10151016
method `<` and default implementations of the other

08-expressions.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: Expressions
33
layout: default
4+
chapter: 6
45
---
56

67
# Expressions
@@ -209,7 +210,7 @@ to the type or method of $x$ in the parent trait of $C$ whose simple
209210
name is $T$. That member must be uniquely defined. If it is a method,
210211
it must be concrete.
211212

212-
###### Example: `super`
213+
### Example:
213214
Consider the following class definitions
214215

215216
```
@@ -824,7 +825,7 @@ Here are some assignment expressions and their equivalent expansions.
824825
`x.f(i, j) = e` x.f.update(i, j, e)
825826
-------------------------- ---------------------
826827

827-
###### Example: imperative matrix multiplication
828+
### Example:
828829

829830
Here is the usual imperative code for matrix multiplication.
830831

09-implicit-parameters-and-views.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: Implicit Parameters and Views
33
layout: default
4+
chapter: 7
45
---
56

67
# Implicit Parameters and Views
@@ -18,7 +19,7 @@ and can be used as implicit conversions called [views](#views).
1819
The `implicit` modifier is illegal for all
1920
type members, as well as for [top-level objects](11-top-level-definitions.html#packagings).
2021

21-
###### Example: `Monoid`
22+
### Example:
2223
The following code defines an abstract class of monoids and
2324
two concrete implementations, `StringMonoid` and
2425
`IntMonoid`. The two implementations are marked implicit.
@@ -289,7 +290,7 @@ As for implicit parameters, overloading resolution is applied
289290
if there are several possible candidates (of either the call-by-value
290291
or the call-by-name category).
291292

292-
###### Example: `Ordered`
293+
### Example:
293294
Class `scala.Ordered[A]` contains a method
294295

295296
```

10-pattern-matching.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: Pattern Matching
33
layout: default
4+
chapter: 8
45
---
56

67
# Pattern Matching
@@ -596,7 +597,7 @@ the compilation of pattern matching can emit warnings which diagnose
596597
that a given set of patterns is not exhaustive, i.e. that there is a
597598
possibility of a `MatchError` being raised at run-time.
598599

599-
###### Example: `eval`
600+
### Example:
600601

601602
Consider the following definitions of arithmetic terms:
602603

11-top-level-definitions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: Top-Level Definitions
33
layout: default
4+
chapter: 9
45
---
56

67
# Top-Level Definitions

12-xml-expressions-and-patterns.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: XML Expressions and Patterns
33
layout: default
4+
chapter: 10
45
---
56

67
# XML Expressions and Patterns

13-user-defined-annotations.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: User-Defined Annotations
33
layout: default
4+
chapter: 11
45
---
56

67
# User-Defined Annotations

0 commit comments

Comments
 (0)