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

Variables that will be expanded in double quoted strings are not parsed as variables #34

Closed
Ben3eeE opened this issue Oct 17, 2018 · 4 comments · Fixed by #72
Closed

Comments

@Ben3eeE
Copy link
Contributor

Ben3eeE commented Oct 17, 2018

http://php.net/manual/en/language.types.string.php#language.types.string.parsing

Program:

<?php
$juice = "apple";

echo "He drank some $juice juice.".PHP_EOL;
// Invalid. "s" is a valid character for a variable name, but the variable is $juice.
echo "He drank some juice made of $juices.";
// Valid. Explicitly specify the end of the variable name by enclosing it in braces:
echo "He drank some juice made of ${juice}s.";
?>

Output:

He drank some apple juice.
He drank some juice made of .
He drank some juice made of apples.

Parser:
All of these variables are parsed as string:

text.html.php
program
echo_statement
string

Version:
0.13.0

@patrickt
Copy link
Contributor

Interpolated strings in general are pretty tricky. Looks like we might be able to get away with an interpolated_string rule that contains the matched variable names.

@Ben3eeE
Copy link
Contributor Author

Ben3eeE commented Oct 17, 2018

There is also the Complex (curly) syntax. If you surround the variable with curly brackets you can do more complex interpolated strings that you otherwise can't like:

// Works, quoted keys only work using the curly brace syntax
echo "This works: {$arr['key']}";

Maybe this will complicate things 😅

@patrickt
Copy link
Contributor

Oof, that’s tricky as well.

@maxbrunsfeld
Copy link
Contributor

Seems like strings work somewhat similarly to double quoted strings in bash? Here's our current rule for that in the bash parser: https://github.com/tree-sitter/tree-sitter-bash/blob/5203b504db454180de58af6f0ea6fc10df47b487/grammar.js#L417-L430.

@cfroystad cfroystad mentioned this issue Apr 6, 2021
32 tasks
@cfroystad cfroystad mentioned this issue Apr 27, 2021
5 tasks
@cfroystad cfroystad linked a pull request Jul 23, 2021 that will close this issue
5 tasks
@aryx aryx closed this as completed in #72 Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants