Quasiquotes
Syntax summaryThis doc page is specific to features shipped in Scala 2, which have either been removed in Scala 3 or replaced by an alternative. Unless otherwise stated, all the code examples in this page assume you are using Scala 2.
Denys Shabalin EXPERIMENTAL
Expressions  Quasiquote Type Emptyq""
EmptyTree Literal q"$value"
Literal Identifier q"$tname"
or q"name"
Ident Selection q"$expr.$tname"
Select Super Selection q"$tpname.super[$tpname].$tname"
Select This q"$tpname.this"
This Application q"$expr(...$exprss)"
Apply Type Application q"$expr[..$tpts]"
TypeApply Assign q"$expr = $expr"
Assign, AssignOrNamedArg Update q"$expr(..$exprs) = $expr"
Tree Return q"return $expr"
Return Throw q"throw $expr"
Throw Ascription q"$expr: $tpt"
Typed Annotated q"$expr: @$annot"
Annotated Tuple q"(..$exprs)"
Tree Block q"{ ..$stats }"
Block If q"if ($expr) $expr else $expr"
If Pattern Match q"$expr match { case ..$cases }"
Match Try q"try $expr catch { case ..$cases } finally $expr"
Try Function q"(..$params) => $expr"
Function Partial Function q"{ case ..$cases }"
Match While Loop q"while ($expr) $expr"
LabelDef Do-While Loop q"do $expr while ($expr)"
LabelDef For Loop q"for (..$enums) $expr"
Tree For-Yield Loop q"for (..$enums) yield $expr"
Tree New q"new { ..$earlydefns } with ..$parents { $self => ..$stats }"
Tree XML Literal Not natively supported Tree Types Patterns Definitions  Quasiquote Type Val q"$mods val $tname: $tpt = $expr"
or q"$mods val $pat = $expr"
ValDef Var q"$mods var $tname: $tpt = $expr"
or q"$mods var $pat = $expr"
ValDef Val Pattern q"$mods val $pat: $tpt = $expr"
Tree Var Pattern q"$mods var $pat: $tpt = $expr"
Tree Method q"$mods def $tname[..$tparams](...$paramss): $tpt = $expr"
DefDef Secondary Constructor q"$mods def this(...$paramss) = this(..$argss)"
DefDef Type q"$mods type $tpname[..$tparams] = $tpt"
TypeDef Class q"$mods class $tpname[..$tparams] $ctorMods(...$paramss) extends { ..$earlydefns } with ..$parents { $self => ..$stats }"
ClassDef Trait q"$mods trait $tpname[..$tparams] extends { ..$earlydefns } with ..$parents { $self => ..$stats }"
TraitDef Object q"$mods object $tname extends { ..$earlydefns } with ..$parents { $self => ..$body }"
ModuleDef Package q"package $ref { ..$topstats }"
PackageDef Package Object q"package object $tname extends { ..$earlydefns } with ..$parents { $self => ..$stats }"
PackageDef Auxiliary Abbreviations
Prefixes of unquotees imply the following:
name: Name
, tname: TermName
, tpname: TypeName
value: T
where T
is value type that corresponds to given literal (e.g. Int
, Char
, Float
etc)expr: Tree
an expression treetpt: Tree
a type treepat: Tree
a pattern treedefn: Tree
a definition treeearlydefn: Tree
an early definion tree (val or type definition)self: Tree
a self definition tree (i.e. val definition)stat: Tree
a statement tree (definition, expression or an import)topstat: Tree
a top-level statement tree (class, trait, package, package object or import)enum: Tree
a for loop enumeratorparam: Tree
a value parameter tree (i.e. val definition)tparam: Tree
a type paremeter tree (i.e. type definition)parent: Tree
a template parentsel: Tree
an import selector treeWhenever a name has suffix s
it means that it is a List
of something. ss
means List of Lists. So for example exprss
means a List
of List
s of expressions.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4