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
No description
No description
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 179
array
__serialize()
No description
at line 189
void
__unserialize(array $data)
No description
at line 204
protected void
reset(string $text)
Reset the parser for a new parsing
at line 254
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 278
void
disableTag(string $tagName)
Disable a tag
at line 289
void
enableTag(string $tagName)
Enable a tag
at line 302
Logger
getLogger()
Get this parser's Logger instance
at line 319
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 330
string
parse(string $text)
Parse a text
at line 367
void
setTagLimit(string $tagName, int $tagLimit)
Change a tag's tagLimit
NOTE: the default tagLimit should generally be set during configuration instead
at line 381
void
setNestingLimit(string $tagName, int $nestingLimit)
Change a tag's nestingLimit
NOTE: the default nestingLimit should generally be set during configuration instead
at line 395
protected void
finalizeOutput()
Finalize the output by appending the rest of the unprocessed text and create the root node
at line 438
protected void
outputTag(Tag $tag)
Append a tag to the output
at line 552
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 710
protected void
outputBrTag(Tag $tag)
Output a linebreak tag
at line 722
protected void
outputIgnoreTag(Tag $tag)
Output an ignore tag
at line 745
protected void
outputParagraphStart(int $maxPos)
Start a paragraph between current position and given position, if applicable
at line 770
protected void
outputParagraphEnd()
Close current paragraph at current position if applicable
at line 788
protected void
outputVerbatim(Tag $tag)
Output the content of a verbatim tag
at line 802
protected void
outputWhitespace(int $maxPos)
Skip as much whitespace after current position as possible
at line 826
void
disablePlugin(string $pluginName)
Disable a plugin
at line 846
void
enablePlugin(string $pluginName)
Enable a plugin
at line 860
protected void
executePluginParser(string $pluginName)
Execute given plugin
at line 887
protected void
executePluginParsers()
Execute all the plugins
at line 905
protected array
getMatches(string $regexp, int $limit)
Execute given regexp and returns as many matches as given limit
at line 922
protected callable
getPluginParser(string $pluginName)
Get the cached callback for given plugin's parser
at line 951
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 980
protected bool
closeAncestor(Tag $tag)
Apply closeAncestor rules associated with given tag
at line 1021
protected bool
closeParent(Tag $tag)
Apply closeParent rules associated with given tag
at line 1057
protected void
createChild(Tag $tag)
Apply the createChild rules associated with given tag
at line 1084
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 1127
protected bool
requireAncestor(Tag $tag)
Apply requireAncestor rules associated with given tag
at line 1164
protected void
addFosterTag(Tag $tag, Tag $fosterTag)
Create and add a copy of a tag as a child of a given tag
at line 1181
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 1204
protected int
getMagicEndPos(int $tagPos)
Compute the position of a magic end tag, adjusted for whitespace
at line 1222
protected int[]
getMagicStartCoords(int $tagPos)
Compute the position and priority of a magic start tag, adjusted for whitespace
at line 1255
protected bool
isFollowedByClosingTag(Tag $tag)
Test whether given start tag is immediately followed by a closing tag
at line 1265
protected void
processTags()
Process all tags in the stack
at line 1310
protected void
processCurrentTag()
Process current tag
at line 1403
protected void
processStartTag(Tag $tag)
Process given start tag (including self-closing tags) at current position
at line 1523
protected void
processEndTag(Tag $tag)
Process given end tag at current position
at line 1687
protected void
popContext()
Update counters and replace current context with its parent context
at line 1702
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 1754
protected bool
tagIsAllowed(string $tagName)
Return whether given tag is allowed in current context
at line 1774
Tag
addStartTag(string $name, int $pos, int $len, int $prio = 0)
Add a start tag
at line 1788
Tag
addEndTag(string $name, int $pos, int $len, int $prio = 0)
Add an end tag
at line 1802
Tag
addSelfClosingTag(string $name, int $pos, int $len, int $prio = 0)
Add a self-closing tag
at line 1814
Tag
addBrTag(int $pos, int $prio = 0)
Add a 0-width "br" tag to force a line break at given position
at line 1827
Tag
addIgnoreTag(int $pos, int $len, int $prio = 0)
Add an "ignore" tag
at line 1841
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 1855
Tag
addCopyTag(Tag $tag, int $pos, int $len, int $prio = null)
Add a copy of given tag at given position and length
at line 1877
protected Tag
addTag(int $type, string $name, int $pos, int $len, int $prio)
Add a tag
at line 1921
protected bool
isInvalidTextSpan(int $pos, int $len)
Test whether given text span is outside text boundaries or an invalid UTF sequence
at line 1932
protected void
insertTag(Tag $tag)
Insert given tag in the tag stack
at line 1963
Tag
addTagPair(string $name, int $startPos, int $startLen, int $endPos, int $endLen, int $prio = 0)
Add a pair of tags
at line 1981
Tag
addVerbatim(int $pos, int $len, int $prio = 0)
Add a tag that represents a verbatim copy of the original text
at line 1991
protected void
sortTags()
Sort tags by position and precedence
at line 2018
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.