Parser
class Parser
Constants
RULE_AUTO_CLOSE |
|
RULE_AUTO_REOPEN |
|
RULE_BREAK_PARAGRAPH |
|
RULE_CREATE_PARAGRAPHS |
|
RULE_DISABLE_AUTO_BR |
|
RULE_ENABLE_AUTO_BR |
|
RULE_IGNORE_TAGS |
|
RULE_IGNORE_TEXT |
|
RULE_IGNORE_WHITESPACE |
|
RULE_IS_TRANSPARENT |
|
RULE_PREVENT_BR |
|
RULE_SUSPEND_AUTO_BR |
|
RULE_TRIM_FIRST_LINE |
|
RULES_AUTO_LINEBREAKS |
Bitwise disjunction of rules related to automatic line breaks |
RULES_INHERITANCE |
Bitwise disjunction of rules that are inherited by subcontexts |
WHITESPACE |
All the characters that are considered whitespace |
Properties
protected array | $cntOpen | ||
protected array | $cntTotal | ||
protected array | $context | ||
protected int | $currentFixingCost | ||
protected Tag | $currentTag | ||
protected bool | $isRich | ||
protected Logger | $logger | ||
int | $maxFixingCost | ||
protected array | $namespaces | ||
protected array | $openTags | ||
protected string | $output | ||
protected int | $pos | ||
protected array | $pluginParsers | ||
protected array | $pluginsConfig | ||
array | $registeredVars | ||
protected array | $rootContext | ||
protected array | $tagsConfig | ||
protected array | $tagStack | ||
protected bool | $tagStackIsSorted | ||
protected string | $text | ||
protected int | $textLen | ||
protected int | $uid | ||
protected int | $wsPos |
Methods
Constructor
Serializer
Unserializer
Reset the parser for a new parsing
Set a tag's option
Disable a tag
Enable a tag
Return the last text parsed
Parse a text
Change a tag's tagLimit
Change a tag's nestingLimit
Finalize the output by appending the rest of the unprocessed text and create the root node
Output the text between the cursor's position (included) and given position (not included)
Start a paragraph between current position and given position, if applicable
Close current paragraph at current position if applicable
Skip as much whitespace after current position as possible
Disable a plugin
Enable a plugin
Execute given plugin
Execute all the plugins
Execute given regexp and returns as many matches as given limit
Get the cached callback for given plugin's parser
Register a parser
Create and add an end tag for given start tag at given position
Compute the position of a magic end tag, adjusted for whitespace
Compute the position and priority of a magic start tag, adjusted for whitespace
Test whether given start tag is immediately followed by a closing tag
Process all tags in the stack
Process current tag
Update counters and replace current context with its parent context
Update counters and replace current context with a new context based on given tag
Return whether given tag is allowed in current context
Add a start tag
Add a self-closing tag
Add a 0-width "br" tag to force a line break at given position
Add an "ignore" tag
Add a paragraph break at given position
Add a copy of given tag at given position and length
Test whether given text span is outside text boundaries or an invalid UTF sequence
Add a pair of tags
Add a tag that represents a verbatim copy of the original text
Sort tags by position and precedence
Generate a key for given tag that can be used to compare its position using lexical comparisons
Details
at line 170
__construct(array $config)
Constructor
at line 190
array
__sleep()
Serializer
Returns the properties that need to persist through serialization.
NOTE: using __sleep() is preferable to implementing Serializable because it leaves the choice of the serializer to the user (e.g. igbinary)
at line 200
void
__wakeup()
Unserializer
at line 211
protected void
reset(string $text)
Reset the parser for a new parsing
at line 261
protected void
setTagOption(string $tagName, string $optionName, mixed $optionValue)
Set a tag's option
This method ensures that the tag's config is a value and not a reference, to prevent potential side-effects. References contained inside the tag's config are left untouched
at line 285
void
disableTag(string $tagName)
Disable a tag
at line 296
void
enableTag(string $tagName)
Enable a tag
at line 309
Logger
getLogger()
Get this parser's Logger instance
at line 326
string
getText()
Return the last text parsed
This method returns the normalized text, which may be slightly different from the original text in that EOLs are normalized to LF and other control codes are stripped. This method is meant to be used in support of processing log entries, which contain offsets based on the normalized text
at line 337
string
parse(string $text)
Parse a text
at line 374
void
setTagLimit(string $tagName, int $tagLimit)
Change a tag's tagLimit
NOTE: the default tagLimit should generally be set during configuration instead
at line 388
void
setNestingLimit(string $tagName, int $nestingLimit)
Change a tag's nestingLimit
NOTE: the default nestingLimit should generally be set during configuration instead
at line 402
protected void
finalizeOutput()
Finalize the output by appending the rest of the unprocessed text and create the root node
at line 445
protected void
outputTag(Tag $tag)
Append a tag to the output
at line 559
protected void
outputText(int $catchupPos, int $maxLines, bool $closeParagraph)
Output the text between the cursor's position (included) and given position (not included)
at line 717
protected void
outputBrTag(Tag $tag)
Output a linebreak tag
at line 729
protected void
outputIgnoreTag(Tag $tag)
Output an ignore tag
at line 752
protected void
outputParagraphStart(int $maxPos)
Start a paragraph between current position and given position, if applicable
at line 777
protected void
outputParagraphEnd()
Close current paragraph at current position if applicable
at line 795
protected void
outputVerbatim(Tag $tag)
Output the content of a verbatim tag
at line 809
protected void
outputWhitespace(int $maxPos)
Skip as much whitespace after current position as possible
at line 833
void
disablePlugin(string $pluginName)
Disable a plugin
at line 853
void
enablePlugin(string $pluginName)
Enable a plugin
at line 867
protected void
executePluginParser(string $pluginName)
Execute given plugin
at line 894
protected void
executePluginParsers()
Execute all the plugins
at line 912
protected array
getMatches(string $regexp, int $limit)
Execute given regexp and returns as many matches as given limit
at line 929
protected callable
getPluginParser(string $pluginName)
Get the cached callback for given plugin's parser
at line 958
void
registerParser(string $pluginName, callable $parser, string $regexp = null, int $limit = PHP_INT_MAX)
Register a parser
Can be used to add a new parser with no plugin config, or pre-generate a parser for an existing plugin
at line 987
protected bool
closeAncestor(Tag $tag)
Apply closeAncestor rules associated with given tag
at line 1028
protected bool
closeParent(Tag $tag)
Apply closeParent rules associated with given tag
at line 1064
protected void
createChild(Tag $tag)
Apply the createChild rules associated with given tag
at line 1091
protected bool
fosterParent(Tag $tag)
Apply fosterParent rules associated with given tag
NOTE: this rule has the potential for creating an unbounded loop, either if a tag tries to foster itself or two or more tags try to foster each other in a loop. We mitigate the risk by preventing a tag from creating a child of itself (the parent still gets closed) and by checking and increasing the currentFixingCost so that a loop of multiple tags do not run indefinitely. The default tagLimit and nestingLimit also serve to prevent the loop from running indefinitely
at line 1134
protected bool
requireAncestor(Tag $tag)
Apply requireAncestor rules associated with given tag
at line 1171
protected void
addFosterTag(Tag $tag, Tag $fosterTag)
Create and add a copy of a tag as a child of a given tag
at line 1188
protected Tag
addMagicEndTag(Tag $startTag, int $tagPos, int $prio = 0)
Create and add an end tag for given start tag at given position
at line 1211
protected int
getMagicEndPos(int $tagPos)
Compute the position of a magic end tag, adjusted for whitespace
at line 1229
protected int[]
getMagicStartCoords(int $tagPos)
Compute the position and priority of a magic start tag, adjusted for whitespace
at line 1262
protected bool
isFollowedByClosingTag(Tag $tag)
Test whether given start tag is immediately followed by a closing tag
at line 1272
protected void
processTags()
Process all tags in the stack
at line 1317
protected void
processCurrentTag()
Process current tag
at line 1410
protected void
processStartTag(Tag $tag)
Process given start tag (including self-closing tags) at current position
at line 1530
protected void
processEndTag(Tag $tag)
Process given end tag at current position
at line 1694
protected void
popContext()
Update counters and replace current context with its parent context
at line 1709
protected void
pushContext(Tag $tag)
Update counters and replace current context with a new context based on given tag
If given tag is a self-closing tag, the context won't change
at line 1761
protected bool
tagIsAllowed(string $tagName)
Return whether given tag is allowed in current context
at line 1781
Tag
addStartTag(string $name, int $pos, int $len, int $prio = 0)
Add a start tag
at line 1795
Tag
addEndTag(string $name, int $pos, int $len, int $prio = 0)
Add an end tag
at line 1809
Tag
addSelfClosingTag(string $name, int $pos, int $len, int $prio = 0)
Add a self-closing tag
at line 1821
Tag
addBrTag(int $pos, int $prio = 0)
Add a 0-width "br" tag to force a line break at given position
at line 1834
Tag
addIgnoreTag(int $pos, int $len, int $prio = 0)
Add an "ignore" tag
at line 1848
Tag
addParagraphBreak(int $pos, int $prio = 0)
Add a paragraph break at given position
Uses a zero-width tag that is actually never output in the result
at line 1862
Tag
addCopyTag(Tag $tag, int $pos, int $len, int $prio = null)
Add a copy of given tag at given position and length
at line 1884
protected Tag
addTag(int $type, string $name, int $pos, int $len, int $prio)
Add a tag
at line 1928
protected bool
isInvalidTextSpan(int $pos, int $len)
Test whether given text span is outside text boundaries or an invalid UTF sequence
at line 1939
protected void
insertTag(Tag $tag)
Insert given tag in the tag stack
at line 1970
Tag
addTagPair(string $name, int $startPos, int $startLen, int $endPos, int $endLen, int $prio = 0)
Add a pair of tags
at line 1988
Tag
addVerbatim(int $pos, int $len, int $prio = 0)
Add a tag that represents a verbatim copy of the original text
at line 1998
protected void
sortTags()
Sort tags by position and precedence
at line 2025
protected string
getSortKey(Tag $tag, int $tagIndex = 0)
Generate a key for given tag that can be used to compare its position using lexical comparisons
Tags are sorted by position first, then by priority, then by whether they consume any text, then by length, and finally in order of their creation.
The stack's array is in reverse order. Therefore, tags that appear at the start of the text are at the end of the array.