-
Notifications
You must be signed in to change notification settings - Fork 3
Empty command e inconsistency #4
Copy link
Copy link
Open
Labels
bugSomething isn't workingSomething isn't working
Description
$ 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 \nso 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]
['', '', '']
>>>Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working