classCondition
final class Condition
Restricted visibility: declared "@visibility root". Code outside that scope must not name this declaration.
Evaluates the expression after %if, %ifdef or %ifndef.
Lemon reads the expression left to right with no precedence: a name is true when it is defined, ! negates the next term, parentheses group, and || and && stop as soon as the answer is known.
Methods§
public function __construct(private list<string> $defines)Parameters
$defines | list<string> | The names defined on the command line |
public function evaluate(string $text, Location $location): boolEvaluates an expression as eval_preprocessor_boolean does.
Parameters
$text | string | The expression |
$location | Location | Where the directive is, for errors |
Returns
bool The valueThrows
SyntaxException When the expression is not well formedTest cases 8
ConditionTest::testEvaluatecallsConditionTest::testEvaluateReadsLeftToRightWithoutPrecedencecallsConditionTest::testEvaluateRejectsAnAndWithoutALeftSidecallsConditionTest::testEvaluateRejectsANegationAfterATermcallsConditionTest::testEvaluateRejectsAnOperatorWithoutALeftSidecallsConditionTest::testEvaluateRejectsASingleAmpersandcallsConditionTest::testEvaluateRejectsASingleBarcallsConditionTest::testEvaluateRejectsTwoTermsInARowcalls
Called from 2
Calls 4
- function-call
strlenline 43 - function-call
ctype_spaceline 46 - method-call Condition::guard() line 50
- method-call Condition::term() line 73
public function term(string $text, int $index, Location $location): array{bool, int}Evaluates a parenthesised group or a name.
Parameters
$text | string | The whole expression |
$index | int | Where the term begins |
$location | Location | Where the directive is, for errors |
Returns
array{bool, int} The value and the index of the term's last byteThrows
SyntaxException When the term is not a group or a nameTest cases 3
Called from 1
Calls 6
- function-call
strlenline 97 - method-call Condition::evaluate() line 101
- function-call
substrline 101 - method-call Condition::error() line 104
- function-call
preg_matchline 106 - function-call
in_arrayline 110
public function guard(bool $condition, string $text, int $index, Location $location): voidRaises the error unless a condition holds.
Parameters
$condition | bool | What must hold |
$text | string | The whole expression |
$index | int | Where the problem is |
$location | Location | Where the directive is |
Throws
SyntaxException When the condition does not holdTest cases 1
ConditionTest::testGuardcalls
Called from 4
- method-call LemonParser\Preprocessor\Condition::evaluate() packages/lemon-parser/src/Preprocessor/Condition.php:50
- method-call LemonParser\Preprocessor\Condition::evaluate() packages/lemon-parser/src/Preprocessor/Condition.php:55
- method-call LemonParser\Preprocessor\Condition::evaluate() packages/lemon-parser/src/Preprocessor/Condition.php:64
- method-call LemonParser\Preprocessor\Condition::evaluate() packages/lemon-parser/src/Preprocessor/Condition.php:72
Calls 1
- method-call Condition::error() line 126
public function error(string $text, int $index, Location $location): SyntaxExceptionWords the error as Lemon does.
Parameters
$text | string | The whole expression |
$index | int | Where the problem is |
$location | Location | Where the directive is |
Returns
SyntaxException The errorTest cases 1
ConditionTest::testErrorcalls
Called from 3
- method-call LemonParser\Preprocessor\Condition::term() packages/lemon-parser/src/Preprocessor/Condition.php:104
- method-call LemonParser\Preprocessor\Condition::term() packages/lemon-parser/src/Preprocessor/Condition.php:107
- method-call LemonParser\Preprocessor\Condition::guard() packages/lemon-parser/src/Preprocessor/Condition.php:126
Calls 2
- new SyntaxException line 141
- function-call
substrline 141
Private surface 1§
Implementation details, listed for orientation only.
private list<string> $definesTest cases 19§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 13
ConditionTest::testErrorcallsConditionTest::testEvaluatecallsConditionTest::testEvaluateReadsLeftToRightWithoutPrecedencecallsConditionTest::testEvaluateRejectsAnAndWithoutALeftSidecallsConditionTest::testEvaluateRejectsANegationAfterATermcallsConditionTest::testEvaluateRejectsAnOperatorWithoutALeftSidecallsConditionTest::testEvaluateRejectsASingleAmpersandcallsConditionTest::testEvaluateRejectsASingleBarcallsConditionTest::testEvaluateRejectsTwoTermsInARowcallsConditionTest::testGuardcallsConditionTest::testTermcallsConditionTest::testTermRejectsANameStartingWithADigitcallsConditionTest::testTermRejectsAnUnclosedGroupcalls