Skip to content

Empty command e inconsistency #4

Description

@aureliojargas
$ 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]
['', '', '']
>>>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions