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

The number of columns is misplaced when the shfmt parses the backquote command with escape symbols. #1028

Closed
tegixia opened this issue Sep 1, 2023 · 1 comment

Comments

@tegixia
Copy link

tegixia commented Sep 1, 2023

  • The shell statement is as follows:
#!/bin/bash
demo=3
last=`echo \\$demo`

After parsing,The number of columns of the keyword ‘\$demo’ is misplaced.It's supposed to be 12 to 19, but it's actually 12 to 18.

  • shfmt parse tree:
[
    {
        "Pos": {
            "Offset": 27,
            "Line": 3,
            "Col": 7
        },
        "End": {
            "Offset": 31,
            "Line": 3,
            "Col": 11
        },
        "Parts": [
            {
                "Type": "Lit",
                "Pos": {
                    "Offset": 27,
                    "Line": 3,
                    "Col": 7
                },
                "End": {
                    "Offset": 31,
                    "Line": 3,
                    "Col": 11
                },
                "ValuePos": {
                    "Offset": 27,
                    "Line": 3,
                    "Col": 7
                },
                "ValueEnd": {
                    "Offset": 31,
                    "Line": 3,
                    "Col": 11
                },
                "Value": "echo"
            }
        ]
    },
    {
        "Pos": {
            "Offset": 33,
            "Line": 3,
            "Col": 12
        },
        "End": {
            "Offset": 39,
            "Line": 3,
            "Col": 18
        },
        "Parts": [
            {
                "Type": "Lit",
                "Pos": {
                    "Offset": 33,
                    "Line": 3,
                    "Col": 12
                },
                "End": {
                    "Offset": 39,
                    "Line": 3,
                    "Col": 18
                },
                "ValuePos": {
                    "Offset": 33,
                    "Line": 3,
                    "Col": 12
                },
                "ValueEnd": {
                    "Offset": 39,
                    "Line": 3,
                    "Col": 18
                },
                "Value": "\\$demo"
            }
        ]
    }
]
@mvdan
Copy link
Owner

mvdan commented Dec 26, 2023

Thanks. This one was quite tricky to figure out, but I think I have now.

@mvdan mvdan closed this as completed in 28117db Dec 26, 2023
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

No branches or pull requests

2 participants