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

Empty command e inconsistency #4

Open
aureliojargas opened this issue Nov 23, 2019 · 1 comment
Open

Empty command e inconsistency #4

aureliojargas opened this issue Nov 23, 2019 · 1 comment
Labels
bug Something isn't working

Comments

@aureliojargas
Copy link
Owner

$ printf e > e1
$ printf 'e\n' > e2
$ python3 sedparse.py -f e1
[
    {
        "cmd": "e",
        "line": 1
    }
]
$ python3 sedparse.py -f e2
[
    {
        "cmd": "e",
        "line": 1,
        "x": {
            "cmd_txt": {
                "text": [
                    "\n"
                ]
            }
        }
    }
]
$ python3 sedparse.py -e e
[
    {
        "cmd": "e",
        "line": 1
    }
]

When the empty e command is followed by \n (see e2 file in the example), its x.cmd_txt.text property comes with a solo \n. This is confusing and probably wrong. Investigate.

Note that in struct_text_buf, we are removing the trailing \n:

class struct_text_buf(struct):
    # ...
    def __str__(self):
        return "".join(self.text)[:-1]  # remove trailing \n

so using str(x.cmd_txt) instead of accessing x.cmd_txt.text directly, will always produce an empty string in all the previous examples.

>>> import sedparse
>>> prog = []
>>> sedparse.compile_string(prog, 'e')
>>> sedparse.compile_file(prog, 'e1')
>>> sedparse.compile_file(prog, 'e2')
>>> [item.x.cmd_txt.text for item in prog]
[[], [], ['\n']]
>>> [str(item.x.cmd_txt) for item in prog]
['', '', '']
>>>
@aureliojargas
Copy link
Owner Author

aureliojargas commented Nov 24, 2019

This extra \n at the end of x.cmd_txt.text is also related to #2.

@aureliojargas aureliojargas added the bug Something isn't working label Dec 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant