mirror of
https://gitlab.freedesktop.org/libinput/libei.git
synced 2026-01-08 22:10:16 +01:00
scanner: parse the descriptions as well
This commit is contained in:
parent
164b2c0c00
commit
c8986b88ba
1 changed files with 26 additions and 1 deletions
|
|
@ -19,6 +19,7 @@ appear in the XML file.
|
|||
|
||||
from typing import Optional, Union, Tuple
|
||||
from pathlib import Path
|
||||
from textwrap import dedent
|
||||
|
||||
import argparse
|
||||
import attr
|
||||
|
|
@ -52,6 +53,12 @@ def snake2camel(s: str) -> str:
|
|||
return s.replace("_", " ").title().replace(" ", "")
|
||||
|
||||
|
||||
@attr.s
|
||||
class Description:
|
||||
summary: str = attr.ib(default="")
|
||||
text: str = attr.ib(default="")
|
||||
|
||||
|
||||
@attr.s
|
||||
class Argument:
|
||||
"""
|
||||
|
|
@ -126,6 +133,7 @@ class Message:
|
|||
since: int = attr.ib()
|
||||
opcode: int = attr.ib()
|
||||
interface: "Interface" = attr.ib()
|
||||
description: Optional[Description] = attr.ib(default=None)
|
||||
is_destructor: bool = attr.ib(default=False)
|
||||
|
||||
arguments: list[Argument] = attr.ib(init=False, factory=list)
|
||||
|
|
@ -234,6 +242,7 @@ class Enum:
|
|||
since: int = attr.ib()
|
||||
interface: "Interface" = attr.ib()
|
||||
is_bitmask: bool = attr.ib(default=False)
|
||||
description: Optional[Description] = attr.ib(default=None)
|
||||
|
||||
entries: list[Entry] = attr.ib(init=False, factory=list)
|
||||
|
||||
|
|
@ -275,12 +284,13 @@ class Enum:
|
|||
class Interface:
|
||||
name: str = attr.ib()
|
||||
version: int = attr.ib()
|
||||
|
||||
requests: list[Request] = attr.ib(init=False, factory=list)
|
||||
events: list[Event] = attr.ib(init=False, factory=list)
|
||||
enums: list[Enum] = attr.ib(init=False, factory=list)
|
||||
|
||||
mode: str = attr.ib() # "ei" or "eis"
|
||||
description: Optional[Description] = attr.ib(default=None)
|
||||
|
||||
|
||||
def add_request(self, request: Request) -> None:
|
||||
if request.name in [r.name for r in self.requests]:
|
||||
|
|
@ -377,6 +387,7 @@ class ProtocolParser(xml.sax.handler.ContentHandler):
|
|||
|
||||
current_interface: Optional[Interface] = attr.ib(init=False, default=None)
|
||||
current_message: Optional[Union[Message, Enum]] = attr.ib(init=False, default=None)
|
||||
current_description: Optional[Description] = attr.ib(init=False, default=None)
|
||||
|
||||
_run_counter: int = attr.ib(init=False, default=0, repr=False)
|
||||
|
||||
|
|
@ -599,6 +610,9 @@ class ProtocolParser(xml.sax.handler.ContentHandler):
|
|||
self.current_message.add_entry(entry)
|
||||
except ValueError as e:
|
||||
raise XmlError.create(str(e), self.location)
|
||||
elif element == "description":
|
||||
summary = attrs.get("summary", "")
|
||||
self.current_description = Description(summary=summary)
|
||||
|
||||
def endElement(self, name):
|
||||
if name == "interface":
|
||||
|
|
@ -618,8 +632,19 @@ class ProtocolParser(xml.sax.handler.ContentHandler):
|
|||
elif name == "enum":
|
||||
assert isinstance(self.current_message, Enum)
|
||||
self.current_message = None
|
||||
elif name == "description":
|
||||
assert self.current_description is not None
|
||||
self.current_description.text = dedent(self.current_description.text)
|
||||
if self.current_message is None:
|
||||
assert self.current_interface is not None
|
||||
self.current_interface.description = self.current_description
|
||||
else:
|
||||
self.current_message.description = self.current_description
|
||||
self.current_description = None
|
||||
|
||||
def characters(self, content):
|
||||
if self.current_description is not None:
|
||||
self.current_description.text += content
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue