PlainPrinter

class PlainPrinter(_ctx: Context) extends Printer
class Printer
class Object
trait Matchable
class Any

Value members

Concrete methods

def Str(str: String, lineRange: LineRange): Str
def annotsText(sym: Symbol): Text
def dclText(sym: Symbol): Text
def dclsText(syms: List[Symbol], sep: String): Text
def homogenize(tp: Type): Type

String representation of symbol's kind.

String representation of symbol's kind.

def locatedText(sym: Symbol): Text
def nameString(name: Name): String
def toText(name: Name): Text
def toText(tp: Type): Text
def toText(sym: Symbol): Text
def toText(denot: Denotation): Text
def toText(const: Constant): Text
def toText(annot: Annotation): Text
def toText(sc: Scope): Text
def toText[T >: Untyped](tree: Tree[T]): Text
def toText(result: SearchResult): Text
def toText(importInfo: ImportInfo): Text

The string representation of this type used as a prefix, including separator

The string representation of this type used as a prefix, including separator

The string representation of this type used as a prefix

The string representation of this type used as a prefix

Inherited methods

def atPrec(prec: Precedence)(op: => Text): Text

Generate text using op, assuming a given precedence level prec.

Generate text using op, assuming a given precedence level prec.

atPrec vs changePrec

This is to be used when changing precedence inside some sort of parentheses: for instance, to print T[A]usetoText(T) ~ '[' ~ atPrec(GlobalPrec) { toText(A) } ~ ']'`.

If the presence of the parentheses depends on precedence, inserting them manually is most certainly a bug. Use changePrec instead to generate them exactly when needed.

Inherited from
Printer
def changePrec(prec: Precedence)(op: => Text): Text

Generate text using op, assuming a given precedence level prec. If new level prec is lower than previous level, put text in parentheses.

Generate text using op, assuming a given precedence level prec. If new level prec is lower than previous level, put text in parentheses.

atPrec vs changePrec

To pretty-print A op B, you need something like changePrec(parsing.precedence(op, isType)) { toText(a) ~ op ~ toText(b) } // BUGGY that will insert parentheses around A op B if, for instance, the preceding operator has higher precedence.

But that does not handle infix operators with left- or right- associativity.

If op and op' have the same precedence and associativity, A op B op' C parses as (A op B) op' C if op and op' are left-associative, and as A op (B op' C) if they're right-associative, so we need respectively

val isType = ??? // is this a term or type operator?
val prec = parsing.precedence(op, isType)
// either:
changePrec(prec) { toText(a) ~ op ~ atPrec(prec + 1) { toText(b) } } // for left-associative op and op'
// or:
changePrec(prec) { atPrec(prec + 1) { toText(a) } ~ op ~ toText(b) } // for right-associative op and op'
Inherited from
Printer

The current precedence level. When pretty-printing arguments of operator op, currentPrecedence must equal op's precedence level, so that pretty-printing expressions using lower-precedence operators can insert parentheses automatically by calling changePrec.

The current precedence level. When pretty-printing arguments of operator op, currentPrecedence must equal op's precedence level, so that pretty-printing expressions using lower-precedence operators can insert parentheses automatically by calling changePrec.

Inherited from
Printer
def toText(elems: Iterable[Showable], sep: String): Text

Render elements alternating with sep string

Render elements alternating with sep string

Inherited from
Printer

Render elements within lowest precedence

Render elements within lowest precedence

Inherited from
Printer

Render element within lowest precedence

Render element within lowest precedence

Inherited from
Printer
def toTextLocal(elems: Iterable[Showable], sep: String): Text

Render elements within highest precedence

Render elements within highest precedence

Inherited from
Printer

Render element within highest precedence

Render element within highest precedence

Inherited from
Printer

Concrete fields