

def _read_grammar(self, grammar, root_label, trace):
    '\n        Helper function for __init__: read the grammar if it is a\n        string.\n        '
    rules = []
    lhs = None
    for line in grammar.split('\n'):
        line = line.strip()
        m = re.match('(?P<nonterminal>(\\.|[^:])*)(:(?P<rule>.*))', line)
        if m:
            self._add_stage(rules, lhs, root_label, trace)
            lhs = m.group('nonterminal').strip()
            rules = []
            line = m.group('rule').strip()
        if ((line == '') or line.startswith('#')):
            continue
        rules.append(RegexpChunkRule.fromstring(line))
    self._add_stage(rules, lhs, root_label, trace)

dataset/ETHPy150Open nltk/nltk/nltk/chunk/regexp.py RegexpParser._read_grammar/original