Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Rescue master branch PRs: Template enhancements #10497

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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