packages/sql-semantics-mysql/resources/models/Value/StartEntryWithGrammarSelectorGcolIdentSysExprEndOfInput_5a05b17d.php

1<?php
2
3declare(strict_types=1);
4
5namespace SqlSemantics\Statement\Model\MySql\Value;
6
7/**
8 * The start_entry SQL value; generated by bin/build-models.php.
9 *
10 * @visibility public
11 * @example Accept a structured SQL value
12 *     $write = static fn (\SqlSemantics\Statement\Model\MySql\Value\StartEntryWithGrammarSelectorGcolIdentSysExprEndOfInput_5a05b17d $value): string => \SqlSemantics\Statement\Writer::render($value);
13 *     $write instanceof \Closure // => true
14 */
15final class StartEntryWithGrammarSelectorGcolIdentSysExprEndOfInput_5a05b17d implements \SqlSemantics\Statement\Model\MySql\Role\StartEntryForm
16{
17    use \SqlSemantics\Statement\Assertion;
18
19    /**
20     * Supplies the SQL values of this form; comments are kept by the position of the symbol each precedes.
21     */
22    public function __construct(
23        public readonly string $grammarSelectorGcol,
24        public readonly \SqlSemantics\Statement\Model\MySql\Role\IdentSysForm $identSys,
25        public readonly \SqlSemantics\Statement\Model\MySql\Role\ExprForm $expr,
26        public readonly \SqlSemantics\Statement\Comments $comments = new \SqlSemantics\Statement\Comments(),
27    ) {
28        $this->assertMatchesPattern($grammarSelectorGcol, \SqlSemantics\Statement\Model\MySql\Contract\Contracts::SPELLINGS['GRAMMAR_SELECTOR_GCOL'], 'The grammarSelectorGcol must be a complete GRAMMAR_SELECTOR_GCOL lexical spelling.');
29        $this->assert(\SqlSemantics\Statement\Model\MySql\Contract\Contracts::contains($identSys), 'The identSys must be a generated immutable SQL value.');
30        $this->assert(\SqlSemantics\Statement\Model\MySql\Contract\Contracts::contains($expr), 'The expr must be a generated immutable SQL value.');
31    }
32
33    /**
34     * Writes SQL entirely from this value's fields.
35     */
36    public function write(\SqlSemantics\Statement\Writer $writer): void
37    {
38        $writer->comments($this->comments, 0);
39        $writer->append($this->grammarSelectorGcol);
40        $writer->comments($this->comments, 1);
41        $this->identSys->write($writer);
42        $writer->comments($this->comments, 2);
43        $writer->append('(');
44        $writer->comments($this->comments, 3);
45        $this->expr->write($writer);
46        $writer->comments($this->comments, 4);
47        $writer->append(')');
48        $writer->comments($this->comments, 5);
49    }
50
51    /**
52     * Returns a copy with a new grammarSelectorGcol, preserving every other field.
53     */
54    public function withGrammarSelectorGcol(string $grammarSelectorGcol): self
55    {
56        return new self($grammarSelectorGcol, $this->identSys, $this->expr, $this->comments);
57    }
58
59    /**
60     * Returns a copy with a new identSys, preserving every other field.
61     */
62    public function withIdentSys(\SqlSemantics\Statement\Model\MySql\Role\IdentSysForm $identSys): self
63    {
64        return new self($this->grammarSelectorGcol, $identSys, $this->expr, $this->comments);
65    }
66
67    /**
68     * Returns a copy with a new expr, preserving every other field.
69     */
70    public function withExpr(\SqlSemantics\Statement\Model\MySql\Role\ExprForm $expr): self
71    {
72        return new self($this->grammarSelectorGcol, $this->identSys, $expr, $this->comments);
73    }
74
75    /**
76     * Returns a copy with a new comments, preserving every other field.
77     */
78    public function withComments(\SqlSemantics\Statement\Comments $comments): self
79    {
80        return new self($this->grammarSelectorGcol, $this->identSys, $this->expr, $comments);
81    }
82}
83