Enhanced C#
Loyc library documentation
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
Properties | Public Member Functions | List of all members
Loyc.Syntax.Impl.IPrinterHelper< out Self > Interface Template Reference

Source file:
Inheritance diagram for Loyc.Syntax.Impl.IPrinterHelper< out Self >:
Loyc.Syntax.Impl.ILNodePrinterHelper< out Self > Loyc.Syntax.Impl.ILNodePrinterHelperWithRevokableNewlines< Checkpoint, out Self > Loyc.Syntax.Impl.ILNodePrinterHelperWithRevokableNewlines< Checkpoint > Loyc.Syntax.Impl.LNodePrinterHelper Loyc.Syntax.Impl.PrinterState

Properties

bool IsAtStartOfLine [get]
 Returns true iff nothing has been written since the last call to Newline or NewlineIsRequiredHere. More...
 
char LastCharWritten [get]
 Gets the character most recently written to the stream, or '' if no characters have been written. More...
 

Public Member Functions

Self Write (char c)
 Appends a character to the output stream or StringBuilder. More...
 
Self Write (string s)
 Appends a string to the output stream or StringBuilder. More...
 
Self Write (UString s)
 Appends a string to the output stream or StringBuilder. More...
 
Self Space ()
 Writes a space character unless the last character written was a space. More...
 
Self Newline (bool deferIndent=false)
 Appends a newline, with indentation afterward according to the current indentation level. More...
 
Self FlushIndent ()
 Writes the pending indent, if applicable. This allows you to call Indent or Dedent afterward while making sure the indentation on the current line is unaffected. More...
 
Self NewlineIsRequiredHere ()
 Requests that a newline be written at this location. If this method is called multiple times at the same location, or if Newline(int) is called immediately afterward, only a single newline is written. More...
 
Self Indent (PrinterIndentHint?hint=null)
 Informs the helper that the printer is starting to write the specified node. The printer must call EndNode when it is done. This information may be used to record range information (to understand why this is useful, please read about LNodeRangeMapper) More...
 
Self Dedent (PrinterIndentHint?hint=null)
 Decreases the current indent level. More...
 

Member Function Documentation

Self Loyc.Syntax.Impl.IPrinterHelper< out Self >.Dedent ( PrinterIndentHint hint = null)

Decreases the current indent level.

Parameters
modeIf the hint is not null, the writer may be able to check that it was the same hint that was passed to Indent and throw an exception if not.
Exceptions
ArgumentExceptionHint provided doesn't match Indent hint

Implemented in Loyc.Syntax.Impl.LNodePrinterHelper.

Self Loyc.Syntax.Impl.IPrinterHelper< out Self >.FlushIndent ( )

Writes the pending indent, if applicable. This allows you to call Indent or Dedent afterward while making sure the indentation on the current line is unaffected.

This method has no effect if indentation has already been written, e.g. right after calling Newline(false) or Write(char). If a newline is pending as a result of a call to NewlineIsRequiredHere, it is implementation- defined whether that additional newline (and its indent) is written. LNodePrinterHelper write a newline when this method is called, but it sets a special internal flag so that a call sequence such as

NewlineIsRequiredHere().FlushIndent().NewlineIsRequiredHere().Newline()

writes only a single newline.

Implemented in Loyc.Syntax.Impl.LNodePrinterHelper.

Self Loyc.Syntax.Impl.IPrinterHelper< out Self >.Indent ( PrinterIndentHint hint = null)

Informs the helper that the printer is starting to write the specified node. The printer must call EndNode when it is done. This information may be used to record range information (to understand why this is useful, please read about LNodeRangeMapper)

Parameters
nodeThe node that begins here.

Increases the current indent level.

Parameters
hintInformation associated with the indent, typically a member of PrinterIndentHint that influences how indentation is performed. You can use null for standard indentation.

This interface does not define what string is used for an indent; typically it's a tab or 2 to 4 spaces.

The standard kind of indentation expresses block boundaries, e.g. statements are indented between curly braces (in languages in the C family).

When printing labels (targets of goto statements), a typical style is that labels are printed with less indentation than a normal statement. The PrinterIndentHint.Label hint indicates that a label is about to be printed.

Another interesting case is a mid-expression break. Consider a statement x = 2 * (1 + Method(<tt>newline parameter1, parameter2)) with a newline before parameter1. It is the printer's responsibility to notice the trivia and call Newline, but in this case the newline should include some extra indentation to indicate that a new statement does not begin here. The PrinterIndentHint.Subexpression and PrinterIndentHint.Brackets hints request this extra indentation; both of these flags indicate a subexpression but the latter is meant to imply a kind of subexpression that begins with round or square brackets () [].

LNodePrinterHelper has an indent stack which it uses to make a smart decision about indentation. When printing the example above, if your code calls Indent(Symbol) with an appropriate hint as it begins each node, the helper will know that four subexpressions have begun but not ended at the time Newline is called:

  • 2 * (1 + Method(<tt>newline parameter1, parameter2))
  • (1 + Method(<tt>newline parameter1, parameter2))
  • Method(<tt>newline parameter1, parameter2))
  • <tt>newline parameter1

LNodePrinterHelper counts the number of "indents" of type PrinterIndentHint.Brackets and then prints indentation based on properties that were given to its constructor (LNodePrinterHelper.BracketIndentString and LNodePrinterHelper.MaxBracketIndents). It treats the PrinterIndentHint.Subexpression hint differently; it ignores the number of Subexpressions on the indent stack and only pays attention to whether there are zero of them, or more than zero. Any number of Subexpression indents larger than zero causes a single bracket indent to be printed. However, if there are also bracket indents on the stack, then the Subexpression indents have no effect.

Implemented in Loyc.Syntax.Impl.LNodePrinterHelper.

Self Loyc.Syntax.Impl.IPrinterHelper< out Self >.Newline ( bool  deferIndent = false)

Appends a newline, with indentation afterward according to the current indentation level.

Parameters
deferIndentRequests that the indentation after the newline not be printed until Write or FlushIndent is called. This option is provided because you may know that you want to print a newline before deciding what indent is needed.

Implemented in Loyc.Syntax.Impl.LNodePrinterHelper.

Self Loyc.Syntax.Impl.IPrinterHelper< out Self >.NewlineIsRequiredHere ( )

Requests that a newline be written at this location. If this method is called multiple times at the same location, or if Newline(int) is called immediately afterward, only a single newline is written.

This method does not officially write a newline; if you call this method followed by Dedent, for example, the newline that is eventually written will be followed by a lower amount of indentation.

Implemented in Loyc.Syntax.Impl.LNodePrinterHelper.

Self Loyc.Syntax.Impl.IPrinterHelper< out Self >.Space ( )

Writes a space character unless the last character written was a space.

Implemented in Loyc.Syntax.Impl.LNodePrinterHelper.

Self Loyc.Syntax.Impl.IPrinterHelper< out Self >.Write ( char  c)

Appends a character to the output stream or StringBuilder.

Do not call Write('
')
; call Newline() instead.

Implemented in Loyc.Syntax.Impl.LNodePrinterHelper.

Self Loyc.Syntax.Impl.IPrinterHelper< out Self >.Write ( string  s)

Appends a string to the output stream or StringBuilder.

The string should not include newlines (if it might, call LNodePrinterHelperExt.WriteSmartly instead).

Implemented in Loyc.Syntax.Impl.LNodePrinterHelper.

Self Loyc.Syntax.Impl.IPrinterHelper< out Self >.Write ( UString  s)

Appends a string to the output stream or StringBuilder.

The string should not include newlines (if it might, call LNodePrinterHelperExt.WriteSmartly instead).

Implemented in Loyc.Syntax.Impl.LNodePrinterHelper.

Property Documentation

bool Loyc.Syntax.Impl.IPrinterHelper< out Self >.IsAtStartOfLine
get

Returns true iff nothing has been written since the last call to Newline or NewlineIsRequiredHere.

char Loyc.Syntax.Impl.IPrinterHelper< out Self >.LastCharWritten
get

Gets the character most recently written to the stream, or '' if no characters have been written.