Esempio n. 1
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
                    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)
Esempio n. 2
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
                    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)