MCPcopy Index your code
hub / github.com/python/cpython / BlockParser

Class BlockParser

Tools/clinic/libclinic/block_parser.py:86–256  ·  view source on GitHub ↗

Block-oriented parser for Argument Clinic. Iterator, yields Block objects.

Source from the content-addressed store, hash-verified

84
85
86class BlockParser:
87 """
88 Block-oriented parser for Argument Clinic.
89 Iterator, yields Block objects.
90 """
91
92 def __init__(
93 self,
94 input: str,
95 language: Language,
96 *,
97 verify: bool = True
98 ) -> None:
99 """
100 "input" should be a str object
101 with embedded \n characters.
102
103 "language" should be a Language object.
104 """
105 language.validate()
106
107 self.input = collections.deque(reversed(input.splitlines(keepends=True)))
108 self.block_start_line_number = self.line_number = 0
109
110 self.language = language
111 before, _, after = language.start_line.partition('{dsl_name}')
112 assert _ == '{dsl_name}'
113 self.find_start_re = libclinic.create_regex(before, after,
114 whole_line=False)
115 self.start_re = libclinic.create_regex(before, after)
116 self.verify = verify
117 self.last_checksum_re: re.Pattern[str] | None = None
118 self.last_dsl_name: str | None = None
119 self.dsl_name: str | None = None
120 self.first_block = True
121
122 def __iter__(self) -> BlockParser:
123 return self
124
125 def __next__(self) -> Block:
126 while True:
127 if not self.input:
128 raise StopIteration
129
130 if self.dsl_name:
131 try:
132 return_value = self.parse_clinic_block(self.dsl_name)
133 except ClinicError as exc:
134 exc.filename = self.language.filename
135 exc.lineno = self.line_number
136 raise
137 self.dsl_name = None
138 self.first_block = False
139 return return_value
140 block = self.parse_verbatim_block()
141 if self.first_block and not block.input:
142 continue
143 self.first_block = False

Callers 4

_make_clinicFunction · 0.90
_testMethod · 0.90
parse_fileFunction · 0.90
parseMethod · 0.90

Calls

no outgoing calls

Tested by 2

_make_clinicFunction · 0.72
_testMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…