Skip to content

Refresh string literal representation #11

Closed

Description

The representation of string literals is still a work-in-progress, and the implementation became even more inconsistent when we moved away from the handspun lexer towards PhpTokenizer. We should put some thought into how best to represent strings and template strings.

Activity

  1. PythooonUser commented on Aug 7, 2020

    @PythooonUser
    Contributor

    Hey,

    here in #11 and in #168 you talk about that strings and template strings are still not implemented perfectly. Can you iterate on what exactly is still missing or not working?

    I had a look at the parse output of e.g.

    <?php "Hello $world";

    Which gives

    {
        "SourceFileNode": {
            "statementList": [
                [...]
                {
                    "ExpressionStatement": {
                        "expression": {
                            "StringLiteral": {
                                "startQuote": {
                                    "kind": "DoubleQuoteToken",
                                    "fullStart": 6,
                                    "start": 6,
                                    "length": 1
                                },
                                "children": [
                                    {
                                        "kind": "EncapsedAndWhitespace",
                                        "fullStart": 7,
                                        "start": 7,
                                        "length": 6
                                    },
                                    {
                                        "Variable": {
                                            "dollar": null,
                                            "name": {
                                                "kind": "VariableName",
                                                "fullStart": 13,
                                                "start": 13,
                                                "length": 6
                                            }
                                        }
                                    }
                                ],
                                "endQuote": {
                                    "kind": "DoubleQuoteToken",
                                    "fullStart": 19,
                                    "start": 19,
                                    "length": 1
                                }
                            }
                        },
                        "semicolon": {
                            "kind": "SemicolonToken",
                            "fullStart": 20,
                            "start": 20,
                            "length": 1
                        }
                    }
                }
            ]
            [...]
        }
    }

    And it returns an instance of StringLiteral which is essentially a non-delimited list of whitespace/characters and expression nodes. That sounds good to me and seems to be flexible enough.

    Have you considered also making escape characters like \n its own token appearing as a children node in a string? Could that be helpful? I know that this distinction is made in language grammars (syntax highlighting) at least.

    Cheers

  2. roblourens commented on Aug 7, 2020

    @roblourens
    Member

    Honestly I'm not sure what else we had in mind. Would have to look back at old notes.

    Have you considered also making escape characters like \n its own token appearing as a children node in a string?

    Probably would not parse it at that granularity unless there was a good reason for it.

  3. PythooonUser commented on Aug 7, 2020

    @PythooonUser
    Contributor

    Yes, I see. The current implementation seems to be in a good state :)

  4. roblourens commented on Aug 8, 2020

    @roblourens
    Member

    Thanks for taking a look though. I will close this unless there is a reason to reopen it.

  5. added a commit that references this issue on Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions