slang::SyntaxPrinter class

Provides support for printing tokens, trivia, or whole syntax trees back to source code.

Public static functions

static auto printFile(const SyntaxTree& tree) -> std::string

Public functions

auto print(Trivia trivia) -> SyntaxPrinter&
auto print(Token token) -> SyntaxPrinter&
auto print(const SyntaxNode& node) -> SyntaxPrinter&
auto print(const SyntaxTree& tree) -> SyntaxPrinter&
auto setIncludeTrivia(bool include) -> SyntaxPrinter&
auto setIncludeMissing(bool include) -> SyntaxPrinter&
auto setIncludeSkipped(bool include) -> SyntaxPrinter&
auto setIncludeDirectives(bool include) -> SyntaxPrinter&
auto setIncludePreprocessed(bool include) -> SyntaxPrinter&
auto setIncludeComments(bool include) -> SyntaxPrinter&
auto setSquashNewlines(bool include) -> SyntaxPrinter&
auto str() const -> std::string

Function documentation

static std::string slang::SyntaxPrinter::printFile(const SyntaxTree& tree)

A helper method that assists in printing an entire syntax tree back to source text. A SyntaxPrinter with useful defaults is constructed, the tree is printed, and the resulting text is returned.

SyntaxPrinter& slang::SyntaxPrinter::print(Trivia trivia)

Returns a reference to this object, to allow chaining additional method calls.

Print the provided trivia to the internal buffer.

SyntaxPrinter& slang::SyntaxPrinter::print(Token token)

Returns a reference to this object, to allow chaining additional method calls.

Print the provided token to the internal buffer.

SyntaxPrinter& slang::SyntaxPrinter::print(const SyntaxNode& node)

Returns a reference to this object, to allow chaining additional method calls.

Print the provided node to the internal buffer.

SyntaxPrinter& slang::SyntaxPrinter::print(const SyntaxTree& tree)

Returns a reference to this object, to allow chaining additional method calls.

Print the provided tree to the internal buffer.

SyntaxPrinter& slang::SyntaxPrinter::setIncludeTrivia(bool include)

Returns a reference to this object, to allow chaining additional method calls.

Sets whether to include trivia when printing syntax.

SyntaxPrinter& slang::SyntaxPrinter::setIncludeMissing(bool include)

Returns a reference to this object, to allow chaining additional method calls.

Sets whether to include missing (automatically inserted) nodes when printing syntax.

SyntaxPrinter& slang::SyntaxPrinter::setIncludeSkipped(bool include)

Returns a reference to this object, to allow chaining additional method calls.

Sets whether to include skipped (due to some sort of error) nodes when printing syntax.

SyntaxPrinter& slang::SyntaxPrinter::setIncludeDirectives(bool include)

Returns a reference to this object, to allow chaining additional method calls.

Sets whether to include preprocessor directives when printing syntax.

SyntaxPrinter& slang::SyntaxPrinter::setIncludePreprocessed(bool include)

Returns a reference to this object, to allow chaining additional method calls.

Sets whether to include preprocessor-expanded tokens when printing syntax.

SyntaxPrinter& slang::SyntaxPrinter::setIncludeComments(bool include)

Returns a reference to this object, to allow chaining additional method calls.

Sets whether to include comments when printing syntax.

SyntaxPrinter& slang::SyntaxPrinter::setSquashNewlines(bool include)

Returns a reference to this object, to allow chaining additional method calls.

Sets whether to squash adjacent newlines down into one when printing syntax.

std::string slang::SyntaxPrinter::str() const

Returns a copy of the internal text buffer.