Skip to content

Commit

Permalink
Discard line continuations
Browse files Browse the repository at this point in the history
- Fixes #54
  • Loading branch information
virtuald committed Jul 23, 2023
1 parent 9bf99db commit b07e1f8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
7 changes: 6 additions & 1 deletion cxxheaderparser/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,12 @@ def _fill_tokbuf(self, tokbuf: typing.Deque[LexToken]) -> bool:
tokbuf.append(tok)

if tok.type == "NEWLINE":
break
# detect/remove line continuations
if len(tokbuf) > 2 and tokbuf[-2].type == "\\":
tokbuf.pop()
tokbuf.pop()
else:
break

# detect/combine user defined literals
if tok.type in udl_start:
Expand Down
3 changes: 0 additions & 3 deletions tests/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,14 @@ def test_enum_w_multiline_expr() -> None:
Token(value="<<"),
Token(value="24"),
Token(value="|"),
Token(value="\\"),
Token(value="'A'"),
Token(value="<<"),
Token(value="16"),
Token(value="|"),
Token(value="\\"),
Token(value="'S'"),
Token(value="<<"),
Token(value="8"),
Token(value="|"),
Token(value="\\"),
Token(value="'H'"),
Token(value=")"),
]
Expand Down
27 changes: 27 additions & 0 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,30 @@ def test_user_defined_literal() -> None:
]
)
)


#
# Line continuation
#


def test_line_continuation() -> None:
content = """
static int \
variable;
"""
data = parse_string(content, cleandoc=True)

assert data == ParsedData(
namespace=NamespaceScope(
variables=[
Variable(
name=PQName(segments=[NameSpecifier(name="variable")]),
type=Type(
typename=PQName(segments=[FundamentalSpecifier(name="int")])
),
static=True,
)
]
)
)

0 comments on commit b07e1f8

Please sign in to comment.