Tptp.Printer.Spacing (Tptp v0.1.0)

Copy Markdown View Source

Determines the white space between two adjacent tokens.

Shared by Tptp.Printer.Canonical and Tptp.Printer.Pretty, so that both apply the same rules and the pretty printer's token sequence remains that of the canonical printer.

The rules are positional rather than syntactic, since a token pair is all that is available: no space precedes a closing delimiter or a separator, none follows an opening delimiter, and none precedes an opening delimiter that follows a word or a prefix operator. A single space is emitted elsewhere.

A space is never omitted where its absence would combine two tokens into a third under the lexer's longest-match rule.

Summary

Functions

Join tokens into iodata, spacing them.

Whether two adjacent tokens need a space between them.

Functions

join(list)

@spec join([binary()]) :: iodata()

Join tokens into iodata, spacing them.

iex> Tptp.Printer.Spacing.join(["p", "(", "a", ",", "b", ")"]) |> IO.iodata_to_binary()
"p(a, b)"

iex> Tptp.Printer.Spacing.join(["~", "p", "|", "q"]) |> IO.iodata_to_binary()
"~p | q"

space?(previous, next)

@spec space?(binary(), binary()) :: boolean()

Whether two adjacent tokens need a space between them.

iex> Tptp.Printer.Spacing.space?("~", "|")
true
iex> Tptp.Printer.Spacing.space?("~", "p")
false