コード例 #1
0
 def GetExpectations(self):
   expects_file = join(self.root, 'preparser.expectation')
   map = {}
   if exists(expects_file):
     rule_regex = re.compile("^([\w\-]+)(?::([\w\-]+))?(?::(\d+),(\d+))?$")
     for line in utils.ReadLinesFrom(expects_file):
       if (line[0] == '#'): continue
       rule_match = rule_regex.match(line)
       if rule_match:
         expects = []
         if (rule_match.group(2)):
           expects = expects + [rule_match.group(2)]
           if (rule_match.group(3)):
             expects = expects + [rule_match.group(3), rule_match.group(4)]
         map[rule_match.group(1)] = expects
   return map;
コード例 #2
0
def ReadConfigurationInto(path, sections, defs):
    """Parses a .status file into specified sections and defs arguments."""
    current_section = Section(Constant(True))
    sections.append(current_section)
    prefix = []
    for line in utils.ReadLinesFrom(path):
        header_match = HEADER_PATTERN.match(line)
        if header_match:
            condition_str = header_match.group(1).strip()
            condition = ParseCondition(condition_str)
            new_section = Section(condition)
            sections.append(new_section)
            current_section = new_section
            continue
        rule_match = RULE_PATTERN.match(line)
        if rule_match:
            path = prefix + _SplitPath(rule_match.group(1).strip())
            value_str = rule_match.group(2).strip()
            value = ParseCondition(value_str)
            if not value:
                return False
            current_section.AddRule(Rule(rule_match.group(1), path, value))
            continue
        def_match = DEF_PATTERN.match(line)
        if def_match:
            name = def_match.group(1).lower()
            value = ParseCondition(def_match.group(2).strip())
            if not value:
                return False
            defs[name] = value
            continue
        prefix_match = PREFIX_PATTERN.match(line)
        if prefix_match:
            prefix = _SplitPath(prefix_match.group(1).strip())
            continue
        print 'Malformed line: "%s".' % line
        return False
    return True