MediaWiki
1.23.2
|
This is a state machine style parser with two internal stacks: More...
Public Member Functions | |
__construct ( $text) | |
Construct a new parser. More... | |
currentToken () | |
Get the current token. More... | |
dumpTokens () | |
Echo a reasonably readable representation of the tokenizer array. More... | |
edit ( $ops) | |
Edit the text. More... | |
endPath () | |
Internal function to update some things at the end of a path region. More... | |
endPathValue () | |
Mark the end of the value part of a path. More... | |
error ( $msg) | |
Generate a parse error. More... | |
expect ( $type) | |
Throws an error if the current token is not of the given type, and then advances to the next position. More... | |
findDeletionRegion ( $pathName) | |
Finds the source byte region which you would want to delete, if $pathName was to be deleted. More... | |
findFirstArrayElement ( $path) | |
Find the path name of first element in the array. More... | |
findLastArrayElement ( $path) | |
Find the path name of the last element in the array. More... | |
findValueRegion ( $pathName) | |
Find the byte region in the source corresponding to the value part. More... | |
firstToken () | |
Reset the parse position. More... | |
getIndent ( $pos, $key=false, $arrowPos=false) | |
Get the indent string which sits after a given start position. More... | |
getTokenAhead ( $offset) | |
Get the token $offset steps ahead of the current position. More... | |
getTypeName ( $type) | |
Get a readable name for the given token type. More... | |
getVars () | |
Get the variables defined in the text. More... | |
isAhead ( $type, $offset=0) | |
Looks ahead to see if the given type is the next token type, starting from the current position plus the given offset. More... | |
markArrow () | |
Mark the arrow separator in an associative array element. More... | |
markComma () | |
Mark the comma separator in an array element. More... | |
newTokenObj ( $internalToken) | |
Create a ConfEditorToken from an element of token_get_all() More... | |
nextPath ( $path) | |
Go to the next path on the same level. More... | |
nextToken () | |
Advance the current position and return the resulting next token. More... | |
parse () | |
Run the parser on the text. More... | |
parseScalar ( $str) | |
Parse a scalar value in PHP. More... | |
popPath () | |
Go down a path level, for example at the end of an array. More... | |
popState () | |
Pop a state from the state stack. More... | |
prevToken () | |
Get the previous token object. More... | |
pushPath ( $path) | |
Go up to a new path level, for example at the start of an array. More... | |
pushState ( $nextState, $stateAfterThat=null) | |
Push a state or two on to the state stack. More... | |
replaceSourceRegion ( $start, $end, $newText=false) | |
Replace the byte offset region of the source with $newText. More... | |
setVar (&$array, $path, $key, $value) | |
Set a value in an array, unless it's set already. More... | |
skipSpace () | |
Advances the current position past any whitespace or comments. More... | |
startPathValue () | |
Mark the start of the value part of a path. More... | |
validatePath ( $path) | |
Returns true if the user input path is valid. More... | |
Static Public Member Functions | |
static | test ( $text) |
Simple entry point for command-line testing. More... | |
Public Attributes | |
$byteNum | |
The current 0-based byte number. More... | |
$colNum | |
The current 1-based column number. More... | |
$currentToken | |
The current ConfEditorToken object. More... | |
$edits | |
Editor state. More... | |
$lineNum | |
The current 1-based line number. More... | |
$pathInfo | |
The elements of the top of the pathStack for every path encountered, indexed by slash-separated path. More... | |
$pathStack | |
The path stack is a stack of associative arrays with the following elements: name The name of top level of the path level The level (number of elements) of the path startByte The byte offset of the start of the path startToken The token offset of the start endByte The byte offset of thee endToken The token offset of the end, plus one valueStartToken The start token offset of the value part valueStartByte The start byte offset of the value part valueEndToken The end token offset of the value part, plus one valueEndByte The end byte offset of the value part, plus one nextArrayIndex The next numeric array index at this level hasComma True if the array element ends with a comma arrowByte The byte offset of the "=>", or false if there isn't one. More... | |
$pos | |
The current position in the token array. More... | |
$prevToken | |
The previous ConfEditorToken object. More... | |
$serial | |
Next serial number for whitespace placeholder paths (@extra-N) More... | |
$stateStack | |
The state machine stack. More... | |
$text | |
The text to parse. More... | |
$tokens | |
The token array from token_get_all() More... | |
Protected Member Functions | |
initParse () | |
Initialise a parse. More... | |
setPos ( $pos) | |
Set the parse position. More... | |
This is a state machine style parser with two internal stacks:
Reference grammar:
file = T_OPEN_TAG *statement statement = T_VARIABLE "=" expression ";" expression = array / scalar / T_VARIABLE array = T_ARRAY "(" [ element *( "," element ) [ "," ] ] ")" element = assoc-element / expression assoc-element = scalar T_DOUBLE_ARROW expression scalar = T_LNUMBER / T_DNUMBER / T_STRING / T_CONSTANT_ENCAPSED_STRING
Definition at line 38 of file ConfEditor.php.
ConfEditor::__construct | ( | $text | ) |
ConfEditor::currentToken | ( | ) |
Get the current token.
Definition at line 808 of file ConfEditor.php.
References $currentToken.
Referenced by expect(), nextToken(), parse(), setPos(), and skipSpace().
ConfEditor::dumpTokens | ( | ) |
Echo a reasonably readable representation of the tokenizer array.
Definition at line 1059 of file ConfEditor.php.
References $out, as, getTypeName(), and newTokenObj().
ConfEditor::edit | ( | $ops | ) |
Edit the text.
Returns the edited text.
array | $ops | of operations. |
Operations are given as an associative array, with members: type: One of delete, set, append or insert (required) path: The path to operate on (required) key: The array key to insert/append, with PHP quotes value: The value, with PHP quotes
delete Deletes an array element or statement with the specified path. e.g. array('type' => 'delete', 'path' => '$foo/bar/baz' ) is equivalent to the runtime PHP code: unset( $foo['bar']['baz'] );
set Sets the value of an array element. If the element doesn't exist, it is appended to the array. If it does exist, the value is set, with comments and indenting preserved.
append Appends a new element to the end of the array. Adds a trailing comma. e.g. array( 'type' => 'append', 'path', '$foo/bar', 'key' => 'baz', 'value' => "'x'" ) is like the PHP code: $foo['bar']['baz'] = 'x';
insert Insert a new element at the start of the array.
MWException |
Definition at line 165 of file ConfEditor.php.
References $e, $out, $path, $type, $value, array(), as, edits, findDeletionRegion(), findFirstArrayElement(), findLastArrayElement(), findValueRegion(), getIndent(), list, parse(), replaceSourceRegion(), and text.
ConfEditor::endPath | ( | ) |
Internal function to update some things at the end of a path region.
Do not call except from popPath() or nextPath().
Definition at line 902 of file ConfEditor.php.
References $byteNum, $pathInfo, $pos, and as.
Referenced by nextPath(), and popPath().
ConfEditor::endPathValue | ( | ) |
ConfEditor::error | ( | $msg | ) |
Generate a parse error.
Definition at line 1007 of file ConfEditor.php.
ConfEditor::expect | ( | $type | ) |
Throws an error if the current token is not of the given type, and then advances to the next position.
Definition at line 862 of file ConfEditor.php.
References $type, currentToken(), error(), getTypeName(), and nextToken().
Referenced by parse().
ConfEditor::findDeletionRegion | ( | $pathName | ) |
Finds the source byte region which you would want to delete, if $pathName was to be deleted.
Includes the leading spaces and tabs, the trailing line break, and any comments in between.
$pathName |
MWException |
Definition at line 414 of file ConfEditor.php.
References $count, $path, $pos, array(), firstToken(), getTokenAhead(), and nextToken().
Referenced by edit().
ConfEditor::findFirstArrayElement | ( | $path | ) |
Find the path name of first element in the array.
If the array is empty, this will return the @extra interstitial element. If the specified path is not found or is not an array, it will return false.
Definition at line 532 of file ConfEditor.php.
Referenced by edit().
ConfEditor::findLastArrayElement | ( | $path | ) |
Find the path name of the last element in the array.
If the array is empty, this will return the @extra interstitial element. If the specified path is not found or is not an array, it will return false.
Definition at line 494 of file ConfEditor.php.
Referenced by edit().
ConfEditor::findValueRegion | ( | $pathName | ) |
Find the byte region in the source corresponding to the value part.
This includes the quotes, but does not include the trailing comma or semicolon.
The end position is the past-the-end (end + 1) value as per convention.
$pathName |
MWException |
Definition at line 476 of file ConfEditor.php.
References $path, and array().
Referenced by edit().
ConfEditor::firstToken | ( | ) |
Reset the parse position.
Definition at line 795 of file ConfEditor.php.
References $currentToken, ConfEditorToken\newEnd(), prevToken(), and setPos().
Referenced by findDeletionRegion(), initParse(), and parse().
ConfEditor::getTokenAhead | ( | $offset | ) |
Get the token $offset steps ahead of the current position.
$offset may be negative, to get tokens behind the current position.
Definition at line 838 of file ConfEditor.php.
References $pos, ConfEditorToken\newEnd(), and newTokenObj().
Referenced by findDeletionRegion(), and isAhead().
ConfEditor::getTypeName | ( | $type | ) |
Get a readable name for the given token type.
Definition at line 1015 of file ConfEditor.php.
References $type.
Referenced by dumpTokens(), and expect().
ConfEditor::getVars | ( | ) |
|
protected |
Initialise a parse.
Definition at line 756 of file ConfEditor.php.
References array(), firstToken(), and text.
Referenced by parse().
ConfEditor::isAhead | ( | $type, | |
$offset = 0 |
|||
) |
Looks ahead to see if the given type is the next token type, starting from the current position plus the given offset.
Skips any intervening whitespace.
Definition at line 1029 of file ConfEditor.php.
References $type, and getTokenAhead().
Referenced by parse().
ConfEditor::markArrow | ( | ) |
Mark the arrow separator in an associative array element.
Definition at line 999 of file ConfEditor.php.
References $byteNum, and $path.
Referenced by parse().
ConfEditor::markComma | ( | ) |
Mark the comma separator in an array element.
Definition at line 991 of file ConfEditor.php.
References $path.
Referenced by parse().
ConfEditor::newTokenObj | ( | $internalToken | ) |
Create a ConfEditorToken from an element of token_get_all()
Definition at line 784 of file ConfEditor.php.
Referenced by dumpTokens(), getTokenAhead(), and setPos().
ConfEditor::nextPath | ( | $path | ) |
ConfEditor::nextToken | ( | ) |
Advance the current position and return the resulting next token.
Definition at line 815 of file ConfEditor.php.
References $currentToken, $text, currentToken(), prevToken(), and setPos().
Referenced by expect(), findDeletionRegion(), parse(), and skipSpace().
ConfEditor::parse | ( | ) |
Run the parser on the text.
Throws an exception if the string does not match our defined subset of PHP syntax.
Definition at line 580 of file ConfEditor.php.
References $text, currentToken(), endPathValue(), error(), expect(), firstToken(), initParse(), isAhead(), markArrow(), markComma(), nextPath(), nextToken(), parseScalar(), popPath(), popState(), pushPath(), pushState(), skipSpace(), startPathValue(), type, and validatePath().
ConfEditor::parseScalar | ( | $str | ) |
Parse a scalar value in PHP.
Definition at line 340 of file ConfEditor.php.
References array().
ConfEditor::popPath | ( | ) |
Go down a path level, for example at the end of an array.
Definition at line 937 of file ConfEditor.php.
References endPath().
Referenced by parse().
ConfEditor::popState | ( | ) |
Pop a state from the state stack.
Definition at line 885 of file ConfEditor.php.
Referenced by parse().
ConfEditor::prevToken | ( | ) |
Get the previous token object.
Definition at line 1052 of file ConfEditor.php.
References $prevToken.
Referenced by firstToken(), and nextToken().
ConfEditor::pushPath | ( | $path | ) |
Go up to a new path level, for example at the start of an array.
Definition at line 918 of file ConfEditor.php.
References $path, and array().
Referenced by parse().
ConfEditor::pushState | ( | $nextState, | |
$stateAfterThat = null |
|||
) |
Push a state or two on to the state stack.
Definition at line 874 of file ConfEditor.php.
Referenced by parse().
ConfEditor::replaceSourceRegion | ( | $start, | |
$end, | |||
$newText = false |
|||
) |
|
protected |
Set the parse position.
Do not call this except from firstToken() and nextToken(), there is more to update than just the position.
Definition at line 769 of file ConfEditor.php.
References $currentToken, $pos, currentToken(), ConfEditorToken\newEnd(), and newTokenObj().
Referenced by firstToken(), and nextToken().
ConfEditor::setVar | ( | & | $array, |
$path, | |||
$key, | |||
$value | |||
) |
Set a value in an array, unless it's set already.
For instance, setVar( $arr, 'foo/bar', 'baz', 3 ); will set $arr['foo']['bar']['baz'] = 3;
$array | array | |
string | $path | slash-delimited path |
$key | mixed Key | |
$value | mixed Value |
Definition at line 320 of file ConfEditor.php.
References $path, $value, array(), and as.
Referenced by getVars().
ConfEditor::skipSpace | ( | ) |
Advances the current position past any whitespace or comments.
Definition at line 850 of file ConfEditor.php.
References $currentToken, currentToken(), and nextToken().
Referenced by parse().
ConfEditor::startPathValue | ( | ) |
|
static |
Simple entry point for command-line testing.
$text | string |
Definition at line 111 of file ConfEditor.php.
ConfEditor::validatePath | ( | $path | ) |
Returns true if the user input path is valid.
This exists to allow "/" and "@" to be reserved for string path keys
Definition at line 894 of file ConfEditor.php.
References $path.
Referenced by parse().
ConfEditor::$byteNum |
The current 0-based byte number.
Definition at line 55 of file ConfEditor.php.
Referenced by endPath(), endPathValue(), markArrow(), and startPathValue().
ConfEditor::$colNum |
The current 1-based column number.
Definition at line 52 of file ConfEditor.php.
ConfEditor::$currentToken |
The current ConfEditorToken object.
Definition at line 58 of file ConfEditor.php.
Referenced by currentToken(), firstToken(), nextToken(), setPos(), and skipSpace().
ConfEditor::$edits |
Editor state.
This consists of the internal copy/insert operations which are applied to the source string to obtain the destination string.
Definition at line 102 of file ConfEditor.php.
ConfEditor::$lineNum |
The current 1-based line number.
Definition at line 49 of file ConfEditor.php.
ConfEditor::$pathInfo |
The elements of the top of the pathStack for every path encountered, indexed by slash-separated path.
Definition at line 91 of file ConfEditor.php.
Referenced by endPath().
ConfEditor::$pathStack |
The path stack is a stack of associative arrays with the following elements: name The name of top level of the path level The level (number of elements) of the path startByte The byte offset of the start of the path startToken The token offset of the start endByte The byte offset of thee endToken The token offset of the end, plus one valueStartToken The start token offset of the value part valueStartByte The start byte offset of the value part valueEndToken The end token offset of the value part, plus one valueEndByte The end byte offset of the value part, plus one nextArrayIndex The next numeric array index at this level hasComma True if the array element ends with a comma arrowByte The byte offset of the "=>", or false if there isn't one.
Definition at line 85 of file ConfEditor.php.
ConfEditor::$pos |
The current position in the token array.
Definition at line 46 of file ConfEditor.php.
Referenced by endPath(), endPathValue(), findDeletionRegion(), getIndent(), getTokenAhead(), setPos(), and startPathValue().
ConfEditor::$prevToken |
The previous ConfEditorToken object.
Definition at line 61 of file ConfEditor.php.
Referenced by prevToken().
ConfEditor::$serial |
Next serial number for whitespace placeholder paths (@extra-N)
Definition at line 96 of file ConfEditor.php.
ConfEditor::$stateStack |
The state machine stack.
This is an array of strings where the topmost element will be popped off and become the next parser state.
Definition at line 67 of file ConfEditor.php.
ConfEditor::$text |
The text to parse.
Definition at line 40 of file ConfEditor.php.
Referenced by __construct(), nextToken(), parse(), and test().
ConfEditor::$tokens |
The token array from token_get_all()
Definition at line 43 of file ConfEditor.php.