def lit(literal: Sequence[Input], *literals: Sequence[Sequence[Input]]) -> Parser:
"""Match a literal sequence.
In the `TextParsers`` context, this matches the literal string
provided. In the ``GeneralParsers`` context, this matches a sequence of
input.
If multiple literals are provided, they are treated as alternatives. e.g.
``lit('+', '-')`` is the same as ``lit('+') | lit('-')``.
Args:
literal: A literal to match
*literals: Alternative literals to match
Returns:
A ``LiteralParser`` in the ``GeneralContext``, a ``LiteralStringParser``
in the ``TextParsers`` context, and an ``AlternativeParser`` if multiple
arguments are provided.
"""
if len(literals) > 0:
return AlternativeParser(options.handle_literal(literal), *map(options.handle_literal, literals))
else:
return options.handle_literal(literal)
评论列表
文章目录