class PhpWriter

PHP code generator helpers.

Methods

static PhpWriter
using(MacroNode $node, Compiler|null $compiler = null)

No description

__construct(MacroTokens $tokens, string|null $modifiers = null, array|null $context = null)

No description

string
write(string $mask, mixed ...$args)

Expands %node.word, %node.array, %node.args, %node.line, %escape(), %modify(), %var, %raw, %word in code.

string
formatModifiers(string $var, bool $isContent = false)

Formats modifiers calling.

string
formatArgs(MacroTokens|null $tokens = null)

Formats macro arguments to PHP code. (It advances tokenizer to the end as a side effect.)

string
formatArray(MacroTokens|null $tokens = null)

Formats macro arguments to PHP array. (It advances tokenizer to the end as a side effect.)

string
formatWord(string $s)

Formats parameter to PHP string.

preprocess(MacroTokens|null $tokens = null)

Preprocessor for tokens. (It advances tokenizer to the end as a side effect.)

void
validateTokens(MacroTokens $tokens)

No description

void
validateKeywords(MacroTokens $tokens)

No description

removeCommentsPass(MacroTokens $tokens)

Removes PHP comments.

replaceFunctionsPass(MacroTokens $tokens)

Replace global functions with custom ones.

shortTernaryPass(MacroTokens $tokens)

Simplified ternary expressions without third part.

optionalChainingPass(MacroTokens $tokens)

Nullsafe operator $var?->prop?->elem[1]?->call()?->item Null-coalescing-safe operator $var??->prop??->elem[1]??->call()??->item

expandCastPass(MacroTokens $tokens)

Pseudocast (expand).

quotingPass(MacroTokens $tokens)

Quotes symbols to strings.

namedArgumentsPass(MacroTokens $tokens)

Converts named arguments name: value to 'name' => value

modernArraySyntax(MacroTokens $tokens)

Converts [name: value] to ['name' => value]

inOperatorPass(MacroTokens $tokens)

Syntax $entry in [item1, item2].

sandboxPass(MacroTokens $tokens)

Applies sandbox policy.

inlineModifierPass(MacroTokens $tokens)

Process inline filters ($var|filter)

modifierPass(MacroTokens $tokens, $var, bool $isContent = false)

Formats modifiers calling.

escapePass(MacroTokens $tokens)

Escapes expression in tokens.

Details

at line 39
static PhpWriter using(MacroNode $node, Compiler|null $compiler = null)

No description

Parameters

MacroNode $node
Compiler|null $compiler

Return Value

PhpWriter

at line 53
__construct(MacroTokens $tokens, string|null $modifiers = null, array|null $context = null)

No description

Parameters

MacroTokens $tokens
string|null $modifiers
array|null $context

at line 65
string write(string $mask, mixed ...$args)

Expands %node.word, %node.array, %node.args, %node.line, %escape(), %modify(), %var, %raw, %word in code.

Parameters

string $mask
mixed ...$args

Return Value

string

at line 132
string formatModifiers(string $var, bool $isContent = false)

Formats modifiers calling.

Parameters

string $var
bool $isContent

Return Value

string

at line 148
string formatArgs(MacroTokens|null $tokens = null)

Formats macro arguments to PHP code. (It advances tokenizer to the end as a side effect.)

Parameters

MacroTokens|null $tokens

Return Value

string

at line 160
string formatArray(MacroTokens|null $tokens = null)

Formats macro arguments to PHP array. (It advances tokenizer to the end as a side effect.)

Parameters

MacroTokens|null $tokens

Return Value

string

at line 174
string formatWord(string $s)

Formats parameter to PHP string.

Parameters

string $s

Return Value

string

at line 190
MacroTokens preprocess(MacroTokens|null $tokens = null)

Preprocessor for tokens. (It advances tokenizer to the end as a side effect.)

Parameters

MacroTokens|null $tokens

Return Value

MacroTokens

at line 207
void validateTokens(MacroTokens $tokens)

No description

Parameters

MacroTokens $tokens

Return Value

void

Exceptions

CompileException

at line 254
void validateKeywords(MacroTokens $tokens)

No description

Parameters

MacroTokens $tokens

Return Value

void

Exceptions

CompileException

at line 285
MacroTokens removeCommentsPass(MacroTokens $tokens)

Removes PHP comments.

Parameters

MacroTokens $tokens

Return Value

MacroTokens

at line 299
MacroTokens replaceFunctionsPass(MacroTokens $tokens)

Replace global functions with custom ones.

Parameters

MacroTokens $tokens

Return Value

MacroTokens

at line 327
MacroTokens shortTernaryPass(MacroTokens $tokens)

Simplified ternary expressions without third part.

Parameters

MacroTokens $tokens

Return Value

MacroTokens

at line 365
MacroTokens optionalChainingPass(MacroTokens $tokens)

Nullsafe operator $var?->prop?->elem[1]?->call()?->item Null-coalescing-safe operator $var??->prop??->elem[1]??->call()??->item

Parameters

MacroTokens $tokens

Return Value

MacroTokens

at line 467
MacroTokens expandCastPass(MacroTokens $tokens)

Pseudocast (expand).

Parameters

MacroTokens $tokens

Return Value

MacroTokens

at line 496
MacroTokens quotingPass(MacroTokens $tokens)

Quotes symbols to strings.

Parameters

MacroTokens $tokens

Return Value

MacroTokens

at line 519
MacroTokens namedArgumentsPass(MacroTokens $tokens)

Converts named arguments name: value to 'name' => value

Parameters

MacroTokens $tokens

Return Value

MacroTokens

at line 543
MacroTokens modernArraySyntax(MacroTokens $tokens)

Converts [name: value] to ['name' => value]

Parameters

MacroTokens $tokens

Return Value

MacroTokens

at line 573
MacroTokens inOperatorPass(MacroTokens $tokens)

Syntax $entry in [item1, item2].

Parameters

MacroTokens $tokens

Return Value

MacroTokens

at line 610
MacroTokens sandboxPass(MacroTokens $tokens)

Applies sandbox policy.

Parameters

MacroTokens $tokens

Return Value

MacroTokens

at line 734
MacroTokens inlineModifierPass(MacroTokens $tokens)

Process inline filters ($var|filter)

Parameters

MacroTokens $tokens

Return Value

MacroTokens

at line 803
MacroTokens modifierPass(MacroTokens $tokens, $var, bool $isContent = false)

Formats modifiers calling.

Parameters

MacroTokens $tokens
$var
bool $isContent

Return Value

MacroTokens

Exceptions

CompileException

at line 881
MacroTokens escapePass(MacroTokens $tokens)

Escapes expression in tokens.

Parameters

MacroTokens $tokens

Return Value

MacroTokens

Traits

Better OOP experience.