[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/vendor/splitbrain/lesserphp/src/ -> Parser.php (summary)

http://leafo.net/lessphp LESS CSS compiler, adapted from http://lesscss.org

File Size: 1523 lines (45 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Parser:: (46 methods):
  __construct()
  parse()
  parseChunk()
  isDirective()
  fixTags()
  expressionList()
  expression()
  expHelper()
  propertyValue()
  parenValue()
  value()
  import()
  mediaQueryList()
  mediaQuery()
  mediaExpression()
  openString()
  stringValue()
  interpolation()
  unit()
  color()
  argumentDef()
  tags()
  mixinTags()
  tagBracket()
  tag()
  func()
  variable()
  assign()
  keyword()
  end()
  guards()
  guardGroup()
  guard()
  literal()
  genericList()
  to()
  match()
  whitespace()
  peek()
  seek()
  throwError()
  pushBlock()
  pushSpecialBlock()
  append()
  pop()
  removeComments()


Class: Parser  - X-Ref

responsible for taking a string of LESS code and converting it into a syntax tree

__construct(?string $sourceName = null)   X-Ref

param: string|null $sourceName name used for error messages

parse($buffer)   X-Ref


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 Lessc::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 Lessc::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, Lessc::seek() is used to remember and set buffer positions.

Before parsing a chain, use $s = $this->seek() to remember the current
position into $s. Then if a chain fails, use $this->seek($s) to
go back where we started.


isDirective($dirname, $directives)   X-Ref
No description

fixTags($tags)   X-Ref
No description

expressionList(&$exps)   X-Ref
No description

expression(&$out)   X-Ref
Attempt to consume an expression.

link: http://en.wikipedia.org/wiki/Operator-precedence_parser#Pseudo-code

expHelper($lhs, $minP)   X-Ref
recursively parse infix equation with $lhs at precedence $minP


propertyValue(&$value, $keyName = null)   X-Ref
No description

parenValue(&$out)   X-Ref
No description

value(&$value)   X-Ref
No description

import(&$out)   X-Ref
No description

mediaQueryList(&$out)   X-Ref
No description

mediaQuery(&$out)   X-Ref
No description

mediaExpression(&$out)   X-Ref
No description

openString($end, &$out, $nestingOpen = null, $rejectStrs = null)   X-Ref
No description

stringValue(&$out)   X-Ref
No description

interpolation(&$out)   X-Ref
No description

unit(&$unit)   X-Ref
No description

color(&$out)   X-Ref
No description

argumentDef(&$args, &$isVararg)   X-Ref
consume an argument definition list surrounded by ()
each argument is a variable name with optional value
or at the end a ... or a variable named followed by ...
arguments are separated by , unless a ; is in the list, then ; is the
delimiter.


tags(&$tags, $simple = false, $delim = ',')   X-Ref
No description

mixinTags(&$tags)   X-Ref
No description

tagBracket(&$parts, &$hasExpression)   X-Ref
No description

tag(&$tag, $simple = false)   X-Ref
No description

func(&$func)   X-Ref
No description

variable(&$name)   X-Ref
No description

assign($name = null)   X-Ref
Consume an assignment operator
Can optionally take a name that will be set to the current property name


keyword(&$word)   X-Ref
No description

end()   X-Ref
No description

guards(&$guards)   X-Ref
No description

guardGroup(&$guardGroup)   X-Ref
No description

guard(&$guard)   X-Ref
No description

literal($what, $eatWhitespace = null)   X-Ref
No description

genericList(&$out, $parseItem, $delim = '', $flatten = true)   X-Ref
No description

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

match($regex, &$out, $eatWhitespace = null)   X-Ref
No description

whitespace()   X-Ref
No description

peek($regex, &$out = null, $from = null)   X-Ref
No description

seek($where = null)   X-Ref
No description

throwError(string $msg = 'parse error', ?int $count = null, \Throwable $previous = null)   X-Ref
Throw a parser exception

This function tries to use the current parsing context to provide
additional info on where/why the error occurred.

param: string $msg The error message to throw
param: int|null $count A line number counter to use instead of the current count
param: \Throwable|null $previous A previous exception to chain

pushBlock($selectors = null, $type = null)   X-Ref
No description

pushSpecialBlock($type)   X-Ref
No description

append($prop, $pos = null)   X-Ref
No description

pop()   X-Ref
No description

removeComments($text)   X-Ref
No description