Parser
in package
Parser
Tags
Table of Contents
- SOURCE_COLUMN = -3
- SOURCE_INDEX = -1
- SOURCE_LINE = -2
- $cache : mixed
- $commentPattern : mixed
- $operatorPattern : mixed
- $precedence : array<string|int, mixed>
- $whitePattern : mixed
- $buffer : mixed
- $charset : mixed
- $commentsSeen : mixed
- $count : mixed
- $eatWhiteDefault : mixed
- $encoding : mixed
- $env : mixed
- $inParens : mixed
- $patternModifiers : mixed
- $sourceIndex : mixed
- $sourceName : mixed
- $sourcePositions : mixed
- $utf8 : mixed
- __construct() : mixed
- Constructor
- getSourceName() : string
- Get source file name
- parse() : Block
- Parser buffer
- parseSelector() : bool
- Parse a selector or selector list
- parseValue() : bool
- Parse a value or value list
- throwParseError() : mixed
- Throw parser error
- append() : mixed
- Append statement to current block
- appendComment() : mixed
- Append comment to current block
- argumentDef() : bool
- Parse mixin/function definition argument list
- argumentList() : bool
- Parse function call argument list
- argValue() : bool
- Parse argument value
- argValues() : bool
- Parse argument values
- color() : bool
- Parse color
- end() : bool
- Consume an end of statement delimiter
- expHelper() : array<string|int, mixed>
- Parse left-hand side of subexpression
- expression() : bool
- Parse expression
- flattenList() : array<string|int, mixed>
- Turn list of length 1 into value type
- func() : bool
- Parse function call
- genericList() : bool
- Parse generic list
- interpolation() : bool
- Parser interpolation
- keyword() : bool
- Parse a keyword
- last() : array<string|int, mixed>|null
- Returns last child was appended
- literal() : bool
- Match literal string
- map() : bool
- Parse map
- match() : bool
- Try to match something on head of buffer
- matchChar() : bool
- Match a single string
- matchString() : bool
- Match string looking for either ending delim, escape, or string interpolation
- mediaExpression() : bool
- Parse media expression
- mediaQuery() : bool
- Parse media query
- mediaQueryList() : bool
- Parse media query list
- mixedKeyword() : bool
- Parse keyword or interpolation
- openString() : bool
- Parse an unbounded string stopped by $end
- parenExpression() : bool
- Parse expression specifically checking for lists in parenthesis or brackets
- parenValue() : bool
- Parse parenthesized value
- parseChunk() : bool
- Parse a single chunk off the head of the buffer and append it to the current parse environment.
- peek() : int
- Peek input stream
- placeholder() : bool
- Parse a placeholder
- popBlock() : Block
- Pop scope and return last block
- progid() : bool
- Parse "progid:"
- propertyName() : bool
- Parse property name (as an array of parts or a string)
- pushBlock() : Block
- Push block onto parse tree
- pushSpecialBlock() : Block
- Push special (named) block onto parse tree
- seek() : mixed
- Seek to position in input stream (or return current position in input stream)
- selector() : bool
- Parse whitespace separated selector list
- selectors() : bool
- Parse comma separated selector list
- selectorSingle() : bool
- Parse the parts that make up a selector
- show() : mixed
- spaceList() : bool
- Parse space separated value list
- string() : bool
- Parse string
- stripAssignmentFlags() : array<string|int, mixed>
- Strip assignment flag from the list
- stripOptionalFlag() : string
- Strip optional flag from selector list
- to() : mixed
- unit() : bool
- Parse number with unit
- url() : bool
- Parse a url
- value() : bool
- Parse value
- valueList() : bool
- Parse comma separated value list
- variable() : bool
- Parse a variable
- whitespace() : bool
- Match some whitespace
- extractLineNumbers() : mixed
- Extract line numbers from buffer
- getSourcePosition() : array<string|int, mixed>
- Get source line number and column (given character position in the buffer)
- pregQuote() : string
- Quote regular expression
- restoreEncoding() : mixed
- Restore internal encoding
- saveEncoding() : mixed
- Save internal encoding
Constants
SOURCE_COLUMN
public
mixed
SOURCE_COLUMN
= -3
SOURCE_INDEX
public
mixed
SOURCE_INDEX
= -1
SOURCE_LINE
public
mixed
SOURCE_LINE
= -2
Properties
$cache
protected
mixed
$cache
$commentPattern
protected
static mixed
$commentPattern
$operatorPattern
protected
static mixed
$operatorPattern
$precedence
protected
static array<string|int, mixed>
$precedence
= ['=' => 0, 'or' => 1, 'and' => 2, '==' => 3, '!=' => 3, '<=>' => 3, '<=' => 4, '>=' => 4, '<' => 4, '>' => 4, '+' => 5, '-' => 5, '*' => 6, '/' => 6, '%' => 6]
$whitePattern
protected
static mixed
$whitePattern
$buffer
private
mixed
$buffer
$charset
private
mixed
$charset
$commentsSeen
private
mixed
$commentsSeen
$count
private
mixed
$count
$eatWhiteDefault
private
mixed
$eatWhiteDefault
$encoding
private
mixed
$encoding
$env
private
mixed
$env
$inParens
private
mixed
$inParens
$patternModifiers
private
mixed
$patternModifiers
$sourceIndex
private
mixed
$sourceIndex
$sourceName
private
mixed
$sourceName
$sourcePositions
private
mixed
$sourcePositions
$utf8
private
mixed
$utf8
Methods
__construct()
Constructor
public
__construct(string $sourceName, int $sourceIndex[, string $encoding = 'utf-8' ][, Cache $cache = null ]) : mixed
Parameters
- $sourceName : string
- $sourceIndex : int
- $encoding : string = 'utf-8'
- $cache : Cache = null
Return values
mixed —getSourceName()
Get source file name
public
getSourceName() : string
Return values
string —parse()
Parser buffer
public
parse(string $buffer) : Block
Parameters
- $buffer : string
Return values
Block —parseSelector()
Parse a selector or selector list
public
parseSelector(string $buffer, string &$out) : bool
Parameters
- $buffer : string
- $out : string
Return values
bool —parseValue()
Parse a value or value list
public
parseValue(string $buffer, string &$out) : bool
Parameters
- $buffer : string
- $out : string
Return values
bool —throwParseError()
Throw parser error
public
throwParseError([string $msg = 'parse error' ]) : mixed
Parameters
- $msg : string = 'parse error'
Tags
Return values
mixed —append()
Append statement to current block
protected
append(array<string|int, mixed> $statement[, int $pos = null ]) : mixed
Parameters
- $statement : array<string|int, mixed>
- $pos : int = null
Return values
mixed —appendComment()
Append comment to current block
protected
appendComment(array<string|int, mixed> $comment) : mixed
Parameters
- $comment : array<string|int, mixed>
Return values
mixed —argumentDef()
Parse mixin/function definition argument list
protected
argumentDef(array<string|int, mixed> &$out) : bool
Parameters
- $out : array<string|int, mixed>
Return values
bool —argumentList()
Parse function call argument list
protected
argumentList(array<string|int, mixed> &$out) : bool
Parameters
- $out : array<string|int, mixed>
Return values
bool —argValue()
Parse argument value
protected
argValue(array<string|int, mixed> &$out) : bool
Parameters
- $out : array<string|int, mixed>
Return values
bool —argValues()
Parse argument values
protected
argValues(array<string|int, mixed> &$out) : bool
Parameters
- $out : array<string|int, mixed>
Return values
bool —color()
Parse color
protected
color(array<string|int, mixed> &$out) : bool
Parameters
- $out : array<string|int, mixed>
Return values
bool —end()
Consume an end of statement delimiter
protected
end() : bool
Return values
bool —expHelper()
Parse left-hand side of subexpression
protected
expHelper(array<string|int, mixed> $lhs, int $minP) : array<string|int, mixed>
Parameters
- $lhs : array<string|int, mixed>
- $minP : int
Return values
array<string|int, mixed> —expression()
Parse expression
protected
expression(array<string|int, mixed> &$out) : bool
Parameters
- $out : array<string|int, mixed>
Return values
bool —flattenList()
Turn list of length 1 into value type
protected
flattenList(array<string|int, mixed> $value) : array<string|int, mixed>
Parameters
- $value : array<string|int, mixed>
Return values
array<string|int, mixed> —func()
Parse function call
protected
func(string $name, array<string|int, mixed> &$func) : bool
Parameters
- $name : string
- $func : array<string|int, mixed>
Return values
bool —genericList()
Parse generic list
protected
genericList(array<string|int, mixed> &$out, callable $parseItem[, string $delim = '' ][, bool $flatten = true ]) : bool
Parameters
- $out : array<string|int, mixed>
- $parseItem : callable
- $delim : string = ''
- $flatten : bool = true
Return values
bool —interpolation()
Parser interpolation
protected
interpolation(array<string|int, mixed> &$out[, bool $lookWhite = true ]) : bool
Parameters
- $out : array<string|int, mixed>
- $lookWhite : bool = true
-
save information about whitespace before and after
Return values
bool —keyword()
Parse a keyword
protected
keyword(string &$word[, bool $eatWhitespace = null ]) : bool
Parameters
- $word : string
- $eatWhitespace : bool = null
Return values
bool —last()
Returns last child was appended
protected
last() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|null —literal()
Match literal string
protected
literal(string $what, int $len[, bool $eatWhitespace = null ]) : bool
Parameters
- $what : string
- $len : int
- $eatWhitespace : bool = null
Return values
bool —map()
Parse map
protected
map(array<string|int, mixed> &$out) : bool
Parameters
- $out : array<string|int, mixed>
Return values
bool —match()
Try to match something on head of buffer
protected
match(string $regex, array<string|int, mixed> &$out[, bool $eatWhitespace = null ]) : bool
Parameters
- $regex : string
- $out : array<string|int, mixed>
- $eatWhitespace : bool = null
Return values
bool —matchChar()
Match a single string
protected
matchChar(string $char[, bool $eatWhitespace = null ]) : bool
Parameters
- $char : string
- $eatWhitespace : bool = null
Return values
bool —matchString()
Match string looking for either ending delim, escape, or string interpolation
protected
matchString(array<string|int, mixed> &$m, string $delim) : bool
}
Parameters
- $m : array<string|int, mixed>
-
Matches (passed by reference)
- $delim : string
-
Delimeter
Return values
bool —True if match; false otherwise
mediaExpression()
Parse media expression
protected
mediaExpression(array<string|int, mixed> &$out) : bool
Parameters
- $out : array<string|int, mixed>
Return values
bool —mediaQuery()
Parse media query
protected
mediaQuery(array<string|int, mixed> &$out) : bool
Parameters
- $out : array<string|int, mixed>
Return values
bool —mediaQueryList()
Parse media query list
protected
mediaQueryList(array<string|int, mixed> &$out) : bool
Parameters
- $out : array<string|int, mixed>
Return values
bool —mixedKeyword()
Parse keyword or interpolation
protected
mixedKeyword(array<string|int, mixed> &$out) : bool
Parameters
- $out : array<string|int, mixed>
Return values
bool —openString()
Parse an unbounded string stopped by $end
protected
openString(string $end, array<string|int, mixed> &$out[, string $nestingOpen = null ]) : bool
Parameters
- $end : string
- $out : array<string|int, mixed>
- $nestingOpen : string = null
Return values
bool —parenExpression()
Parse expression specifically checking for lists in parenthesis or brackets
protected
parenExpression(array<string|int, mixed> &$out, int $s[, string $closingParen = ")" ][, array<string|int, mixed> $allowedTypes = [Type::T_LIST, Type::T_MAP] ]) : bool
Parameters
- $out : array<string|int, mixed>
- $s : int
- $closingParen : string = ")"
- $allowedTypes : array<string|int, mixed> = [Type::T_LIST, Type::T_MAP]
Return values
bool —parenValue()
Parse parenthesized value
protected
parenValue(array<string|int, mixed> &$out) : bool
Parameters
- $out : array<string|int, mixed>
Return values
bool —parseChunk()
Parse a single chunk off the head of the buffer and append it to the current parse environment.
protected
parseChunk() : bool
Returns false when the buffer is empty, or when there is an error.
This function is called repeatedly until the entire document is parsed.
This parser is most similar to a recursive descent parser. Single functions represent discrete grammatical rules for the language, and they are able to capture the text that represents those rules.
Consider the function Compiler::keyword(). (All parse functions are structured the same.)
The function takes a single reference argument. When calling the function it will attempt to match a keyword on the head of the buffer. If it is successful, it will place the keyword in the referenced argument, advance the position in the buffer, and return true. If it fails then it won't advance the buffer and it will return false.
All of these parse functions are powered by Compiler::match(), which behaves the same way, but takes a literal regular expression. Sometimes it is more convenient to use match instead of creating a new function.
Because of the format of the functions, to parse an entire string of grammatical rules, you can chain them together using &&.
But, if some of the rules in the chain succeed before one fails, then the buffer position will be left at an invalid state. In order to avoid this, Compiler::seek() is used to remember and set buffer positions.
Before parsing a chain, use $s = $this->count to remember the current position into $s. Then if a chain fails, use $this->seek($s) to go back where we started.
Return values
bool —peek()
Peek input stream
protected
peek(string $regex, array<string|int, mixed> &$out[, int $from = null ]) : int
Parameters
- $regex : string
- $out : array<string|int, mixed>
- $from : int = null
Return values
int —placeholder()
Parse a placeholder
protected
placeholder(string &$placeholder) : bool
Parameters
- $placeholder : string
Return values
bool —popBlock()
Pop scope and return last block
protected
popBlock() : Block
Tags
Return values
Block —progid()
Parse "progid:"
protected
progid(array<string|int, mixed> &$out) : bool
Parameters
- $out : array<string|int, mixed>
Return values
bool —propertyName()
Parse property name (as an array of parts or a string)
protected
propertyName(array<string|int, mixed> &$out) : bool
Parameters
- $out : array<string|int, mixed>
Return values
bool —pushBlock()
Push block onto parse tree
protected
pushBlock(array<string|int, mixed> $selectors, int $pos) : Block
Parameters
- $selectors : array<string|int, mixed>
- $pos : int
Return values
Block —pushSpecialBlock()
Push special (named) block onto parse tree
protected
pushSpecialBlock(string $type, int $pos) : Block
Parameters
- $type : string
- $pos : int
Return values
Block —seek()
Seek to position in input stream (or return current position in input stream)
protected
seek(int $where) : mixed
Parameters
- $where : int
Return values
mixed —selector()
Parse whitespace separated selector list
protected
selector(array<string|int, mixed> &$out[, mixed $subSelector = false ]) : bool
Parameters
- $out : array<string|int, mixed>
- $subSelector : mixed = false
Return values
bool —selectors()
Parse comma separated selector list
protected
selectors(array<string|int, mixed> &$out[, mixed $subSelector = false ]) : bool
Parameters
- $out : array<string|int, mixed>
- $subSelector : mixed = false
Return values
bool —selectorSingle()
Parse the parts that make up a selector
protected
selectorSingle(array<string|int, mixed> &$out[, mixed $subSelector = false ]) : bool
}
Parameters
- $out : array<string|int, mixed>
- $subSelector : mixed = false
Return values
bool —show()
protected
show() : mixed
Tags
Return values
mixed —spaceList()
Parse space separated value list
protected
spaceList(array<string|int, mixed> &$out) : bool
Parameters
- $out : array<string|int, mixed>
Return values
bool —string()
Parse string
protected
string(array<string|int, mixed> &$out) : bool
Parameters
- $out : array<string|int, mixed>
Return values
bool —stripAssignmentFlags()
Strip assignment flag from the list
protected
stripAssignmentFlags(array<string|int, mixed> &$value) : array<string|int, mixed>
Parameters
- $value : array<string|int, mixed>
Return values
array<string|int, mixed> —stripOptionalFlag()
Strip optional flag from selector list
protected
stripOptionalFlag(array<string|int, mixed> &$selectors) : string
Parameters
- $selectors : array<string|int, mixed>
Return values
string —to()
protected
to(mixed $what, mixed &$out[, mixed $until = false ][, mixed $allowNewline = false ]) : mixed
Parameters
- $what : mixed
- $out : mixed
- $until : mixed = false
- $allowNewline : mixed = false
Tags
Return values
mixed —unit()
Parse number with unit
protected
unit(array<string|int, mixed> &$unit) : bool
Parameters
- $unit : array<string|int, mixed>
Return values
bool —url()
Parse a url
protected
url(array<string|int, mixed> &$out) : bool
Parameters
- $out : array<string|int, mixed>
Return values
bool —value()
Parse value
protected
value(array<string|int, mixed> &$out) : bool
Parameters
- $out : array<string|int, mixed>
Return values
bool —valueList()
Parse comma separated value list
protected
valueList(array<string|int, mixed> &$out) : bool
Parameters
- $out : array<string|int, mixed>
Return values
bool —variable()
Parse a variable
protected
variable(array<string|int, mixed> &$out) : bool
Parameters
- $out : array<string|int, mixed>
Return values
bool —whitespace()
Match some whitespace
protected
whitespace() : bool
Return values
bool —extractLineNumbers()
Extract line numbers from buffer
private
extractLineNumbers(string $buffer) : mixed
Parameters
- $buffer : string
Return values
mixed —getSourcePosition()
Get source line number and column (given character position in the buffer)
private
getSourcePosition(int $pos) : array<string|int, mixed>
Parameters
- $pos : int
Return values
array<string|int, mixed> —pregQuote()
Quote regular expression
private
pregQuote(string $what) : string
Parameters
- $what : string
Return values
string —restoreEncoding()
Restore internal encoding
private
restoreEncoding() : mixed
Return values
mixed —saveEncoding()
Save internal encoding
private
saveEncoding() : mixed