slang::syntax::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
A helper method that assists in printing an entire syntax tree back to source text.

Public functions

auto append(std::string_view text) -> SyntaxPrinter&
Append raw text to the buffer.
auto print(parsing::Trivia trivia) -> SyntaxPrinter&
Print the provided trivia to the internal buffer.
auto print(parsing::Token token) -> SyntaxPrinter&
Print the provided token to the internal buffer.
auto print(const SyntaxNode& node) -> SyntaxPrinter&
Print the provided node to the internal buffer.
auto print(const SyntaxTree& tree) -> SyntaxPrinter&
Print the provided tree to the internal buffer.
auto setIncludeTrivia(bool include) -> SyntaxPrinter&
Sets whether to include trivia when printing syntax.
auto setIncludeMissing(bool include) -> SyntaxPrinter&
Sets whether to include missing (automatically inserted) nodes when printing syntax.
auto setIncludeSkipped(bool include) -> SyntaxPrinter&
Sets whether to include skipped (due to some sort of error) nodes when printing syntax.
auto setIncludeDirectives(bool include) -> SyntaxPrinter&
Sets whether to include preprocessor directives when printing syntax.
auto setIncludePreprocessed(bool include) -> SyntaxPrinter&
Sets whether to include preprocessor-expanded tokens when printing syntax.
auto setIncludeComments(bool include) -> SyntaxPrinter&
Sets whether to include comments when printing syntax.
auto setSquashNewlines(bool include) -> SyntaxPrinter&
Sets whether to squash adjacent newlines down into one when printing syntax.
auto str() const -> std::string

Function documentation

static std::string slang::syntax::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::syntax::SyntaxPrinter::append(std::string_view text)

Append raw text to the buffer.

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

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

Print the provided trivia to the internal buffer.

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

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

Print the provided token to the internal buffer.

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

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

Print the provided node to the internal buffer.

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

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

Print the provided tree to the internal buffer.

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

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

Sets whether to include trivia when printing syntax.

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

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

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

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

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

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

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

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

Sets whether to include preprocessor directives when printing syntax.

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

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

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

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

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

Sets whether to include comments when printing syntax.

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

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

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

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

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

Returns a copy of the internal text buffer.