Instead of producing a big message with all ABI contents and then parse as a whole, simplify the code by handling each ABI symbol in separate. As an additional benefit, there's no need to place file/line nubers inlined at the data and use a regex to convert them.
Showing the changes to scripts (2 of 3 files). Show all
Unified · Split
| @@ -63,8 +63,11 @@ class AbiRest: · 62 unmodified lines | |||
| 63 | parser.parse_abi() | 63 | parser.parse_abi() |
| 64 | parser.check_issues() | 64 | parser.check_issues() |
| 65 | 65 | ||
| 66 | for msg in parser.doc(args.enable_lineno, args.raw, not args.no_file): | 66 | for t in parser.doc(args.raw, not args.no_file): |
| 67 | print(msg) | 67 | if args.enable_lineno: |
| 68 | print (f".. LINENO {t[1]}#{t[2]}\n\n") | ||
| 69 | |||
| 70 | print(t[0]) | ||
| 68 | 71 | ||
| 69 | class AbiValidate: | 72 | class AbiValidate: |
| 70 | """Initialize an argparse subparser for ABI validation""" | 73 | """Initialize an argparse subparser for ABI validation""" |
| @@ -427,7 +427,7 @@ class AbiParser: · 426 unmodified lines | |||
| 427 | 427 | ||
| 428 | return new_desc + "\n\n" | 428 | return new_desc + "\n\n" |
| 429 | 429 | ||
| 430 | def doc(self, enable_lineno, output_in_txt=False, show_file=False): | 430 | def doc(self, output_in_txt=False, show_file=True): |
| 431 | """Print ABI at stdout""" | 431 | """Print ABI at stdout""" |
| 432 | 432 | ||
| 433 | part = None | 433 | part = None |
| @@ -444,10 +444,6 @@ class AbiParser: · 10 unmodified lines | |||
| 444 | 444 | ||
| 445 | msg = "" | 445 | msg = "" |
| 446 | 446 | ||
| 447 | if enable_lineno: | ||
| 448 | ln = v.get("line_no", 1) | ||
| 449 | msg += f".. LINENO {file_ref[0][0]}#{ln}\n\n" | ||
| 450 | |||
| 451 | if wtype != "File": | 447 | if wtype != "File": |
| 452 | cur_part = names[0] | 448 | cur_part = names[0] |
| 453 | if cur_part.find("/") >= 0: | 449 | if cur_part.find("/") >= 0: |
| @@ -508,7 +504,9 @@ class AbiParser: · 54 unmodified lines | |||
| 508 | if users and users.strip(" \t\n"): | 504 | if users and users.strip(" \t\n"): |
| 509 | msg += f"Users:\n\t{users.strip("\n").replace('\n', '\n\t')}\n\n" | 505 | msg += f"Users:\n\t{users.strip("\n").replace('\n', '\n\t')}\n\n" |
| 510 | 506 | ||
| 511 | yield msg | 507 | ln = v.get("line_no", 1) |
| 508 | |||
| 509 | yield (msg, file_ref[0][0], ln) | ||
| 512 | 510 | ||
| 513 | def check_issues(self): | 511 | def check_issues(self): |
| 514 | """Warn about duplicated ABI entries""" | 512 | """Warn about duplicated ABI entries""" |