Skip to content

Strange behavior with strings? #122

@jrfaller

Description

@jrfaller

Hi, and thanks a lot for the amazing work on this PHP parser!

I am writing a generic tree transformer for tree-sitter grammars in order to integrate them in a structural diff tool (https://github.com/GumTreeDiff/gumtree) and I was currently trying to integrate PHP thanks to your awesome grammar.

I noticed something weird for the case of strings. If I parse

<?php foo("test") ?>

I obtain (syntax is this: type: associated_text [start_pos,end_pos], I only retain the associated text on leafs)

program [0,21]
    php_tag: <?php [0,5]
    expression_statement [6,17]
        function_call_expression [6,17]
            name: foo [6,9]
            arguments [9,17]
                (: ( [9,10]
                argument [10,16]
                    encapsed_string [10,16]
                        ": " [10,11]
                        string: test [11,15]
                        ": " [15,16]
                ): ) [16,17]
    text_interpolation [18,20]
        ?>: ?> [18,20]

Which is perfect! (perhaps thinking again I am not sure to understand the text_interpolation node but this is not a problem for my usage)

However for the program

<?php foo('test') ?>

I get

    php_tag: <?php [0,5]
    expression_statement [6,17]
        function_call_expression [6,17]
            name: foo [6,9]
            arguments [9,17]
                (: ( [9,10]
                argument [10,16]
                    string [10,16]
                        ': ' [10,11]
                        ': ' [15,16]
                ): ) [16,17]
    text_interpolation [18,20]
        ?>: ?> [18,20]

Notice that in this case the value associated to the string production is not in any child of the string typed node, as it was the case for the encapsed_string and it prevents me to associate the string value to the string node since I retain only the text for leaf nodes.

Is it a normal behavior? Would it be too much hassle to make it work like encapsed_string work?

Cheers!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions