packages/sql-semantics-postgres/src/Model/Statement/Spelling/Spelled.php
1<?php
2
3declare(strict_types=1);
4
5namespace SqlSemantics\Platform\PostgreSql\Model\Statement\Spelling;
6
7use SqlSemantics\Platform\PostgreSql\Model\Diagnostic\Check;
8use SqlSemantics\Platform\PostgreSql\Model\Statement\Snapshot;
9
10/**
11 * How one token of a spelled region was written: the trivia before it and its own spelling.
12 *
13 * The spelling is a choice among the equivalent spellings of the token the
14 * rendering produces at that position, such as the letter case of a keyword
15 * or the quoting of a name. It never adds or removes a token.
16 *
17 * @visibility public
18 * @example Reading the spelling of a token
19 * $token = new \SqlSemantics\Platform\PostgreSql\Model\Statement\Spelling\Spelled(' ', 'and');
20 * [$token->gap, $token->text] // => [' ', 'and']
21 */
22final class Spelled
23{
24 use Snapshot;
25
26 /**
27 * @param string $gap The whitespace and comments written before the token; empty for the first token of a region
28 * @param string $text The spelling of the token
29 */
30 public function __construct(public readonly string $gap, public readonly string $text)
31 {
32 Check::input($text !== '', 'A spelled token is not empty.');
33 }
34}
35