classUnary
final class Unary
implements Scalar
uses Snapshot
Public API: explicitly declared with
@visibility public.A prefix operation over one operand.
Rule: SQLITE-UNARY-001. The facts follow SQLITE-OPERATOR-RESULT-001; the operand is a single value (SQLITE-ROW-VALUE-USE-001). The operand must keep its place without parentheses (SQLITE-PRECEDENCE-001): it may not start with an operator weaker than the prefix operator. Source: https://sqlite.org/lang_expr.html#operators_and_parse_affecting_attributes. Status: Implemented.
$query = (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze('SELECT -a FROM t');
$query->statement->columns[0]->expression->operand->name->value // => 'a'$sum = (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze('SELECT 1 + 2')->statement->columns[0]->expression;
new \SqlSemantics\Platform\Sqlite\Statement\Expression\Operator\Unary(\SqlSemantics\Platform\Sqlite\Statement\Expression\Operator\UnaryOperator::Minus, $sum) // throws \SqlSemantics\Platform\Sqlite\Model\Diagnostic\InvalidConstructionProperties§
public UnaryOperator $operatorpublic Scalar $operandMethods§
public function __construct(public UnaryOperator $operator, public Scalar $operand)Parameters
$operator | UnaryOperator | The operator |
$operand | Scalar | The operand |
Calls 6
- static-call Check::input() line 46
- method-call Precedence::opening() line 46
- new Precedence line 46
- class-const UnaryOperator::Not() line 46
- class-const Precedence::NEGATION() line 46
- class-const Precedence::PREFIX() line 46
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFactDerives the operand and the result of the operator.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 5
- method-call Derivation::scalar() line 54
- method-call RowValueUse::single() line 55
- new RowValueUse line 55
- method-call Operators::unary() line 57
- new Operators line 57
public function render(Output $out): voidWrites the operator before the operand.
Parameters
$out | Output |
Calls 4
- class-const UnaryOperator::Not() line 65
- method-call Output::keyword() line 66
- method-call Output::symbol() line 68
- method-call Output::node() line 70
Test cases 12§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 3
Other tests reaching this symbol 9
OperatorRuleTest::testExpressionLowersThePrefixOperatorscallsPrecedenceTest::testEdgesOfAPrefixOperatorHaveNoLeftOperandcallsOrdinalsTest::testValueIsNullForAnOrdinaryExpressioncallsOrdinalsTest::testValueLooksThroughSignsCollationsAndParenthesescallsBinaryTest::testRefusesIsFollowedByAPrefixNotcallsPatternMatchTest::testRefusesAnEscapeAfterAPatternThatWouldTakeItcallsUnaryOperatorTest::testEachOperatorIsReadFromItsSpellingcallsExistsTest::testRenderWritesTheKeywordAndTheParenthesescallsOutputOrdinalTest::testPositionCountsFromOnecalls
Relations§
Instantiated in 2
- new SqlSemantics\Platform\Sqlite\Lowering\Expression\OperatorRule::expression() packages/sql-semantics-sqlite/src/Lowering/Expression/OperatorRule.php:55
- new SqlSemantics\Platform\Sqlite\Lowering\Expression\OperatorRule::expression() packages/sql-semantics-sqlite/src/Lowering/Expression/OperatorRule.php:56
Type checks 6
- instanceof SqlSemantics\Platform\Sqlite\Rules\Definition\Expression\LiteralDefaults::constant() packages/sql-semantics-sqlite/src/Rules/Definition/Expression/LiteralDefaults.php:90
- instanceof SqlSemantics\Platform\Sqlite\Rules\Definition\Query\ValueKinds::of() packages/sql-semantics-sqlite/src/Rules/Definition/Query/ValueKinds.php:88
- instanceof SqlSemantics\Platform\Sqlite\Rules\Expression\Precedence::edges() packages/sql-semantics-sqlite/src/Rules/Expression/Precedence.php:115
- instanceof SqlSemantics\Platform\Sqlite\Rules\Query\Ordinals::value() packages/sql-semantics-sqlite/src/Rules/Query/Ordinals.php:39
- instanceof SqlSemantics\Platform\Sqlite\Rules\Query\Ordinals::value() packages/sql-semantics-sqlite/src/Rules/Query/Ordinals.php:40
- instanceof SqlSemantics\Platform\Sqlite\Statement\Expression\Operator\Binary::__construct() packages/sql-semantics-sqlite/src/Statement/Expression/Operator/Binary.php:53