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

compiledb/parser: Unescape input to bashlex parser #7

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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