Skip to content

Commit fb63880

Browse files
committed
Add dependencies and setup section plus a redirect
1 parent d5aadc4 commit fb63880

14 files changed

+108
-61
lines changed

overviews/macros/quasiquotes.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Redirecting you to the quasiquotes guide...</title>
5+
</head>
6+
<body>
7+
<h2>Redirecting you to the quasiquotes guide...</h2>
8+
<script type="text/javascript">
9+
window.location.href = 'http://docs.scala-lang.org/overviews/quasiquotes/intro.html';
10+
</script>
11+
</body>

overviews/quasiquotes/definition-details.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ title: Definition and import details
55
disqus: true
66

77
partof: quasiquotes
8-
num: 10
9-
outof: 12
8+
num: 11
9+
outof: 13
1010
---
1111
**Denys Shabalin** <span class="label warning" style="float: right;">EXPERIMENTAL</span>
1212

overviews/quasiquotes/expression-details.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ title: Expression details
55
disqus: true
66

77
partof: quasiquotes
8-
num: 7
9-
outof: 12
8+
num: 8
9+
outof: 13
1010
---
1111
**Denys Shabalin** <span class="label warning" style="float: right;">EXPERIMENTAL</span>
1212

overviews/quasiquotes/future.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ title: Future prospects
55
disqus: true
66

77
partof: quasiquotes
8-
num: 12
9-
outof: 12
8+
num: 13
9+
outof: 13
1010
---
1111
**Denys Shabalin** <span class="label warning" style="float: right;">EXPERIMENTAL</span>
1212

overviews/quasiquotes/hygiene.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ title: Hygiene
55
disqus: true
66

77
partof: quasiquotes
8-
num: 4
9-
outof: 12
8+
num: 5
9+
outof: 13
1010
---
1111
**Denys Shabalin, Eugene Burmako** <span class="label warning" style="float: right;">EXPERIMENTAL</span>
1212

overviews/quasiquotes/intro.md

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,11 @@ title: Introduction
55
disqus: true
66

77
partof: quasiquotes
8-
num: 1
9-
outof: 12
8+
num: 2
9+
outof: 13
1010
---
1111
**Denys Shabalin** <span class="label warning" style="float: right;">EXPERIMENTAL</span>
1212

13-
## Before you start {:#before-you-start}
14-
15-
Before you start reading this guide it's recommended to start a Scala REPL with one extra line:
16-
17-
scala> val universe = reflect.runtime.universe; import universe._
18-
19-
REPL is the best place to explore quasiquotes and this guide will use it extensively to demonstrate handling of trees. All of the examples will assume that import.
20-
21-
Additionally some examples that use `ToolBox` API might need a few more lines to get things rolling:
22-
23-
scala> import reflect.runtime.currentMirror
24-
scala> import tools.reflect.ToolBox
25-
scala> val toolbox = currentMirror.mkToolBox()
26-
27-
Another tool you might want to be aware of is new and shiny `showCode` pretty printer (contributed by [@VladimirNik](https://github.com/VladimirNik)):
28-
29-
scala> val C = q"class C"
30-
C: universe.ClassDef =
31-
class C extends scala.AnyRef {
32-
def <init>() = {
33-
super.<init>();
34-
()
35-
}
36-
}
37-
38-
scala> println(showCode(C))
39-
class C
40-
41-
Default pretty printer shows you contents of the tree in imaginary low-level Scala-like notation. `showCode` on the other hand will do its best to reconstruct actual source code equivalent to the given tree in proper Scala syntax.
42-
43-
On the other side of spectrum there is also a `showRaw` pretty printer that shows direct internal organization of the tree:
44-
45-
scala> println(showRaw(q"class C"))
46-
ClassDef(Modifiers(), TypeName("C"), List(), Template(List(Select(Ident(scala), TypeName("AnyRef"))), noSelfType, List(DefDef(Modifiers(), termNames.CONSTRUCTOR, List(), List(List()), TypeTree(), Block(List(pendingSuperCall), Literal(Constant(())))))))
47-
48-
## Basics {:#basics}
49-
5013
Quasiquotes are a neat notation that lets you manipulate Scala syntax trees with ease:
5114

5215
scala> val tree = q"i am { a quasiquote }"

overviews/quasiquotes/lifting.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ title: Lifting
55
disqus: true
66

77
partof: quasiquotes
8-
num: 2
9-
outof: 12
8+
num: 3
9+
outof: 13
1010
---
1111
**Denys Shabalin** <span class="label warning" style="float: right;">EXPERIMENTAL</span>
1212

overviews/quasiquotes/pattern-details.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ title: Pattern details
55
disqus: true
66

77
partof: quasiquotes
8-
num: 9
9-
outof: 12
8+
num: 10
9+
outof: 13
1010
---
1111
**Denys Shabalin** <span class="label warning" style="float: right;">EXPERIMENTAL</span>
1212

overviews/quasiquotes/setup.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
layout: overview-large
3+
title: Dependencies and setup
4+
5+
disqus: true
6+
7+
partof: quasiquotes
8+
num: 1
9+
outof: 13
10+
---
11+
12+
## Scala 2.11 {:#211}
13+
14+
In Scala 2.11, quasiquotes are shipped in the official Scala distribution as part of `scala-reflect.jar`, so you don't need to do anything special to use them - just don't forget to add a dependency on `scala-reflect`.
15+
16+
All examples and code snippets in this guide are run under in 2.11 REPL with one extra line:
17+
18+
scala> val universe = reflect.runtime.universe; import universe._
19+
20+
A wildcard import from a universe (be it a runtime reflection universe like here or a compile-time universe provided in macros) is all that's needed to use quasiquotes. All of the examples will assume that import.
21+
22+
Additionally some examples that use `ToolBox` API will need a few more lines to get things rolling:
23+
24+
scala> import reflect.runtime.currentMirror
25+
scala> import tools.reflect.ToolBox
26+
scala> val toolbox = currentMirror.mkToolBox()
27+
28+
Another tool you might want to be aware of is new and shiny `showCode` pretty printer (contributed by [@VladimirNik](https://github.com/VladimirNik)):
29+
30+
scala> val C = q"class C"
31+
C: universe.ClassDef =
32+
class C extends scala.AnyRef {
33+
def <init>() = {
34+
super.<init>();
35+
()
36+
}
37+
}
38+
39+
scala> println(showCode(C))
40+
class C
41+
42+
Default pretty printer shows you contents of the tree in imaginary low-level Scala-like notation. `showCode` on the other hand will do its best to reconstruct actual source code equivalent to the given tree in proper Scala syntax.
43+
44+
On the other side of spectrum there is also a `showRaw` pretty printer that shows direct internal organization of the tree:
45+
46+
scala> println(showRaw(q"class C"))
47+
ClassDef(Modifiers(), TypeName("C"), List(), Template(List(Select(Ident(scala), TypeName("AnyRef"))), noSelfType, List(DefDef(Modifiers(), termNames.CONSTRUCTOR, List(), List(List()), TypeTree(), Block(List(pendingSuperCall), Literal(Constant(())))))))
48+
49+
## Scala 2.10 {:#210}
50+
51+
In Scala 2.10, quasiquotes are only available via the [macro paradise compiler plugin](http://docs.scala-lang.org/overviews/macros/paradise.html).
52+
53+
In short, using quasiquotes in 2.10 is as simple as adding a single `addCompilerPlugin` line to your SBT build for the macro paradise plugin that enables quasiquotes and an additional `libraryDependencies` line for the supporting library that is necessary for quasiquotes to function in Scala 2.10. A full example is provided at [https://github.com/scalamacros/sbt-example-paradise](https://github.com/scalamacros/sbt-example-paradise).
54+
55+
New `showCode` pretty printer is not available under 2.10.
56+
57+
## SBT cross-compile {:#sbt}
58+
59+
Here's a neat SBT snippet taken from [Spire](https://github.com/non/spire) that allows you to use quasiquotes and cross-compile against both Scala 2.10 and 2.11:
60+
61+
libraryDependencies := {
62+
CrossVersion.partialVersion(scalaVersion.value) match {
63+
// if scala 2.11+ is used, quasiquotes are merged into scala-reflect
64+
case Some((2, scalaMajor)) if scalaMajor >= 11 =>
65+
libraryDependencies.value
66+
// in Scala 2.10, quasiquotes are provided by macro paradise
67+
case Some((2, 10)) =>
68+
libraryDependencies.value ++ Seq(
69+
compilerPlugin("org.scalamacros" % "paradise" % "2.0.0" cross CrossVersion.full),
70+
"org.scalamacros" %% "quasiquotes" % "2.0.0" cross CrossVersion.binary)
71+
}
72+
}
73+

overviews/quasiquotes/syntax-summary.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ title: Syntax summary
55
disqus: true
66

77
partof: quasiquotes
8-
num: 6
9-
outof: 12
8+
num: 7
9+
outof: 13
1010
---
1111
**Denys Shabalin** <span class="label warning" style="float: right;">EXPERIMENTAL</span>
1212

overviews/quasiquotes/terminology.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ title: Terminology summary
55
disqus: true
66

77
partof: quasiquotes
8-
num: 11
9-
outof: 12
8+
num: 12
9+
outof: 13
1010
---
1111
<span class="label warning" style="float: right;">EXPERIMENTAL</span>
1212

overviews/quasiquotes/type-details.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ title: Type details
55
disqus: true
66

77
partof: quasiquotes
8-
num: 8
9-
outof: 12
8+
num: 9
9+
outof: 13
1010
---
1111
**Denys Shabalin** <span class="label warning" style="float: right;">EXPERIMENTAL</span>
1212

overviews/quasiquotes/unlifting.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ title: Unlifting
55
disqus: true
66

77
partof: quasiquotes
8-
num: 3
9-
outof: 12
8+
num: 4
9+
outof: 13
1010
---
1111
**Denys Shabalin** <span class="label warning" style="float: right;">EXPERIMENTAL</span>
1212

overviews/quasiquotes/usecases.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ title: Use cases
55
disqus: true
66

77
partof: quasiquotes
8-
num: 5
9-
outof: 12
8+
num: 6
9+
outof: 13
1010
---
1111
**Denys Shabalin** <span class="label warning" style="float: right;">EXPERIMENTAL</span>
1212

0 commit comments

Comments
 (0)