Exemple #1
0
def intersperse_parser(parser_list: list,
                       interspersed: pp.ParserElement) -> pp.ParserElement:
    ret = interspersed.copy()
    for i in parser_list:
        ret = ret + i.copy() + interspersed.copy()

    return ret
Exemple #2
0
    def _create_optional_argument(self,
                                  name_list: list,
                                  arg_name: str,
                                  value_parser: pp.ParserElement,
                                  help_text=None,
                                  optional=True):

        arg = pp.MatchFirst([pp.CaselessKeyword(i) for i in name_list
                             ]).setParseAction(lambda x: arg_name)

        # It is important that the ParseAction is inside the Optional! Otherwise we will get errors if it does not
        # match.
        complete = (arg + value_parser.copy()).setName(
            arg_name).setParseAction(lambda x: {x[0]: x[1]})(arg_name)
        if optional:
            complete = pp.Optional(complete)
        return self._arg_info(complete, arg_name, name_list, help_text)