Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

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

SCSSPHP

Copyright: 2012-2020 Leaf Corcoran
License: http://opensource.org/licenses/MIT MIT
File Size: 4097 lines (111 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)   X-Ref
Constructor

param: string      $sourceName
param: integer     $sourceIndex
param: string|null $encoding
param: Cache|null  $cache
param: bool        $cssOnly

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

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

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

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

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

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

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

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

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

param: string  $type
param: integer $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: integer $from
return: integer

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

param: integer $where

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

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

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

param: array $parsed
return: bool|array

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: boolean 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: boolean $eatWhitespace
return: boolean

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

param: string  $char
param: boolean $eatWhitespace
return: boolean

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

param: string  $what
param: integer $len
param: boolean $eatWhitespace
return: boolean

whitespace()   X-Ref
Match some whitespace

return: boolean

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

param: array $comment

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

param: array|null $statement
param: integer $pos

last()   X-Ref
Returns last child was appended

return: array|null

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

param: array $out
return: boolean

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

param: array $out
return: boolean

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

param: array $out
return: boolean

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

param: array $out
return: boolean

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

param: array $out
return: boolean

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

param: array $out
return: boolean

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: boolean|string $endChar
return: boolean

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

param: array $out
return: boolean

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: $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: boolean

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: boolean $flatten
return: boolean

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

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

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

param: array   $out
param: integer $s
param: string  $closingParen
param: array   $allowedTypes
return: boolean

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

param: array   $lhs
param: integer $minP
return: array

value(&$out)   X-Ref
Parse value

param: array $out
return: boolean

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

param: array $out
return: boolean

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

param: array $out
return: boolean

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

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

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

param: array $out
return: boolean

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

param: array $out
return: boolean

map(&$out)   X-Ref
Parse map

param: array $out
return: boolean

color(&$out)   X-Ref
Parse color

param: array $out
return: boolean

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

param: array $unit
return: boolean

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

param: array $out
return: boolean

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: boolean $restricted
return: boolean

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: boolean $rtrim
param: string $disallow
return: boolean

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

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

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

param: array $out
return: boolean

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

param: array $out
return: boolean

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

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

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

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

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|boolean $subSelector
return: boolean

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

param: array $out
return: boolean

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

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

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

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

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

param: string|array $placeholder
return: boolean

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

param: array $out
return: boolean

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

param: bool $eatWhitespace
return: boolean

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

param: array $value
return: array

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

param: array $selectors
return: string

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

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

param: integer $pos
return: array

saveEncoding()   X-Ref
Save internal encoding


restoreEncoding()   X-Ref
Restore internal encoding