Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401]

SCSSPHP

Copyright: 2012-2020 Leaf Corcoran
License: http://opensource.org/licenses/MIT MIT
File Size: 4205 lines (115 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: Parser  - X-Ref

Parser

__construct($sourceName, $sourceIndex = 0, $encoding = 'utf-8', Cache $cache = null, $cssOnly = false, LoggerInterface $logger = null)   X-Ref
Constructor

param: string|null          $sourceName
param: int                  $sourceIndex
param: string|null          $encoding
param: Cache|null           $cache
param: bool                 $cssOnly
param: LoggerInterface|null $logger

getSourceName()   X-Ref
Get source file name

return: string

throwParseError($msg = 'parse error')   X-Ref
Throw parser error

param: string $msg

parseError($msg = 'parse error')   X-Ref
Creates a parser error

param: string $msg
return: ParserException

parse($buffer)   X-Ref
Parser buffer

param: string $buffer
return: Block

parseValue($buffer, &$out)   X-Ref
Parse a value or value list

param: string       $buffer
param: string|array $out
return: bool

parseSelector($buffer, &$out, $shouldValidate = true)   X-Ref
Parse a selector or selector list

param: string       $buffer
param: string|array $out
param: bool         $shouldValidate
return: bool

parseMediaQueryList($buffer, &$out)   X-Ref
Parse a media Query

param: string $buffer
param: array  $out
return: bool

parseChunk()   X-Ref
Parse a single chunk off the head of the buffer and append it to the
current parse environment.

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: bool

pushBlock($selectors, $pos = 0)   X-Ref
Push block onto parse tree

param: array|null $selectors
param: int        $pos
return: Block

registerPushedBlock(Block $b, $pos)   X-Ref

param: Block $b
param: int   $pos
return: void

pushSpecialBlock($type, $pos)   X-Ref
Push special (named) block onto parse tree

param: string  $type
param: int     $pos
return: Block

popBlock()   X-Ref
Pop scope and return last block

return: Block

peek($regex, &$out, $from = null)   X-Ref
Peek input stream

param: string $regex
param: array  $out
param: int    $from
return: int

seek($where)   X-Ref
Seek to position in input stream (or return current position in input stream)

param: int $where
return: void

assertPlainCssValid($parsed, $startPos = null)   X-Ref
Assert a parsed part is plain CSS Valid

param: array|false $parsed
param: int         $startPos
return: array

isPlainCssValidElement($parsed, $allowExpression = false)   X-Ref
Check a parsed element is plain CSS Valid

param: array $parsed
param: bool  $allowExpression
return: array|false

matchString(&$m, $delim)   X-Ref
Match string looking for either ending delim, escape, or string interpolation

{@internal This is a workaround for preg_match's 250K string match limit. }}

param: array  $m     Matches (passed by reference)
param: string $delim Delimiter
return: bool True if match; false otherwise

match($regex, &$out, $eatWhitespace = null)   X-Ref
Try to match something on head of buffer

param: string $regex
param: array  $out
param: bool   $eatWhitespace
return: bool

matchChar($char, $eatWhitespace = null)   X-Ref
Match a single string

param: string $char
param: bool   $eatWhitespace
return: bool

literal($what, $len, $eatWhitespace = null)   X-Ref
Match literal string

param: string $what
param: int    $len
param: bool   $eatWhitespace
return: bool

whitespace()   X-Ref
Match some whitespace

return: bool

appendComment($comment)   X-Ref
Append comment to current block

param: array $comment
return: void

append($statement, $pos = null)   X-Ref
Append statement to current block

param: array|null $statement
param: int        $pos
return: void

last()   X-Ref
Returns last child was appended

return: array|null

mediaQueryList(&$out)   X-Ref
Parse media query list

param: array $out
return: bool

mediaQuery(&$out)   X-Ref
Parse media query

param: array $out
return: bool

supportsQuery(&$out)   X-Ref
Parse supports query

param: array $out
return: bool

mediaExpression(&$out)   X-Ref
Parse media expression

param: array $out
return: bool

argValues(&$out)   X-Ref
Parse argument values

param: array $out
return: bool

argValue(&$out)   X-Ref
Parse argument value

param: array $out
return: bool

isKnownGenericDirective($directiveName)   X-Ref
Check if a generic directive is known to be able to allow almost any syntax or not

param: mixed $directiveName
return: bool

directiveValue(&$out, $endChar = false)   X-Ref
Parse directive value list that considers $vars as keyword

param: array        $out
param: string|false $endChar
return: bool

valueList(&$out)   X-Ref
Parse comma separated value list

param: array $out
return: bool

functionCallArgumentsList(&$out, $mandatoryEnclos = true, $charAfter = null, $eatWhiteSp = null)   X-Ref
Parse a function call, where externals () are part of the call
and not of the value list

param: array       $out
param: bool        $mandatoryEnclos
param: null|string $charAfter
param: null|bool   $eatWhiteSp
return: bool

spaceList(&$out)   X-Ref
Parse space separated value list

param: array $out
return: bool

genericList(&$out, $parseItem, $delim = '', $flatten = true)   X-Ref
Parse generic list

param: array  $out
param: string $parseItem The name of the method used to parse items
param: string $delim
param: bool   $flatten
return: bool

expression(&$out, $listOnly = false, $lookForExp = true)   X-Ref
Parse expression

param: array $out
param: bool  $listOnly
param: bool  $lookForExp
return: bool

enclosedExpression(&$out, $s, $closingParen = ')   X-Ref
Parse expression specifically checking for lists in parenthesis or brackets

param: array    $out
param: int      $s
param: string   $closingParen
param: string[] $allowedTypes
return: bool

expHelper($lhs, $minP)   X-Ref
Parse left-hand side of subexpression

param: array $lhs
param: int   $minP
return: array

value(&$out)   X-Ref
Parse value

param: array $out
return: bool

parenValue(&$out)   X-Ref
Parse parenthesized value

param: array $out
return: bool

progid(&$out)   X-Ref
Parse "progid:"

param: array $out
return: bool

func($name, &$func)   X-Ref
Parse function call

param: string $name
param: array  $func
return: bool

argumentList(&$out)   X-Ref
Parse function call argument list

param: array $out
return: bool

argumentDef(&$out)   X-Ref
Parse mixin/function definition  argument list

param: array $out
return: bool

map(&$out)   X-Ref
Parse map

param: array $out
return: bool

color(&$out)   X-Ref
Parse color

param: array $out
return: bool

unit(&$unit)   X-Ref
Parse number with unit

param: array $unit
return: bool

string(&$out, $keepDelimWithInterpolation = false)   X-Ref
Parse string

param: array $out
param: bool  $keepDelimWithInterpolation
return: bool

matchEscapeCharacter(&$out, $inKeywords = false)   X-Ref

param: string $out
param: bool   $inKeywords
return: bool

mixedKeyword(&$out, $restricted = false)   X-Ref
Parse keyword or interpolation

param: array $out
param: bool  $restricted
return: bool

openString($end, &$out, $nestOpen = null, $nestClose = null, $rtrim = true, $disallow = null)   X-Ref
Parse an unbounded string stopped by $end

param: string $end
param: array  $out
param: string $nestOpen
param: string $nestClose
param: bool   $rtrim
param: string $disallow
return: bool

interpolation(&$out, $lookWhite = true)   X-Ref
Parser interpolation

param: string|array $out
param: bool         $lookWhite save information about whitespace before and after
return: bool

propertyName(&$out)   X-Ref
Parse property name (as an array of parts or a string)

param: array $out
return: bool

customProperty(&$out)   X-Ref
Parse custom property name (as an array of parts or a string)

param: array $out
return: bool

selectors(&$out, $subSelector = false)   X-Ref
Parse comma separated selector list

param: array $out
param: string|bool $subSelector
return: bool

selector(&$out, $subSelector = false)   X-Ref
Parse whitespace separated selector list

param: array          $out
param: string|bool $subSelector
return: bool

matchEscapeCharacterInSelector(&$out, $keepEscapedNumber = false)   X-Ref
parsing escaped chars in selectors:
- escaped single chars are kept escaped in the selector but in a normalized form
(if not in 0-9a-f range as this would be ambigous)
- other escaped sequences (multibyte chars or 0-9a-f) are kept in their initial escaped form,
normalized to lowercase

TODO: this is a fallback solution. Ideally escaped chars in selectors should be encoded as the genuine chars,
and escaping added when printing in the Compiler, where/if it's mandatory
- but this require a better formal selector representation instead of the array we have now

param: string $out
param: bool   $keepEscapedNumber
return: bool

selectorSingle(&$out, $subSelector = false)   X-Ref
Parse the parts that make up a selector

{@internal
div[yes=no]#something.hello.world:nth-child(-2n+1)%placeholder
}}

param: array          $out
param: string|bool $subSelector
return: bool

variable(&$out)   X-Ref
Parse a variable

param: array $out
return: bool

keyword(&$word, $eatWhitespace = null, $inSelector = false)   X-Ref
Parse a keyword

param: string $word
param: bool   $eatWhitespace
param: bool   $inSelector
return: bool

restrictedKeyword(&$word, $eatWhitespace = null, $inSelector = false)   X-Ref
Parse a keyword that should not start with a number

param: string $word
param: bool   $eatWhitespace
param: bool   $inSelector
return: bool

placeholder(&$placeholder)   X-Ref
Parse a placeholder

param: string|array $placeholder
return: bool

url(&$out)   X-Ref
Parse a url

param: array $out
return: bool

end($eatWhitespace = null)   X-Ref
Consume an end of statement delimiter

param: bool $eatWhitespace
return: bool

stripAssignmentFlags(&$value)   X-Ref
Strip assignment flag from the list

param: array $value
return: string[]

stripOptionalFlag(&$selectors)   X-Ref
Strip optional flag from selector list

param: array $selectors
return: bool

flattenList($value)   X-Ref
Turn list of length 1 into value type

param: array $value
return: array

pregQuote($what)   X-Ref
Quote regular expression

param: string $what
return: string

extractLineNumbers($buffer)   X-Ref
Extract line numbers from buffer

param: string $buffer
return: void

getSourcePosition($pos)   X-Ref
Get source line number and column (given character position in the buffer)

param: int $pos
return: array

saveEncoding()   X-Ref
Save internal encoding of mbstring

When mbstring.func_overload is used to replace the standard PHP string functions,
this method configures the internal encoding to a single-byte one so that the
behavior matches the normal behavior of PHP string functions while using the parser.
The existing internal encoding is saved and will be restored when calling {@see restoreEncoding}.

If mbstring.func_overload is not used (or does not override string functions), this method is a no-op.

return: void

restoreEncoding()   X-Ref
Restore internal encoding

return: void