Parser
extends Token
in package
LightnCandy Parser
Table of Contents
- BLOCKPARAM = 9999
- LITERAL = -1
- PARTIALBLOCK = 9998
- POS_BACKFILL = 13
- POS_BEGINRAW = 5
- POS_BEGINTAG = 3
- POS_ENDRAW = 8
- POS_ENDTAG = 10
- POS_INNERTAG = 7
- POS_LOTHER = 1
- POS_LSPACE = 2
- POS_LSPACECTL = 4
- POS_OP = 6
- POS_ROTHER = 12
- POS_RSPACE = 11
- POS_RSPACECTL = 9
- SUBEXP = -2
- VARNAME_SEARCH = '/(\[[^\]]+\]|[^\[\]\.]+)/'
- getBlockParams() : array<string|int, string>|null
- Get block params and fix the variable list
- getPartialBlock() : int
- Get partial block id and fix the variable list
- getPartialName() : array<string|int, string>|null
- Get partial name from "foo" or [foo] or \'foo\'
- isSubExp() : bool
- Check a parsed result is a subexpression or not
- parse() : array<string|int, bool|int|array>
- Parse the token and return parsed result.
- setDelimiter() : mixed
- Setup delimiter by default or provided string
- subexpression() : array<string|int, bool|int|array>
- Parse a subexpression then return parsed result.
- toString() : string
- return token string
- advancedVariable() : array<string|int, bool|int|array>
- Analyze parsed token for advanved variables.
- analyze() : array<string|int, bool|int|array>
- Analyze a token string and return parsed result.
- detectQuote() : array<string, int>|null
- Detect quote charactors
- getExpression() : array<int, string>
- Return array presentation for an expression
- getLiteral() : array<string|int, int|string>
- Return array presentation for a literal
Constants
BLOCKPARAM
public
mixed
BLOCKPARAM
= 9999
LITERAL
public
mixed
LITERAL
= -1
PARTIALBLOCK
public
mixed
PARTIALBLOCK
= 9998
POS_BACKFILL
public
mixed
POS_BACKFILL
= 13
POS_BEGINRAW
public
mixed
POS_BEGINRAW
= 5
POS_BEGINTAG
public
mixed
POS_BEGINTAG
= 3
POS_ENDRAW
public
mixed
POS_ENDRAW
= 8
POS_ENDTAG
public
mixed
POS_ENDTAG
= 10
POS_INNERTAG
public
mixed
POS_INNERTAG
= 7
POS_LOTHER
public
mixed
POS_LOTHER
= 1
POS_LSPACE
public
mixed
POS_LSPACE
= 2
POS_LSPACECTL
public
mixed
POS_LSPACECTL
= 4
POS_OP
public
mixed
POS_OP
= 6
POS_ROTHER
public
mixed
POS_ROTHER
= 12
POS_RSPACE
public
mixed
POS_RSPACE
= 11
POS_RSPACECTL
public
mixed
POS_RSPACECTL
= 9
SUBEXP
public
mixed
SUBEXP
= -2
VARNAME_SEARCH
public
mixed
VARNAME_SEARCH
= '/(\[[^\]]+\]|[^\[\]\.]+)/'
Methods
getBlockParams()
Get block params and fix the variable list
public
static getBlockParams(array<string|int, bool|int|string|array> &$vars) : array<string|int, string>|null
Parameters
- $vars : array<string|int, bool|int|string|array>
-
parsed token
Return values
array<string|int, string>|null —Return list of block params or null
getPartialBlock()
Get partial block id and fix the variable list
public
static getPartialBlock(array<string|int, bool|int|string|array> &$vars) : int
Parameters
- $vars : array<string|int, bool|int|string|array>
-
parsed token
Return values
int —Return partial block id
getPartialName()
Get partial name from "foo" or [foo] or \'foo\'
public
static getPartialName(array<string|int, bool|int|array> &$vars, int $pos) : array<string|int, string>|null
Parameters
- $vars : array<string|int, bool|int|array>
-
parsed token
- $pos : int
-
position of partial name
Tags
Return values
array<string|int, string>|null —Return one element partial name array
isSubExp()
Check a parsed result is a subexpression or not
public
static isSubExp(array<string|int, string|int|array> $var) : bool
Parameters
- $var : array<string|int, string|int|array>
Tags
Return values
bool —return true when input is a subexpression
parse()
Parse the token and return parsed result.
public
static parse(array<string|int, string> &$token, array<string, array|string|int> &$context) : array<string|int, bool|int|array>
Parameters
- $token : array<string|int, string>
-
preg_match results
- $context : array<string, array|string|int>
-
current compile context
Tags
Return values
array<string|int, bool|int|array> —Return parsed result
setDelimiter()
Setup delimiter by default or provided string
public
static setDelimiter(array<string, array|string|int> &$context[, string|null $left = null ][, string|null $right = null ]) : mixed
Parameters
- $context : array<string, array|string|int>
-
Current context
- $left : string|null = null
-
left string of a token
- $right : string|null = null
-
right string of a token
Return values
mixed —subexpression()
Parse a subexpression then return parsed result.
public
static subexpression(string $expression, array<string, array|string|int> &$context) : array<string|int, bool|int|array>
Parameters
- $expression : string
-
the full string of a sub expression
- $context : array<string, array|string|int>
-
current compile context
Tags
Return values
array<string|int, bool|int|array> —Return parsed result
toString()
return token string
public
static toString(array<string|int, string> $token[, array<string|int, string>|null $merge = null ]) : string
Parameters
- $token : array<string|int, string>
-
detected handlebars {{ }} token
- $merge : array<string|int, string>|null = null
-
list of token strings to be merged
Tags
Return values
string —Return whole token
advancedVariable()
Analyze parsed token for advanved variables.
protected
static advancedVariable(array<string|int, bool|int|array> $vars, array<string, array|string|int> &$context, string $token) : array<string|int, bool|int|array>
Parameters
- $vars : array<string|int, bool|int|array>
-
parsed token
- $context : array<string, array|string|int>
-
current compile context
- $token : string
-
original token
Tags
Return values
array<string|int, bool|int|array> —Return parsed result
analyze()
Analyze a token string and return parsed result.
protected
static analyze(string $token, array<string, array|string|int> &$context) : array<string|int, bool|int|array>
Parameters
- $token : string
-
preg_match results
- $context : array<string, array|string|int>
-
current compile context
Tags
Return values
array<string|int, bool|int|array> —Return parsed result
detectQuote()
Detect quote charactors
protected
static detectQuote(string $string) : array<string, int>|null
Parameters
- $string : string
-
the string to be detect the quote charactors
Return values
array<string, int>|null —Expected ending string when quote charactor be detected
getExpression()
Return array presentation for an expression
protected
static getExpression(string $v, array<string, array|string|int> &$context, int $pos) : array<int, string>
Parameters
- $v : string
-
analyzed expression names.
- $context : array<string, array|string|int>
-
Current compile content.
- $pos : int
-
expression position
Tags
Return values
array<int, string> —Return variable name array
getLiteral()
Return array presentation for a literal
protected
static getLiteral(string $name, bool $asis[, bool $quote = false ]) : array<string|int, int|string>
Parameters
- $name : string
-
variable name.
- $asis : bool
-
keep the name as is or not
- $quote : bool = false
-
add single quote or not
Return values
array<string|int, int|string> —Return variable name array