@classmethod
def as_optional(cls):
    """Construct a copy of this class, but with the optional flag set true.

        Used in constructing grammars, will make an identical class
        but with the optional argument set to true. Used in constructing
        sequences.
        """
    classname = 'Optional_{0}'.format(cls.__name__)
    newclass = type(classname, (cls,), dict(optional=True))
    return newclass
