SourceCodeWriter

Description

sealed class Tinman.Core.Parsing.SourceCodeWriter

Derived from

Disposable abstract
IFlushable

A text writer with additional functionality related to emitting common source code structures, such as pairs of braces and indented blocks.

Public / Constructors

Source​Code​Writer


public constructor SourceCodeWriter → (4)

stream in : ITextStream own

[not-null]
The output text stream.

autoBreakColumns opt : int32 = 100

[>=0]
The maximum number of columns (inclusive indentation) to write per source code line before emitting an automatic line break.

indentToken opt : string = "  "

[not-null]
The string token that represents a single indentation level.

newlineToken opt : LineEnding = LineEnding.Native

The string token that represents a line break.

Creates a new instance of SourceCodeWriter.

Public / Methods

Angle


public method Angle → ()

returns → SourceCodeWriter

this

Begins a nested pair of angle brackets: < >

IOException

If an I/O error has occurred.

Auto​Break​Pop


public method AutoBreakPop → ()

returns → SourceCodeWriter

this

Restores the saved auto-break settings from the internal stack.

Auto​Break​Push

2 overloads


public method AutoBreakPush1 → ()

returns → SourceCodeWriter

this

Saves the current auto-break settings onto an internal stack.


public method AutoBreakPush2 → (1)

autoBreakPause in : bool

See AutoBreakPause.

returns → SourceCodeWriter

this

Saves the current auto-break settings onto an internal stack and updates the settings.

Braces


public method Braces → ()

returns → SourceCodeWriter

this

Begins a nested pair of braces: ( )

IOException

If an I/O error has occurred.

Brackets


public method Brackets → ()

returns → SourceCodeWriter

this

Begins a nested pair of square brackets: [ ]

IOException

If an I/O error has occurred.

Close


public method Close → ()

returns → SourceCodeWriter

this

Closes the current nested tag by writing the end tag that has been specified by the corresponding call to Open2.

IOException

If an I/O error has occurred.

Colon


public method Colon → ()

returns → SourceCodeWriter

this

Writes a token: ':'

IOException

If an I/O error has occurred.

Comma


public method Comma → (1)

autoBreakPause opt : bool = true

Set AutoBreakPause to true while writing the token?

returns → SourceCodeWriter

this

Writes a token: ','

IOException

If an I/O error has occurred.

Curly


public method Curly → ()

returns → SourceCodeWriter

this

Begins a nested pair of curly braces: { }

IOException

If an I/O error has occurred.

Indent​Left


public method IndentLeft → (1)

opt : int32 = 1

[>=0]
Number of indentation levels to remove.

returns → SourceCodeWriter

this

Decreases the indentation level.

The new indentation level will be taken into account immediately for fresh lines or after the next line break has been emitted.

Indent​Right


public method IndentRight → (1)

opt : int32 = 1

[>=0]
Number of indentation levels to add.

returns → SourceCodeWriter

this

Increases the indentation level.

The new indentation level will be taken into account immediately for fresh lines or after the next line break has been emitted.

Line​Prefix


public method LinePrefix → (1)

value in : string

The line prefix value or null to disable the line prefix. Passing the empty string has the same effect as passing null.

Specifies the line prefix to use for subsequent text.

IOException

If an I/O error has occurred.

Newline

2 overloads


public method Newline1 → (1)

opt : int32 = 1

[>=0]
Number of line breaks to emit.

returns → SourceCodeWriter

this

Appends a line break and begins a fresh line.

IOException

If an I/O error has occurred.


public method Newline2 → (1)

token in : string

[not-null]
The string token to write.

returns → SourceCodeWriter

this

Writes the given token, followed by a line break.

IOException

If an I/O error has occurred.

Newline​If​Not​Fresh


public method NewlineIfNotFresh → ()

returns → SourceCodeWriter

this

Ensures that the current write cursor is located at the beginning of a fresh source code line.

This method emits a line break when characters have been written to the current code line.

IOException

If an I/O error has occurred.

Node


public method Node → (2)

node in : ICodeOutput

[not-null]
The source code producing node.

context in : Context

[not-null]
Context object.

