Skip to content
Browse files

Better variable extraction

  • Loading branch information...
1 parent d35da4a commit c3bed3511294ab63c3ed5eabd4ab83aab6a8cbd5 @quarnster committed May 28, 2012
Showing with 38 additions and 4 deletions.
  1. +16 −4 parsehelp.py
  2. +22 −0 unittest.py
View
20 parsehelp.py
@@ -432,13 +432,25 @@ def remove_empty_classes(data):
def get_type_definition(data):
before = extract_completion(data)
- match = re.search(r"([^\.\-:]+)[^\.\-:]*(\.|->|::)(.*)", before)
- var = match.group(1)
+ tocomplete = ""
+ var = None
+ end = None
+ for m in re.finditer(r"([^\.\-,+*/:]+)(\.|->|::)", before):
+ if var != None and m.start(0) != end:
+ var = None
+ tocomplete = ""
+
+ if len(tocomplete):
+ tocomplete += m.group(1)
+ tocomplete += m.group(2)
+ if var == None:
+ var = m.group(1)
+ end = m.end(2)
+
extra = ""
if var.endswith("[]"):
extra = var[var.find("["):]
var = var[:var.find("[")]
- tocomplete = before[match.start(2):match.end(3)]
if var == "this":
clazz = extract_class(data)
@@ -451,7 +463,7 @@ def get_type_definition(data):
if clazz:
sup = extract_inheritance(data, clazz)
return -1, -1, sup, var, tocomplete
- elif match.group(2) == "::":
+ elif tocomplete.startswith("::"):
return 0, 0, var, var, tocomplete
else:
match = get_var_type(data, var)
View
22 unittest.py
@@ -651,4 +651,26 @@ class Test
test = """std::vector<int> a, b;"""
if extract_variables(test) != [('std::vector<int>', 'a'), ('std::vector<int>', 'b')]:
raise Exception("Didn't extract variables properly")
+
+if get_type_definition("struct timeval t; a+t.") != (1, 16, 'timeval', 't', '.'):
+ raise Exception("Couldn't get the type definition")
+if get_type_definition("struct timeval t; a|t.") != (1, 16, 'timeval', 't', '.'):
+ raise Exception("Couldn't get the type definition")
+if get_type_definition("struct timeval t; a-t.") != (1, 16, 'timeval', 't', '.'):
+ raise Exception("Couldn't get the type definition")
+if get_type_definition("struct timeval t; a*t.") != (1, 16, 'timeval', 't', '.'):
+ raise Exception("Couldn't get the type definition")
+if get_type_definition("struct timeval t; a/t.") != (1, 16, 'timeval', 't', '.'):
+ raise Exception("Couldn't get the type definition")
+
+test = """SwapBuffersData& data = (*i).second;
+ if (++data."""
+if get_type_definition(test) != (1, 18, 'SwapBuffersData&', 'data', '.'):
+ raise Exception("Couldn't get the type definition")
+
+test = """SwapBuffersData& data = (*i).second;
+end.tv_usec-data."""
+if get_type_definition(test) != (1, 18, 'SwapBuffersData&', 'data', '.'):
+ raise Exception("Couldn't get the type definition")
+
print "all is well"

0 comments on commit c3bed35

Please sign in to comment.
Something went wrong with that request. Please try again.