Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

impossible detect curly in encapsed #175

Closed
alexander-akait opened this issue Aug 29, 2018 · 3 comments · Fixed by #231
Closed

impossible detect curly in encapsed #175

alexander-akait opened this issue Aug 29, 2018 · 3 comments · Fixed by #231
Assignees

Comments

@alexander-akait
Copy link
Collaborator

alexander-akait commented Aug 29, 2018

Input:

$juices = ['FOO' => 1];

echo "He drank some $juices[FOO] juice.";
echo "\n";
echo "He drank some ${juices['FOO']} juice.";
echo "\n";
echo "He drank some {$juices['FOO']} juice.";

Impossible detect ${ and } for first example. Maybe we can add options syntax:

  1. syntax: simple, curly: false
  2. syntax: simple, curly: true
  3. syntax: complex
@ichiriac
Copy link
Member

👍 I'll fix it soon

@alexander-akait
Copy link
Collaborator Author

Looks due this problem we break code:
Input:

$var = "This is my array value: $anArray[key]";
$var = "This is my array value: {$anArray[key]}";

Output:

$var = "This is my array value: $anArray[key]";
$var = "This is my array value: $anArray[key]";

Second expression output (with { and } no):

PHP Warning:  Use of undefined constant key - assumed 'key'

@alexander-akait
Copy link
Collaborator Author

alexander-akait commented Oct 25, 2018

I look on https://github.com/nikic/PHP-Parser/, they don't have information about { and }. After investigate and testing difference examples of code i find what we should introduce EncapsedItem node and have curly property for this and expression (maybe better name) property that have variable/*lookup/call node. It is allow to avoid adding curly to variable/*lookup/call nodes and save ast clear.

Example.

Input:

"{$var}";

AST:

{
      "kind": "encapsed",
      },
      "value": [
        {
                "kind": "encapseditem",
                "curly" : "true",
                "expression":  {
                      "kind": "variable",
                      "name": "var",
                      "byref": false,
                      "curly": false
                }
        }
      ],
      "type": "string"
    }

Input:

"$var";

AST:

{
      "kind": "encapsed",
      },
      "value": [
        {
                "kind": "encapseditem",
                "curly" : "false",
                "expression":  {
                      "kind": "variable",
                      "name": "var",
                      "byref": false,
                      "curly": false
                }
        }
      ],
      "type": "string"
    }

Input:

"${var}";

AST:

{
      "kind": "encapsed",
      },
      "value": [
        {
                "kind": "encapseditem",
                "curly" : "false",
                "expression":  {
                      "kind": "variable",
                      "name": "var",
                      "byref": false,
                      "curly": true
                }
        }
      ],
      "type": "string"
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants