Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

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

SCSSPHP

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

Defines 1 class

Parser:: (66 methods):
  __construct()
  getSourceName()
  throwParseError()
  parse()
  parseValue()
  parseSelector()
  parseMediaQueryList()
  parseChunk()
  pushBlock()
  pushSpecialBlock()
  popBlock()
  peek()
  seek()
  matchString()
  match()
  matchChar()
  literal()
  whitespace()
  appendComment()
  append()
  last()
  mediaQueryList()
  mediaQuery()
  supportsQuery()
  mediaExpression()
  argValues()
  argValue()
  valueList()
  spaceList()
  genericList()
  expression()
  enclosedExpression()
  expHelper()
  value()
  parenValue()
  progid()
  func()
  argumentList()
  argumentDef()
  map()
  color()
  unit()
  string()
  mixedKeyword()
  openString()
  interpolation()
  propertyName()
  selectors()
  selector()
  selectorSingle()
  variable()
  keyword()
  restrictedKeyword()
  placeholder()
  url()
  end()
  stripAssignmentFlags()
  stripOptionalFlag()
  flattenList()
  to()
  show()
  pregQuote()
  extractLineNumbers()
  getSourcePosition()
  saveEncoding()
  restoreEncoding()


Class: Parser  - X-Ref

Parser

__construct($sourceName, $sourceIndex = 0, $encoding = 'utf-8', $cache = null)   X-Ref
Constructor

param: string                 $sourceName
param: integer                $sourceIndex
param: string                 $encoding
param: \ScssPhp\ScssPhp\Cache $cache

getSourceName()   X-Ref
Get source file name

return: string

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

param: string $msg

parse($buffer)   X-Ref
Parser buffer

param: string $buffer
return: \ScssPhp\ScssPhp\Block

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

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

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

param: string       $buffer
param: string|array $out
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   $selectors
param: integer $pos
return: \ScssPhp\ScssPhp\Block

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

param: string  $type
param: integer $pos
return: \ScssPhp\ScssPhp\Block

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

return: \ScssPhp\ScssPhp\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

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 Delimeter
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   $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

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

param: array $out
return: boolean

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: callable $parseItem
param: string   $delim
param: boolean  $flatten
return: boolean

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

param: array $out
param: bool $listOnly
param: bool $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)   X-Ref
Parse string

param: array $out
return: boolean

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

param: array   $out
param: boolean $restricted
return: boolean

openString($end, &$out, $nestingOpen = null)   X-Ref
Parse an unbounded string stopped by $end

param: string $end
param: array  $out
param: string $nestingOpen
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

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

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

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

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

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

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

param: array $out
return: boolean

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

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

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

param: string  $word
param: boolean $eatWhitespace
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()   X-Ref
Consume an end of statement delimiter

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

to($what, &$out, $until = false, $allowNewline = false)   X-Ref


show()   X-Ref


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