Example #1
0
 def parse_scope_definition(self, language, loaded_modules):
     scopes = {}
     scope_count = 0
     for params in self.scope_rules:
         if is_valid_definition(params, language):
             try:
                 bh_plugin.load_modules(params, loaded_modules)
                 entry = ScopeDefinition(params)
                 if not entry.enabled:
                     log(
                         SCOPE_ERROR % (
                             str(params.get('name', '?')),
                             "\\A" + params.get("open", ""),
                             params.get("close", "") + "\\Z"
                         )
                     )
                     continue
                 if not self.check_compare and entry.compare is not None:
                     self.check_compare = True
                 if not self.check_validate and entry.validate is not None:
                     self.check_validate = True
                 if not self.check_post_match and entry.post_match is not None:
                     self.check_post_match = True
                 if not self.highlighting and entry.highlighting is not None:
                     self.highlighting = True
                 for x in entry.scopes:
                     if x not in scopes:
                         scopes[x] = scope_count
                         scope_count += 1
                         self.scopes.append({"name": x, "brackets": [entry]})
                     else:
                         self.scopes[scopes[x]]["brackets"].append(entry)
                 )
             except Exception as e:
                 log(e)
Example #2
0
    def parse_scope_definition(self, language, loaded_modules):
        """
        Parse the scope defintion
        """

        scopes = {}
        scope_count = 0
        for params in self.scope_rules:
            if is_valid_definition(params, language):
                try:
                    bh_plugin.load_modules(params, loaded_modules)
                    entry = ScopeDefinition(params)
                    if not self.check_compare and entry.compare is not None:
                        self.check_compare = True
                    if not self.check_validate and entry.validate is not None:
                        self.check_validate = True
                    if not self.check_post_match and entry.post_match is not None:
                        self.check_post_match = True
                    if not self.highlighting and entry.highlighting is not None:
                        self.highlighting = True
                    for x in entry.scopes:
                        if x not in scopes:
                            scopes[x] = scope_count
                            scope_count += 1
                            self.scopes.append({"name": x, "brackets": [entry]})
                        else:
                            self.scopes[scopes[x]]["brackets"].append(entry)
                    debug("Scope Regex (%s)\n    Opening: %s\n    Closing: %s\n" % (entry.name, entry.open.pattern, entry.close.pattern))
                except Exception as e:
                    log(e)
    def parse_scope_definition(self, language, loaded_modules):
        """
        Parse the scope defintion
        """

        scopes = {}
        scope_count = 0
        for params in self.scope_rules:
            if is_valid_definition(params, language):
                try:
                    bh_plugin.load_modules(params, loaded_modules)
                    entry = ScopeDefinition(params)
                    if not self.check_compare and entry.compare is not None:
                        self.check_compare = True
                    if not self.check_validate and entry.validate is not None:
                        self.check_validate = True
                    if not self.check_post_match and entry.post_match is not None:
                        self.check_post_match = True
                    for x in entry.scopes:
                        if x not in scopes:
                            scopes[x] = scope_count
                            scope_count += 1
                            self.scopes.append({
                                "name": x,
                                "brackets": [entry]
                            })
                        else:
                            self.scopes[scopes[x]]["brackets"].append(entry)
                    debug(
                        "Scope Regex (%s)\n    Opening: %s\n    Closing: %s\n"
                        %
                        (entry.name, entry.open.pattern, entry.close.pattern))
                except Exception as e:
                    log(e)
Example #4
0
    def parse_bracket_definition(self, language, loaded_modules):
        """
        Parse the bracket defintion
        """

        names = []
        subnames = []
        find_regex = []
        sub_find_regex = []

        for params in self.bracket_rules:
            if is_valid_definition(params, language):
                try:
                    bh_plugin.load_modules(params, loaded_modules)
                    entry = BracketDefinition(params)
                    if not self.check_compare and entry.compare is not None:
                        self.check_compare = True
                    if not self.check_validate and entry.validate is not None:
                        self.check_validate = True
                    if not self.check_post_match and entry.post_match is not None:
                        self.check_post_match = True
                    if not self.highlighting and entry.highlighting is not None:
                        self.highlighting = True
                    self.brackets.append(entry)
                    if not entry.find_in_sub_search_only:
                        find_regex.append(params["open"])
                        find_regex.append(params["close"])
                        names.append(params["name"])
                    else:
                        find_regex.append(r"([^\s\S])")
                        find_regex.append(r"([^\s\S])")

                    if entry.find_in_sub_search:
                        sub_find_regex.append(params["open"])
                        sub_find_regex.append(params["close"])
                        subnames.append(params["name"])
                    else:
                        sub_find_regex.append(r"([^\s\S])")
                        sub_find_regex.append(r"([^\s\S])")
                except Exception as e:
                    log(e)

        if len(self.brackets):
            self.brackets = tuple(self.brackets)
            debug(
                "Bracket Pattern: (%s)\n" % ','.join(names) +
                "    (Opening|Closing):     (?:%s)\n" % '|'.join(find_regex)
            )
            debug(
                "SubBracket Pattern: (%s)\n" % ','.join(subnames) +
                "    (Opening|Closing): (?:%s)\n" % '|'.join(sub_find_regex)
            )
            self.sub_pattern = ure.compile("(?:%s)" % '|'.join(sub_find_regex), ure.MULTILINE | ure.IGNORECASE)
            self.pattern = ure.compile("(?:%s)" % '|'.join(find_regex), ure.MULTILINE | ure.IGNORECASE)
