Lines Matching +full:in +full:- +full:line

1 # -*- coding: utf-8 -*-
6 # Copyright (c) 2013-2019 Red Hat Inc.
11 # Marc-André Lureau <marcandre.lureau@redhat.com>
15 # See the COPYING file in the top-level directory.
38 # pylint: disable=cyclic-import
39 # TODO: Remove cycle. [schema -> expr -> parser -> schema]
48 # pylint: disable=too-few-public-methods
62 for ch in parser.src[parser.line_pos:parser.pos]:
74 Parse a JSON-esque schema file and process directives. See
75 qapi-code-gen.rst section "Schema Syntax" for the exact syntax.
90 :raise QAPIError: For errors in the schema source.
116 def _parse(self) -> None:
120 :return: None. Results are stored in ``.exprs`` and ``.docs``.
125 with open(self._fname, 'r', encoding='utf-8') as fp:
127 if self.src == '' or self.src[-1] != '\n':
145 info, "top-level expression must be an object")
147 if 'include' in expr:
163 elif "pragma" in expr:
171 for name, value in pragma.items():
183 doc: Optional['QAPIDoc'] = None) -> None:
187 def reject_expr_doc(doc: Optional['QAPIDoc']) -> None:
199 ) -> Optional['QAPISchemaParser']:
209 if incl_abs_fname in previously_included:
221 def _pragma(name: str, value: object, info: QAPISourceInfo) -> None:
223 def check_list_str(name: str, value: object) -> List[str]:
225 any(not isinstance(elt, str) for elt in value)):
233 if name == 'doc-required':
236 "pragma 'doc-required' must be boolean")
238 elif name == 'command-name-exceptions':
240 elif name == 'command-returns-exceptions':
242 elif name == 'documentation-exceptions':
244 elif name == 'member-name-exceptions':
249 def accept(self, skip_comment: bool = True) -> None:
260 - ``.tok`` represents the token type. See below for values.
261 - ``.info`` describes the token's source location.
262 - ``.val`` is the token's value, if any. See below.
263 - ``.pos`` is the buffer index of the first character of
266 * Single-character tokens:
271 * Multi-character tokens:
277 ``.val`` is a string including all chars until end-of-line,
308 elif self.tok in '{}:,[]':
321 # no use for funny characters in strings
334 self, "funny character in string")
354 self.src[self.cursor-1:])
357 def get_members(self) -> Dict[str, object]:
372 if key in expr:
384 def get_values(self) -> List[object]:
389 if self.tok not in tuple("{['tf"):
401 def get_expr(self) -> _ExprValue:
409 elif self.tok in tuple("'tf"):
418 def get_doc_line(self) -> Optional[str]:
436 def _match_at_name_colon(string: str) -> Optional[Match[str]]:
439 def get_doc_indented(self, doc: 'QAPIDoc') -> Optional[str]:
441 line = self.get_doc_line()
442 while line == '':
443 doc.append_line(line)
445 line = self.get_doc_line()
446 if line is None:
447 return line
448 indent = must_match(r'\s*', line).end()
450 return line
451 doc.append_line(line)
455 line = self.get_doc_line()
456 if line is None:
457 return line
458 if self._match_at_name_colon(line):
459 return line
460 cur_indent = must_match(r'\s*', line).end()
461 if line != '' and cur_indent < indent:
463 return line
466 "unexpected de-indent (expected at least %d spaces)" %
468 doc.append_line(line)
471 def get_doc_paragraph(self, doc: 'QAPIDoc') -> Optional[str]:
474 line = self.get_doc_line()
475 if line is None:
476 return line
477 if line == '':
478 return line
479 doc.append_line(line)
481 def get_doc(self) -> 'QAPIDoc':
487 line = self.get_doc_line()
488 if line is not None and line.startswith('@'):
490 if not line.endswith(':'):
491 raise QAPIParseError(self, "line should end with ':'")
494 # which *is* validated in expr.py.
495 symbol = line[1:-1]
500 line = self.get_doc_line()
503 while line is not None:
505 while line == '':
507 line = self.get_doc_line()
508 if line is None:
510 # Non-blank line, first of a section
511 if line == 'Features:':
514 self, "duplicated 'Features:' line")
516 line = self.get_doc_line()
517 while line == '':
519 line = self.get_doc_line()
520 while (line is not None
521 and (match := self._match_at_name_colon(line))):
523 text = line[match.end():]
526 line = self.get_doc_indented(doc)
531 elif match := self._match_at_name_colon(line):
538 while (line is not None
539 and (match := self._match_at_name_colon(line))):
541 text = line[match.end():]
544 line = self.get_doc_indented(doc)
549 line,
556 # TODO: Remove these errors sometime in 2025 or so
560 # See commit message for more markup suggestions O:-)
561 if 'Note' in match.group(1):
570 if 'Example' in match.group(1):
573 "supported. Please use the '.. qmp-example::' "
579 text = line[match.end():]
582 line = self.get_doc_indented(doc)
584 elif line.startswith('='):
587 "unexpected '=' markup in definition documentation")
589 # tag-less paragraph
591 doc.append_line(line)
592 line = self.get_doc_paragraph(doc)
594 # Free-form documentation
598 while line is not None:
599 if match := self._match_at_name_colon(line):
602 "'@%s:' not allowed in free-form documentation"
604 if line.startswith('='):
608 "'=' heading must come first in a comment block")
609 doc.append_line(line)
611 line = self.get_doc_line()
621 A documentation comment block, either definition or free-form
625 * a body section: one line naming the definition, followed by an
633 * additional (non-argument) sections, possibly tagged
635 Free-form documentation blocks consist only of a body section.
639 # pylint: disable=too-few-public-methods
649 def append_line(self, line: str) -> None:
650 self.text += line + '\n'
657 def connect(self, member: 'QAPISchemaMember') -> None:
661 # info points to the doc comment block's first line
663 # definition doc's symbol, None for free-form doc
665 # the sections in textual order
680 def end(self) -> None:
681 for section in self.all_sections:
687 def ensure_untagged_section(self, info: QAPISourceInfo) -> None:
688 if self.all_sections and not self.all_sections[-1].tag:
690 self.all_sections[-1].text += '\n'
697 def new_tagged_section(self, info: QAPISourceInfo, tag: str) -> None:
718 desc: Dict[str, ArgSection]) -> None:
721 if name in desc:
727 def new_argument(self, info: QAPISourceInfo, name: str) -> None:
730 def new_feature(self, info: QAPISourceInfo, name: str) -> None:
733 def append_line(self, line: str) -> None:
734 self.all_sections[-1].append_line(line)
736 def connect_member(self, member: 'QAPISchemaMember') -> None:
737 if member.name not in self.args:
739 if self.symbol not in member.info.pragma.documentation_exceptions:
747 def connect_feature(self, feature: 'QAPISchemaFeature') -> None:
748 if feature.name not in self.features:
754 def check_expr(self, expr: QAPIExpression) -> None:
755 if 'command' in expr:
756 if self.returns and 'returns' not in expr:
770 def check(self) -> None:
774 ) -> None:
775 bogus = [name for name, section in args.items()