classSpellings
final class Spellings
Checks that the layouts of a rendering only re-spelled the rendered tokens.
Rule: CORE-SPELLING-001 (validation part). The SQL as the structure renders it and the SQL as the layouts spell it are read by the parser of the profile. Both must have the same number of tokens, and the comparison keys of the token correspondence check, which depend on the production and position of each token, must be equal position by position. A layout therefore cannot add, drop or change a significant token, its gaps can only hold whitespace and comments, and a spelling counts as the same token only where the database reads it as the same request. Status: Implemented.
Methods§
public function __construct(
private SqlParser $parser,
private Productions $productions,
private LeafKeys $keys,
)Parameters
$parser | SqlParser | The parser of the profile |
$productions | Productions | The productions of the grammar release |
$keys | LeafKeys | The token rules of the profile |
public function check(string $rendered, string $spelled): voidRefuses a spelled SQL text whose tokens are not those of the rendered SQL text.
Parameters
$rendered | string | |
$spelled | string |
Throws
InvariantViolation When a layout changed a token or wrote a token into a gapCalled from 1
Calls 7
- method-call Spellings::tokens() line 51
- static-call Check::invariant() line 53
- function-call
countline 53 - new TokenCorrespondence line 54
- method-call TokenCorrespondence::difference() line 55
- method-call TokenCorrespondence::keys() line 55
- method-call Spellings::tree() line 55
public function tree(string $text): NodeParses a rendered or spelled text.
Parameters
$text | string |
Returns
NodeThrows
InvariantViolation When the text is outside the grammarCalled from 1
Calls 2
- method-call SqlParser::parse() line 67
- new InvariantViolation line 69
public function tokens(string $text): list<Token>Reads the tokens of a text, without the end marker.
Parameters
$text | string |
Returns
list<Token>Throws
InvariantViolation When the text is not lexically validCalled from 2
- method-call SqlSemantics\Platform\PostgreSql\Model\Validation\Spellings::check() packages/sql-semantics-postgres/src/Model/Validation/Spellings.php:51
- method-call SqlSemantics\Platform\PostgreSql\Model\Validation\Spellings::check() packages/sql-semantics-postgres/src/Model/Validation/Spellings.php:52
Calls 4
- method-call SqlParser::tokenize() line 82
- new InvariantViolation line 84
- function-call
array_valuesline 87 - function-call
array_filterline 87
Private surface 3§
Implementation details, listed for orientation only.
private SqlParser $parserprivate Productions $productionsprivate LeafKeys $keys