Skip to content

Commit

Permalink
compiledb/parser: Unescape input to bashlex parser
Browse files Browse the repository at this point in the history
Unescape input to bashlex parser.
It should address issues nickdiego#124, nickdiego#120

Signed-off-by: Ioannis Damigos <[email protected]>
  • Loading branch information
ydamigos authored and marzojr committed Feb 22, 2024
1 parent 170f3f3 commit aea17ec
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions compiledb/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def skip_line(cmd, reason):

# add entry to database
tokens = c['tokens']
arguments = [unescape(a) for a in tokens[len(wrappers):]]
arguments = [a for a in tokens[len(wrappers):]]

compiler = get_compiler(arguments[0])

Expand Down Expand Up @@ -184,7 +184,7 @@ class CommandProcessor(bashlex.ast.nodevisitor):
looking for and extracting compilation commands."""
@staticmethod
def process(line, wd):
trees = bashlex.parser.parse(line)
trees = bashlex.parser.parse(unescape(line))
if not trees:
return []
for tree in trees:
Expand All @@ -201,7 +201,7 @@ def process(line, wd):
preprocessed[start:end] = out.strip()
preprocessed = ''.join(preprocessed)

trees = bashlex.parser.parse(preprocessed)
trees = bashlex.parser.parse(unescape(preprocessed))
processor = CommandProcessor(preprocessed, wd)
for tree in trees:
processor.do_process(tree)
Expand Down Expand Up @@ -256,6 +256,6 @@ def check_last_cmd(self):


def unescape(s):
return s.encode().decode('unicode_escape')
return s.encode('unicode_escape').decode()

# ex: ts=2 sw=4 et filetype=python

0 comments on commit aea17ec

Please sign in to comment.