def _expose_rule_functions(self, expose_all_rules=False):
def make_parse_rule_function(rule_name):<EOL><INDENT>"<STR_LIT>"<EOL>def rule_fxn(s):<EOL><INDENT>try:<EOL><INDENT>return self._grammar(s).__getattr__(rule_name)()<EOL><DEDENT>except ometa.runtime.ParseError as exc:<EOL><INDENT>raise HGVSParseError("<STR_LIT>".format(<EOL>s=s, exc=exc, reason=exc.formatReason()))<EOL><DEDENT><DEDENT>rule_fxn.__doc__ = "<STR_LIT>" % rule_name<EOL>return rule_fxn<EOL><DEDENT>exposed_rule_re = re.compile(r"<STR_LIT>"<EOL>r"<STR_LIT>")<EOL>exposed_rules = [<EOL>m.replace("<STR_LIT>", "<STR_LIT>") for m in dir(self._grammar._grammarClass)<EOL>if m.startswith("<STR_LIT>")<EOL>]<EOL>if not expose_all_rules:<EOL><INDENT>exposed_rules = [<EOL>rule_name for rule_name in exposed_rules if exposed_rule_re.match(rule_name)<EOL>]<EOL><DEDENT>for rule_name in exposed_rules:<EOL><INDENT>att_name = "<STR_LIT>" + rule_name<EOL>rule_fxn = make_parse_rule_function(rule_name)<EOL>self.__setattr__(att_name, rule_fxn)<EOL><DEDENT>self._logger.debug("<STR_LIT>".format(<EOL>n=len(exposed_rules), rules="<STR_LIT:U+002CU+0020>".join(exposed_rules)))<EOL>
add parse functions for public grammar rules

        Defines a function for each public grammar rule, based on
        introspecting the grammar. For example, the `c_interval` rule
        is exposed as a method `parse_c_interval` and used like this::

          Parser.parse_c_interval('26+2_57-3') -> Interval(...)