tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

GenerateEventListFromHeaders.py (1349B)


      1 # This Source Code Form is subject to the terms of the Mozilla Public
      2 # License, v. 2.0. If a copy of the MPL was not distributed with this
      3 # file, You can obtain one at https://mozilla.org/MPL/2.0/.
      4 
      5 """
      6 This script parses mozilla-central's EventNameList.h and writes a JSON-formatted equivalent
      7 in order to guess if a DOM Event name is implemented by Gecko:
      8  "devtools/server/event-list.json"
      9 
     10 Run this script via
     11 
     12 > ./mach python devtools/server/GenerateEventListFromHeaders.py dom/events/EventNameList.h
     13 """
     14 
     15 import json
     16 import re
     17 import sys
     18 
     19 
     20 def main(output_file, event_name_list_h):
     21    events = []
     22    with open(event_name_list_h, encoding="utf8") as f:
     23        text = f.read()
     24        # Match all lines following this syntax:
     25        #   xxx_EVENT(name, message, type, struct)
     26        #
     27        # "type" may include logical expression like "(EventNameType_HTMLXUL | EventNameType_SVGSVG)"
     28        matches = re.findall(
     29            r"^((\w+)?EVENT)\((\w+),\s+(\w+),\s+([(\\|\) \w]+),\s+(\w+)\)",
     30            text,
     31            re.MULTILINE,
     32        )
     33        for category, _, name, message, type, struct in matches:
     34            events.append(name)
     35 
     36    output_file.write(json.dumps(events, indent=2, sort_keys=True))
     37 
     38    print("Successfully generated event list for DevTools")
     39 
     40 
     41 if __name__ == "__main__":
     42    main(sys.stdout, sys.argv[1])