returns → SourceCodeWriter

this

Writes a node that itself is producing source code.

IOException

If an I/O error has occurred.

Open

2 overloads


public method Open1 → (1)

tag in : string

[not-null]
The opening and end tag.

returns → SourceCodeWriter

this

Begins a nested tag by writing the opening tag now and the end tag when the corresponding call to Close is made.

IOException

If an I/O error has occurred.


public method Open2 → (2)

openTag in : string

[not-null]
The opening tag.

endTag in : string

[not-null]
The end tag.

returns → SourceCodeWriter

this

Begins a nested tag by writing the opening tag now and the end tag when the corresponding call to Close is made.

IOException

If an I/O error has occurred.

Period


public method Period → ()

returns → SourceCodeWriter

this

Writes a token: '.'

IOException

If an I/O error has occurred.

Semicolon


public method Semicolon → (1)

autoBreakPause opt : bool = true

Set AutoBreakPause to true while writing the token?

returns → SourceCodeWriter

this

Writes a token: ';'

IOException

If an I/O error has occurred.

Tag


public method Tag → (1)

name in : string

[not-empty]
The tag name.

returns → SourceCodeWriter

this

Begins an XML element pair: <name> </name>

IOException

If an I/O error has occurred.

Text


public method Text → (2)

text in : string

[not-null]
The text to write.

behaviour opt : TrimBehaviour = TrimBehaviour.WhitespaceAndLineBreak

The trim behaviour to use.

returns → SourceCodeWriter

this

Writes the given text.

The text will be split at the whitespaces and the resulting tokens will be emitted in order.

IOException

If an I/O error has occurred.

Token

2 overloads


public method Token1 → (2)

token in : string

[not-null]
The token to write.

newline opt : bool = false

Output a line break after writing the token?

returns → SourceCodeWriter

this

Writes a token on the current source code line.

A token is considered to be atomic, i.e. it will never be split because of automatic line breaks.

IOException

If an I/O error has occurred.


public method Token2 → (2)

token in : char

The token character to write.

opt : int32 = 1

Number of times to repeat token in.

returns → SourceCodeWriter

this

Writes a token on the current source code line.

A token is considered to be atomic, i.e. it will never be split because of automatic line breaks.

IOException

If an I/O error has occurred.

White


public method White → (1)

deferred opt : bool = true

false to write a whitespace token immediately, true to defer writing until the subsequent token is output: the whitespace will only be output if the subsequent token is not a whitespace.

returns → SourceCodeWriter

this

Writes a whitespace token.

IOException

If an I/O error has occurred.

Will​Auto​Break


public method WillAutoBreak → (2)

opt : int32 = 1

[>=0]
Length of next token, in characters.

breakOverlong opt : bool = false

true to return true for overlong tokens (i.e. tokens that do not fit into a single line),
false to return false for overlong tokens.

returns → bool

true if a line-break will occur, false if not.

Will an automatic line-break occur when the next token is output?

Public / Attributes

Auto​Break​Columns


public attribute AutoBreakColumns → (get)

value : int32

[>=0]
The maximum number of columns before auto-breaking occurs.

The maximum number of columns (inclusive indentation) to write per source code line before emitting an automatic line break.

Auto​Break​Pause


public attribute AutoBreakPause → (get,set)

value : bool

true to suspend automatic line breaking,
false to resume it.

Suspends resp. resumes automatic line breaking.

Defaults to false.

Column


public attribute Column → (get)

value : int32

[>=0]
The current column number.

Returns the current column number (zero-based).

Indent


public attribute Indent → (get,set)

value : int32

[>=0]
The current line indent level.

The current line indent level.

The new indent level will be taken into account for fresh lines or after the next line break has been emitted.

Indent​Token


public attribute IndentToken → (get)

value : string

[not-null]
The indent token string.

The string token that represents a single indentation level.

Is​Fresh​Line


public attribute IsFreshLine → (get)

value : bool

true if the current line is fresh, false if not.

Is the current line fresh (i.e. no characters have been output yet)?

Line


public attribute Line → (get)

value : int32

[>=0]
The current line number.

Returns the current line number (zero-based).