mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-25 13:36:31 +08:00
Update extract_code_go.py
This commit is contained in:
parent
e8c78f89f0
commit
61a2c32f64
1 changed files with 22 additions and 21 deletions
|
@ -70,11 +70,7 @@ class ExtractCodeBlocksGo(ExtractCodeBlocksJava):
|
|||
func_cls_label = func_match.group(self.func_pattern_keys.index("class"))
|
||||
func_return = func_match.group(self.func_pattern_keys.index("return"))
|
||||
|
||||
if classes:
|
||||
# The function should not blong to any class
|
||||
flag = False
|
||||
for label in classes:
|
||||
# Match the target class label
|
||||
def check_func_blong_to_class(label):
|
||||
class_label_pattern = re.compile(f".*\*{label}\).*")
|
||||
func_return_pattern = re.compile(f".*\*{label}.*")
|
||||
constructor_pattern = re.compile(f".*new.*")
|
||||
|
@ -83,6 +79,16 @@ class ExtractCodeBlocksGo(ExtractCodeBlocksJava):
|
|||
func_return_match = func_return_pattern.match(f"{func_return}")
|
||||
constructor_match = constructor_pattern.match(func_label)
|
||||
|
||||
return class_label_match, func_return_match, constructor_match
|
||||
|
||||
if classes:
|
||||
# The function should not blong to any class
|
||||
flag = False
|
||||
for label in classes:
|
||||
# Match the target class label
|
||||
class_label_match, func_return_match, constructor_match = \
|
||||
check_func_blong_to_class(label)
|
||||
|
||||
if class_label_match is not None or \
|
||||
func_return_match is not None and constructor_match is not None:
|
||||
flag = True
|
||||
|
@ -91,17 +97,11 @@ class ExtractCodeBlocksGo(ExtractCodeBlocksJava):
|
|||
|
||||
elif class_label:
|
||||
# Match the target class label
|
||||
class_label_pattern = re.compile(f".*\*{class_label}\).*")
|
||||
func_return_pattern = re.compile(f".*\*{class_label}.*")
|
||||
constructor_pattern = re.compile(f".*new.*")
|
||||
class_label_match, func_return_match, constructor_match = \
|
||||
check_func_blong_to_class(class_label)
|
||||
|
||||
class_label_match = class_label_pattern.match(f"{func_cls_label}")
|
||||
func_return_match = func_return_pattern.match(f"{func_return}")
|
||||
constructor_match = constructor_pattern.match(func_label)
|
||||
|
||||
if class_label_match is None and func_return_match is None:
|
||||
continue
|
||||
if func_return_match is not None and constructor_match is None:
|
||||
if class_label_match is None and func_return_match is None or \
|
||||
func_return_match is not None and constructor_match is None:
|
||||
continue
|
||||
|
||||
# Search the block from the header line
|
||||
|
@ -177,7 +177,8 @@ class ExtractCodeBlocksGo(ExtractCodeBlocksJava):
|
|||
for func in funcs.values():
|
||||
replace_tabs(func)
|
||||
|
||||
for code_path in glob.glob("codes/go/chapter_*/array_hash_map.go"):
|
||||
ext = ExtractCodeBlocksGo()
|
||||
res = ext.extract(code_path)
|
||||
pass
|
||||
|
||||
# for code_path in glob.glob("codes/go/chapter_*/array_hash_map.go"):
|
||||
# ext = ExtractCodeBlocksGo()
|
||||
# res = ext.extract(code_path)
|
||||
# pass
|
||||
|
|
Loading…
Reference in a new issue