Enhanced C#
Loyc library documentation
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
Nested classes | Public Member Functions | List of all members
Loyc.Syntax.Impl.PrinterState Class Reference

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

Nested classes

struct  Checkpoint
 

Public Member Functions

 PrinterState (StringBuilder s, string indent="\t", string newline="\n")
 
- Public Member Functions inherited from Loyc.Syntax.Impl.LNodePrinterHelper
 LNodePrinterHelper (StringBuilder s, Action< ILNode, IndexRange, int >?saveRange=null, bool allowNewlineRevocation=true, string indent="\t", string newline="\n", string labelIndent=" ", string bracketIndent=" ", int maxBracketIndents=4)
 
virtual void Reset ()
 Calls Dispose() and resets the state of this object, like calling the constructor. Does not clear the StringBuilder. More...
 
virtual LNodePrinterHelper Write (char c)
 Appends a character to the output stream or StringBuilder.Do not call Write('
')
; call Newline() instead.
 
virtual LNodePrinterHelper 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).
 
virtual LNodePrinterHelper 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).
 
LNodePrinterHelper Space ()
 Writes a space character unless the last character written was a space.
 
StringBuilder Append (string s)
 
StringBuilder Append (UString s)
 
LNodePrinterHelperLocation Newline (int changeIndentLevel)
 Older version of Newline method, which returns a checkpoint instead of this. More...
 
virtual LNodePrinterHelper 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.

 
LNodePrinterHelper 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...
 
virtual LNodePrinterHelper 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.
 
virtual LNodePrinterHelper Indent (PrinterIndentHint?modeHint=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.
 
virtual LNodePrinterHelper Dedent (PrinterIndentHint?modeHint=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

 
virtual LNodePrinterHelper BeginNode (ILNode node)
 
virtual LNodePrinterHelper EndNode ()
 Informs the helper that the printer is done writing the most recently started node. The helper may save the range of the node, e.g. by calling ILNodePrinterOptions.SaveRange.
Parameters
abortIndicates that the range of this node should not be saved.

 
LNodePrinterHelper BeginNode (ILNode node, PrinterIndentHint indentHint)
 Combines the BeginNode and Indent operations.
Parameters
indentHintTypically a member of PrinterIndentHint that influences how indentation is performed

 
LNodePrinterHelper EndNode (PrinterIndentHint indentHint)
 Combines the EndNode and Dedent operations.
 
virtual LNodePrinterHelperLocation GetCheckpoint ()
 Gets a value that can be passed later to RevokeNewlinesSince(Checkpoint).
 
virtual LNodePrinterHelperLocation NewlineAfterCheckpoint ()
 Appends a newline, returning a checkpoint from with indentation afterward according to the current indentation level.
 
int RevokeOrCommitNewlines (LNodePrinterHelperLocation cp, int maxLineWidth)
 
LNodePrinterHelper CommitNewlines ()
 Commits all uncommitted newlines permanently.Also causes ranges after the uncommitted newlines to be saved.
 
int RevokeNewlinesSince (LNodePrinterHelperLocation cp)
 
void Dispose ()
 Commits uncommitted newlines and node ranges. Throws if a SaveRange method was provided but EndNode has not been called the correct number of times. More...
 
- Public Member Functions inherited from Loyc.Syntax.Impl.ILNodePrinterHelperWithRevokableNewlines< Checkpoint, out Self >
int RevokeNewlinesSince (Checkpoint cp)
 Deletes uncommitted newlines that were written after the specified checkpoint. More...
 
int RevokeOrCommitNewlines (Checkpoint cp, int maxLineWidth)
 Revokes or commits newlines added since the specified checkpoint. Recent newlines are revoked if the combined line length after revokation does not exceed maxLineWidth, otherwise ALL newlines are committed permanently. More...
 

Additional Inherited Members

- Public fields inherited from Loyc.Syntax.Impl.LNodePrinterHelper
int LineStartIndex => _lineStartIndex
 
int IndexInCurrentLine => _s.Length - _lineStartIndex
 
int IndexInCurrentLineAfterIndent => _s.Length - _lineStartAfterIndent
 
bool AtStartOfLine => IsAtStartOfLine
 
bool IsAtStartOfLine => _s.Length <= _lineStartAfterIndent | (_pendingAction & PendingAction.Newline) != 0
 
char LastCharWritten => _s.TryGet(_s.Length - 1, '\uFFFF')
 
int LineWidth => _s.Length - _lineStartIndex
 
int LineNumber => _lineNo
 
int Length => StringBuilder.Length
 Current length of the output string. This length can decrease if newlines are revoked. More...
 
- Properties inherited from Loyc.Syntax.Impl.LNodePrinterHelper
string IndentString [get, set]
 
string NewlineString [get, set]
 
string LabelIndentString [get, set]
 
string BracketIndentString [get, set]
 
int MaxBracketIndents [get, set]
 
StringBuilder StringBuilder [get, set]
 
Action< ILNode, IndexRange, int > SaveRange [get]
 Gets or sets a method that is called when the node's range in the output is locked in (after you call EndNode()). More...
 
- Properties inherited from Loyc.Syntax.Impl.ILNodePrinterHelperWithRevokableNewlines< Checkpoint, out Self >
int LineWidth [get]
 Gets the current width of the current line (typically measured in characters). More...
 
- Properties inherited from Loyc.Syntax.Impl.IPrinterHelper< out Self >
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...
 
- Protected Member Functions inherited from Loyc.Syntax.Impl.LNodePrinterHelper
virtual void OnNodeChanged (char firstChar)
 This method, which does nothing by default, is called by all three versions of Write() when the first character is written after a call to BeginNode(ILNode) or EndNode(). You can override this method can detect conflicts between this character and the previous characters in the stream (LastCharWritten). More...
 
virtual void AppendIndentAfterNewline (int indentStackSize)
 Called just after a newline is emitted to append indentation. More...
 
- Protected fields inherited from Loyc.Syntax.Impl.LNodePrinterHelper
int _indentLevel
 
int _lineNo
 
StringBuilder _s
 
InternalList< Pair< ILNode, int > > _nodeStack
 
InternalList< object > _indentStack