Example #5
0
    def parse_bracket_definition(self, language, loaded_modules):
        """
        Parse the bracket defintion
        """

        names = []
        subnames = []
        find_regex = []
        sub_find_regex = []

        for params in self.bracket_rules:
            if is_valid_definition(params, language):
                try:
                    bh_plugin.load_modules(params, loaded_modules)
                    entry = BracketDefinition(params)
                    if not self.check_compare and entry.compare is not None:
                        self.check_compare = True
                    if not self.check_validate and entry.validate is not None:
                        self.check_validate = True
                    if not self.check_post_match and entry.post_match is not None:
                        self.check_post_match = True
                    if not self.highlighting and entry.highlighting is not None:
                        self.highlighting = True
                    self.brackets.append(entry)
                    if not entry.find_in_sub_search_only:
                        find_regex.append(params["open"])
                        find_regex.append(params["close"])
                        names.append(params["name"])
                    else:
                        find_regex.append(r"([^\s\S])")
                        find_regex.append(r"([^\s\S])")

                    if entry.find_in_sub_search:
                        sub_find_regex.append(params["open"])
                        sub_find_regex.append(params["close"])
                        subnames.append(params["name"])
                    else:
                        sub_find_regex.append(r"([^\s\S])")
                        sub_find_regex.append(r"([^\s\S])")
                except Exception as e:
                    log(e)

        if len(self.brackets):
            self.brackets = tuple(self.brackets)
            debug("Bracket Pattern: (%s)\n" % ','.join(names) +
                  "    (Opening|Closing):     (?:%s)\n" % '|'.join(find_regex))
            debug("SubBracket Pattern: (%s)\n" % ','.join(subnames) +
                  "    (Opening|Closing): (?:%s)\n" % '|'.join(sub_find_regex))
            self.sub_pattern = ure.compile("(?:%s)" % '|'.join(sub_find_regex),
                                           ure.MULTILINE | ure.IGNORECASE)
            self.pattern = ure.compile("(?:%s)" % '|'.join(find_regex),
                                       ure.MULTILINE | ure.IGNORECASE)
Example #6
0
    def parse_scope_definition(self, language, loaded_modules):
        """Parse the scope definition."""

        scopes = {}
        scope_count = 0
        for params in self.scope_rules:
            if is_valid_definition(params, language):
                try:
                    bh_plugin.load_modules(params, loaded_modules)
                    entry = ScopeDefinition(params)
                    if not entry.enabled:
                        log(
                            SCOPE_ERROR % (
                                str(params.get('name', '?')),
                                "\\A" + params.get("open", ""),
                                params.get("close", "") + "\\Z"
                            )
                        )
                        continue
                    if not self.check_compare and entry.compare is not None:
                        self.check_compare = True
                    if not self.check_validate and entry.validate is not None:
                        self.check_validate = True
                    if not self.check_post_match and entry.post_match is not None:
                        self.check_post_match = True
                    if not self.highlighting and entry.highlighting is not None:
                        self.highlighting = True
                    for x in entry.scopes:
                        if x not in scopes:
                            scopes[x] = scope_count
                            scope_count += 1
                            self.scopes.append({"name": x, "brackets": [entry]})
                        else:
                            self.scopes[scopes[x]]["brackets"].append(entry)
                    debug(
                        "Scope Regex (%s)\n    Opening: %s\n    Closing: %s\n" % (
                            entry.name, entry.open.pattern, entry.close.pattern
                        )
                    )
                except Exception as e:
                    log(e)
Example #7
0
 def parse_bracket_definition(self, language, loaded_modules):
     names = []
     subnames = []
     find_regex = []
     sub_find_regex = []
     self.sub_pattern = None
     self.pattern = None
     for params in self.bracket_rules:
         if is_valid_definition(params, language):
             try:
                 bh_plugin.load_modules(params, loaded_modules)
                 entry = BracketDefinition(params)
                 if not self.check_compare and entry.compare is not None:
                     self.check_compare = True
                 if not self.check_validate and entry.validate is not None:
                     self.check_validate = True
                 if not self.check_post_match and entry.post_match is not None:
                     self.check_post_match = True
                 if not self.highlighting and entry.highlighting is not None:
                     self.highlighting = True
                 self.brackets.append(entry)
                 if not entry.find_in_sub_search_only:
                     find_regex.append(params["open"])
                     find_regex.append(params["close"])
                     names.append(params["name"])
                 else:
                     find_regex.append(r"([^\s\S])")
                     find_regex.append(r"([^\s\S])")
                 if entry.find_in_sub_search:
                     sub_find_regex.append(params["open"])
                     sub_find_regex.append(params["close"])
                     subnames.append(params["name"])
                 else:
                     sub_find_regex.append(r"([^\s\S])")
                     sub_find_regex.append(r"([^\s\S])")
             except Exception as e:
                 log(e)
     if len(self.brackets):
         self.brackets = tuple(self.brackets)
         self.sub_pattern = bre.compile_search("(?:%s)" % '|'.join(sub_find_regex), bre.MULTILINE | bre.IGNORECASE)
         self.pattern = bre.compile_search("(?:%s)" % '|'.join(find_regex), bre.MULTILINE | bre.IGNORECASE)
         if (
             self.sub_pattern.groups != len(sub_find_regex) or
             self.pattern.groups != len(find_regex)
         ):
             if self.sub_pattern.groups != len(sub_find_regex):
                 log(
                     BRACKET_ERROR % (
                         len(sub_find_regex),
                         'sub-pattern',
                         self.sub_pattern.groups,
                         "(?:%s)" % '|'.join(sub_find_regex)
                     )
                 )
             if self.pattern.groups != len(find_regex):
                 log(
                     BRACKET_ERROR % (
                         len(find_regex),
                         'pattern',
                         self.pattern.groups,
                         "(?:%s)" % '|'.join(find_regex)
                     )
                 )
             self.brackets = []
             self.sub_pattern = None
             self.pattern = None