tor-browser

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

ReservedWordReader.py (1278B)


      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 http://mozilla.org/MPL/2.0/.
      4 
      5 import re
      6 
      7 
      8 def read_reserved_word_list(filename, *args):
      9 
     10    enable_decorators = False
     11    enable_explicit_resource_management = False
     12 
     13    for arg in args:
     14        if arg == "--enable-decorators":
     15            enable_decorators = True
     16        elif arg == "--enable-explicit-resource-management":
     17            enable_explicit_resource_management = True
     18        else:
     19            raise ValueError("Unknown argument: " + arg)
     20 
     21    macro_pat = re.compile(r"MACRO\(([^,]+), *[^,]+, *[^\)]+\)\s*\\?")
     22 
     23    reserved_word_list = []
     24    index = 0
     25    with open(filename) as f:
     26        for line in f:
     27            m = macro_pat.search(line)
     28            if m:
     29                reserved_word = m.group(1)
     30                if reserved_word == "accessor" and not enable_decorators:
     31                    continue
     32                if reserved_word == "using" and not enable_explicit_resource_management:
     33                    continue
     34                reserved_word_list.append((index, reserved_word))
     35                index += 1
     36 
     37    assert len(reserved_word_list) != 0
     38 
     39    return reserved_word_list