P6C::Tree ^

This is the string interpolation section. Here's a rundown:

1.) The string is parsed with the quoted_string rule in the grammar. - Unlike perl5, the string is checked straight through, rather than finding the end and then parsing the middle. - While much slower, this allows for strings like: "%var{"one"}" which would be syntactically illegal in perl5. - quoted_string shouldn't be included in the grammar bare, but rather through sv_literal; this is because the quoted_string parse object doesn't have a tree method. Not only would it would be horribly complex, it would be impossible to capture spaces between string atoms without specifying the return value inside the rule.

2.) Next, sv_literal's tree method is called. After discovering that the literal is a string, it calls and returns quoted_string's tree method.

3.) concat_string first removes the parse object name, and then calls P6C::Tree::String::interpolate_expand.

4.) interpolate_expand deals with embedded strings (aka "\q{}" and '\qq{}') by flattening a potentially tree-like structure into a list.

5.) This list is then passed to interpolate_concat_literal, which does 3 things: "interpolates" variables and interpolated_values by calling their tree structures upon them, escapes backslashes and quotes in strings, and also performs a runtime speed optimization by concatting successive literal strings together.

6.) The modified list is next passed to concat_list, which turns the list into a node representation. Literal strings are turned into sv_literal's, and lists longer than 1 item are concatted with the _ (concat) binop.

7.) Finally, the node representation is returned.


parrot