'Create a RegexpChunkRule from a string description.
Currently, the following formats are supported::
{regexp}         # chunk rule
}regexp{         # chink rule
regexp}{regexp   # split rule
regexp{}regexp   # merge rule
Where ``regexp`` is a regular expression for the rule.  Any
text following the comment marker (``#``) will be used as
the rule\'s description:
>>> from nltk.chunk.regexp import RegexpChunkRule
>>> RegexpChunkRule.fromstring(\'{<DT>?<NN.*>+}\')
<ChunkRule: \'<DT>?<NN.*>+\'>'

@staticmethod
def fromstring(s):

    m = re.match(u'(?P<rule>(\\\\.|[^#])*)(?P<comment>#.*)?', s)
    rule = m.group(u'rule').strip()
    comment = (m.group(u'comment') or u'')[1:].strip()
    try:
        if (not rule):
            raise ValueError(u'Empty    chunk    pattern')
        if ((rule[0] == u'{') and (rule[(-1)] == u'}')):
            return ChunkRule(rule[1:(-1)], comment)
        elif ((rule[0] == u'}') and (rule[(-1)] == u'{')):
            return ChinkRule(rule[1:(-1)], comment)
        elif (u'}{' in rule):
            (left, right) = rule.split(u'}{')
            return SplitRule(left, right, comment)
        elif (u'{}' in rule):
            (left, right) = rule.split(u'{}')
            return MergeRule(left, right, comment)
        elif re.match(u'[^{}]*{[^{}]*}[^{}]*', rule):
            (left, chunk, right) = re.split(u'[{}]', rule)
            return ChunkRuleWithContext(left, chunk, right, comment)
        else:
            raise ValueError((u'Illegal    chunk    pattern:    %s' % rule))
    except (ValueError, re.error):
        raise ValueError((u'Illegal    chunk    pattern:    %s' % rule))
