@yex.decorator.control(even_if_not_expanding=True)
def String(parser):
result = []
location = parser.location
def add(ch, with_escapechar=False):
if with_escapechar:
escapechar = parser.doc[r'\escapechar']
if escapechar>=0 and escapechar<=255:
add(chr(escapechar))
for c in ch:
result.append(
yex.parse.Token.get(
ch = c,
category = None, # i.e. Other or Space
location = location,
)
)
t = parser.next(level='deep')
logger.debug(
r'\string: token was %s of class %s',
t, t.__class__.__name__)
if isinstance(t, yex.parse.ControlName):
add(t.name, with_escapechar=True)
return result
try:
identifier = t.identifier
add(t.identifier[1:], with_escapechar=True)
return result
except AttributeError:
pass
try:
add(t.ch)
return result
except AttributeError:
pass
add(str(t))
return result