Meta: Add limited parsing for WebIDL dictionaries
For now, this is limited as we do not parse the contents of the dictionary and only extract the dictionary names.
This commit is contained in:
parent
f44fc34737
commit
265559c5b5
1 changed files with 37 additions and 1 deletions
|
|
@ -58,10 +58,17 @@ class Interface:
|
|||
self.namespace_class = f"{self.name}Namespace"
|
||||
|
||||
|
||||
@dataclass
|
||||
class Dictionary:
|
||||
name: str
|
||||
path: Path
|
||||
|
||||
|
||||
@dataclass
|
||||
class Module:
|
||||
path: Path
|
||||
interface: Optional[Interface] = None
|
||||
dictionaries: List[Dictionary] = field(default_factory=list)
|
||||
|
||||
|
||||
@dataclass
|
||||
|
|
@ -117,7 +124,9 @@ class Parser:
|
|||
extended_attributes = self.parse_extended_attributes()
|
||||
|
||||
if self.next_is_keyword("dictionary") or self.next_is_keyword("partial dictionary"):
|
||||
self.skip_braced_declaration()
|
||||
dictionary = self.parse_dictionary()
|
||||
if dictionary is not None:
|
||||
module.dictionaries.append(dictionary)
|
||||
elif self.next_is_keyword("enum"):
|
||||
self.skip_braced_declaration()
|
||||
elif self.next_is_keyword("typedef"):
|
||||
|
|
@ -223,6 +232,33 @@ class Parser:
|
|||
interface.finalize()
|
||||
return interface
|
||||
|
||||
def parse_dictionary(self) -> Optional[Dictionary]:
|
||||
is_partial = False
|
||||
if self.next_is_keyword("partial"):
|
||||
self.consume_keyword("partial")
|
||||
self.consume_whitespace()
|
||||
is_partial = True
|
||||
|
||||
self.consume_keyword("dictionary")
|
||||
self.consume_whitespace()
|
||||
|
||||
dictionary_name = self.parse_identifier_ending_with_space_or(":", "{")
|
||||
self.consume_whitespace()
|
||||
|
||||
if self.lexer.consume_specific(":"):
|
||||
self.consume_whitespace()
|
||||
self.parse_identifier_ending_with_space_or("{")
|
||||
self.consume_whitespace()
|
||||
|
||||
self.consume_braced_block()
|
||||
self.consume_whitespace()
|
||||
self.assert_specific(";")
|
||||
|
||||
if is_partial:
|
||||
return None
|
||||
|
||||
return Dictionary(name=dictionary_name, path=self.path)
|
||||
|
||||
def parse_interface_body(self, interface: Interface, body_text: str) -> None:
|
||||
for statement in split_top_level_statements(remove_line_comments(body_text)):
|
||||
if not statement:
|
||||
|
|
|
|||
Loading…
Reference in a new issue