Fix parsing of C line comments

Fix // comments stopping on 'n' instead of newlines. Also allow
backslash-newline in // comments.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
Gilles Peskine 2024-01-08 21:05:42 +01:00
parent 4411c9c1f8
commit 89b50a7cb4

View File

@ -76,7 +76,7 @@ class FunctionInfo:
# Match one C comment.
# Note that we match both comment types, so things like // in a /*...*/
# comment are handled correctly.
_C_COMMENT_RE = re.compile(r'//[^n]*|/\*.*?\*/', re.S)
_C_COMMENT_RE = re.compile(r'//(?:[^\n]|\\\n)*|/\*.*?\*/', re.S)
_NOT_NEWLINES_RE = re.compile(r'[^\n]+')
def read_logical_lines(filename: str) -> Iterator[Tuple[int, str]]: