Skip to content

Commit

Permalink
Merge pull request #10497 from creative-commoners/pulls/5/rescue-mast…
Browse files Browse the repository at this point in the history
…er-template-enhancements

Rescue master branch PRs: Template enhancements
  • Loading branch information
emteknetnz authored Sep 15, 2022
2 parents 71dca01 + 1385712 commit fc78763
Show file tree
Hide file tree
Showing 8 changed files with 2,027 additions and 1,540 deletions.
46 changes: 45 additions & 1 deletion src/View/SSTemplateParser.peg
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ class SSTemplateParser extends Parser implements TemplateParser

$property = $sub['Call']['Method']['text'];

if (isset($sub['Call']['CallArguments']) && $arguments = $sub['Call']['CallArguments']['php']) {
if (isset($sub['Call']['CallArguments']) && isset($sub['Call']['CallArguments']['php'])) {
$arguments = $sub['Call']['CallArguments']['php'];
$res['php'] .= "->$method('$property', [$arguments], true)";
} else {
$res['php'] .= "->$method('$property', null, true)";
Expand Down Expand Up @@ -415,6 +416,28 @@ class SSTemplateParser extends Parser implements TemplateParser

QuotedString: q:/['"]/ String:/ (\\\\ | \\. | [^$q\\])* / '$q'

# Null

Null: / (null)\b /i

# Booleans

Boolean: / (true|false)\b /i

# Integers and floats

Sign: / [+-] /

Float: / [0-9]*\.?[0-9]+([eE][-+]?[0-9]+)? /
Hexadecimal: / 0[xX][0-9a-fA-F]+ /
Octal: / 0[0-7]+ /
Binary: / 0[bB][01]+ /
Decimal: / 0 | [1-9][0-9]* /

# The order of the below statements is important. E.g. with Float first, the '0' in a '0x1A' hexadecimal would
# match the first part of the float regexp, so would stop matching there
IntegerOrFloat: ( Sign )? ( Hexadecimal | Binary | Float | Octal | Decimal )

# In order to support 2.4's base syntax, we also need to detect free strings - strings not surrounded by
# quotes, and containing spaces or punctuation, but supported as a single string. We support almost as flexible
# a string as 2.4 - we don't attempt to determine the closing character by context, but just break on any
Expand All @@ -429,6 +452,9 @@ class SSTemplateParser extends Parser implements TemplateParser
Argument:
:DollarMarkedLookup |
:QuotedString |
:Null |
:Boolean |
:IntegerOrFloat |
:Lookup !(< FreeString)|
:FreeString
*/
Expand Down Expand Up @@ -459,6 +485,24 @@ class SSTemplateParser extends Parser implements TemplateParser
$res['php'] = "'" . str_replace("'", "\\'", $sub['String']['text']) . "'";
}

function Argument_Null(&$res, $sub)
{
$res['ArgumentMode'] = 'string';
$res['php'] = $sub['text'];
}

function Argument_Boolean(&$res, $sub)
{
$res['ArgumentMode'] = 'string';
$res['php'] = $sub['text'];
}

function Argument_IntegerOrFloat(&$res, $sub)
{
$res['ArgumentMode'] = 'string';
$res['php'] = $sub['text'];
}

function Argument_Lookup(&$res, $sub)
{
if (count($sub['LookupSteps']) == 1 && !isset($sub['LookupSteps'][0]['Call']['Arguments'])) {
Expand Down
Loading

0 comments on commit fc78763

Please sign in to comment.