MCPcopy Create free account
hub / github.com/ElementsProject/lightning / gather_quotes

Function gather_quotes

devtools/check_quotes.py:76–125  ·  view source on GitHub ↗
(args: Namespace)

Source from the content-addressed store, hash-verified

74
75# We expect lines to start with '# BOLT #NN:'
76def gather_quotes(args: Namespace) -> Dict[int, List[Quote]]:
77 boltquotes: Dict[int, List[Quote]] = {}
78 curquote = None
79 # These initializations simply keep flake8 happy
80 curbolt = 0
81 filestart = ""
82 linestart = 0
83 for file_line in fileinput.input(args.files):
84 line = file_line.strip()
85 boltnum, quote = get_boltstart(
86 args, line, fileinput.filename(), fileinput.filelineno()
87 )
88 if boltnum is not None:
89 if curquote is not None:
90 add_quote(boltquotes, curbolt, filestart, linestart, curquote)
91
92 linestart = fileinput.filelineno()
93 filestart = fileinput.filename()
94 curbolt = boltnum
95 curquote = quote
96 # Handle single-line comment: /* BOLT #N: text */
97 if args.comment_end is not None:
98 stripped = curquote.rstrip()
99 if stripped.endswith(args.comment_end):
100 curquote = stripped[: -len(args.comment_end)]
101 add_quote(boltquotes, curbolt, filestart, linestart, curquote)
102 curquote = None
103 elif curquote is not None:
104 # If this is a continuation (and not an end!), add it.
105 if (
106 args.comment_end is None or not line.startswith(args.comment_end)
107 ) and line.startswith(args.comment_continue):
108 # Special case where end marker is on same line.
109 if args.comment_end is not None and line.endswith(args.comment_end):
110 curquote += (
111 " " + line[len(args.comment_continue):-len(args.comment_end)]
112 )
113 add_quote(boltquotes, curbolt, filestart, linestart, curquote)
114 curquote = None
115 else:
116 curquote += " " + line[len(args.comment_continue):]
117 else:
118 add_quote(boltquotes, curbolt, filestart, linestart, curquote)
119 curquote = None
120
121 # Handle quote at eof.
122 if curquote is not None:
123 add_quote(boltquotes, curbolt, filestart, linestart, curquote)
124
125 return boltquotes
126
127
128def load_bolt(boltdir: str, num: int) -> List[str]:

Callers 1

mainFunction · 0.85

Calls 2

get_boltstartFunction · 0.85
add_quoteFunction · 0.85

Tested by

no test coverage detected