Documentation

Class: Tag

Full name: Clarity\Engine\Compiler\Tag

One scanned tag, as the pre-scan sees it.

A tag is {% … %} (BLOCK), {{ … }} (OUTPUT) or {# … #} (COMMENT), with the byte range it occupied in the source. Only BLOCK tags carry a keyword; the pre-scan only ever needs to look at block tags, and never at text.

Public Properties

  • public readonly int $type ·
  • public readonly string $content ·
  • public readonly int $line ·
  • public readonly int $start ·
  • public readonly int $end ·

Public methods

__construct() ·

public function __construct(int $type, string $content, int $line, int $start, int $end): mixed

Parameters

Name Type Default Description
$type int - One of the Tokenizer::TEXT/OUTPUT/BLOCK/COMMENT constants.
$content string - The tag's inner text, trimmed.
$line int - 1-based line the tag starts on.
$start int - Byte offset of the opening delimiter.
$end int - Byte offset just past the closing delimiter.

Return value

  • Type: mixed

isBlock() ·

public function isBlock(): bool

Return value

  • Type: bool

isComment() ·

public function isComment(): bool

Return value

  • Type: bool

keyword() ·

public function keyword(): string

The lowercased first word of a block tag, or '' for anything else.

{% endblock %} -> "endblock", {% if x %}, -> "if". Matching is on the whole word, so {% endforelse %} never reads as endfor.

Return value

  • Type: string

is() ·

public function is(string $keyword): bool

Whether this is a block tag whose keyword is $keyword.

Parameters

Name Type Default Description
$keyword string -

Return value

  • Type: bool

rest() ·

public function rest(): string

The tag's content with its first word removed and trimmed — the argument text a directive parser wants.

Return value

  • Type: string

Back to the Index