Skip to content

Commit 212ae62

Browse files
committed
Introduce :: lexical token, should make parsing easier
1 parent 5432b45 commit 212ae62

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

CppHeaderParser/CppHeaderParser.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,13 @@ def _split_namespace(namestack):
255255
256256
:rtype: Tuple[str, list]
257257
"""
258+
# TODO: this should be using tokens instead of nhack
259+
258260
last_colon = None
259261
for i, n in enumerate(namestack):
260-
if n == ":":
262+
if n == "::":
261263
last_colon = i
262-
if i and n != ":" and not _nhack.match(n):
264+
if i and n != "::" and not _nhack.match(n):
263265
break
264266

265267
if last_colon:
@@ -472,12 +474,8 @@ def _parse_cppclass_name(c, stack):
472474
if t == ":":
473475
if i >= sl:
474476
raise CppParseError("class decl ended with ':'")
475-
t = stack[i]
476-
if t != ":":
477-
# reached the base declaration
478-
break
479-
480-
i += 1
477+
break
478+
elif t == "::":
481479
name += "::"
482480
continue
483481
elif t == "final":
@@ -954,7 +952,7 @@ def __init__(self, nameStack, curClass, methinfo, curTemplate, doxygen, location
954952
if len(self["rtnType"]) == 0 or self["name"] == curClass:
955953
self["rtnType"] = "void"
956954

957-
self["rtnType"] = self["rtnType"].replace(" : : ", "::")
955+
self["rtnType"] = self["rtnType"].replace(" :: ", "::")
958956
self["rtnType"] = self["rtnType"].replace(" < ", "<")
959957
self["rtnType"] = self["rtnType"].replace(" > ", "> ").replace(">>", "> >")
960958
self["rtnType"] = self["rtnType"].replace(" ,", ",")
@@ -1959,8 +1957,8 @@ def finalize(self):
19591957
)
19601958
meth["returns_unknown"] = True
19611959

1962-
if meth["returns"].startswith(": : "):
1963-
meth["returns"] = meth["returns"].replace(": : ", "::")
1960+
if meth["returns"].startswith(":: "):
1961+
meth["returns"] = meth["returns"].replace(":: ", "::")
19641962

19651963
for cls in list(self.classes.values()):
19661964
methnames = cls.get_all_method_names()
@@ -1996,7 +1994,7 @@ def parse_method_type(self, stack):
19961994
stack = stack[1:]
19971995
info = {
19981996
"debug": " ".join(stack)
1999-
.replace(" : : ", "::")
1997+
.replace(" :: ", "::")
20001998
.replace(" < ", "<")
20011999
.replace(" > ", "> ")
20022000
.replace(" >", ">")
@@ -2010,7 +2008,7 @@ def parse_method_type(self, stack):
20102008

20112009
header = stack[: stack.index("(")]
20122010
header = " ".join(header)
2013-
header = header.replace(" : : ", "::")
2011+
header = header.replace(" :: ", "::")
20142012
header = header.replace(" < ", "<")
20152013
header = header.replace(" > ", "> ")
20162014
header = header.replace("default ", "default")
@@ -2452,6 +2450,7 @@ def evalute_forward_decl(self):
24522450
"+",
24532451
"STRING_LITERAL",
24542452
"ELLIPSIS",
2453+
"DBL_COLON",
24552454
"SHIFT_LEFT",
24562455
}
24572456

@@ -3164,7 +3163,7 @@ def _parse_template(self):
31643163
consumed = self._consume_balanced_tokens(tok)
31653164
tmpl = " ".join(tok.value for tok in consumed)
31663165
tmpl = (
3167-
tmpl.replace(" : : ", "::")
3166+
tmpl.replace(" :: ", "::")
31683167
.replace(" <", "<")
31693168
.replace("< ", "<")
31703169
.replace(" >", ">")
@@ -3364,10 +3363,10 @@ def _parse_enumerator_list(self, values):
33643363
while True:
33653364
tok = self.lex.token()
33663365
if tok.type == "}":
3367-
value["value"] = (" ".join(v)).replace(": :", "::")
3366+
value["value"] = " ".join(v)
33683367
return
33693368
elif tok.type == ",":
3370-
value["value"] = (" ".join(v)).replace(": :", "::")
3369+
value["value"] = " ".join(v)
33713370
break
33723371
elif tok.type in self._balanced_token_map:
33733372
v.extend(t.value for t in self._consume_balanced_tokens(tok))

CppHeaderParser/lexer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class Lexer(object):
2222
"ELLIPSIS",
2323
"DBL_LBRACKET",
2424
"DBL_RBRACKET",
25+
"DBL_COLON",
2526
"SHIFT_LEFT",
2627
]
2728

@@ -85,6 +86,7 @@ def t_COMMENT_SINGLELINE(self, t):
8586
t_ELLIPSIS = r"\.\.\."
8687
t_DBL_LBRACKET = r"\[\["
8788
t_DBL_RBRACKET = r"\]\]"
89+
t_DBL_COLON = r"::"
8890
t_SHIFT_LEFT = r"<<"
8991
# SHIFT_RIGHT introduces ambiguity
9092

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy