You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
These cannot be combined, since if you define a function to perform an action, the next remap attempt raises an error:
TypeError: 'function' object does not support item assignment
What is the recommended way to use both of these techniques in a lexical token?
I assume the function could examine the value of the match (say, the string in ID) with something like if t.value == 'if', but how to return a different token?
The text was updated successfully, but these errors were encountered:
The two techniques can't be combined. In fact, the whole token remapping feature was meant to replace the need for writing a function like this (which was commonplace):
keywords = { 'if', 'else', 'while' }
@_(r'[a-zA-Z_][a-zA-Z0-9_]*')
def ID(self, t):
if t.value in keywords:
t.type = t.value.upper()
return t
As shown in the function, the token type can be changed by assigning a different value to t.type.
From the examples, one can have actions when a lexical rules matches:
One can also remap tokens:
These cannot be combined, since if you define a function to perform an action, the next remap attempt raises an error:
What is the recommended way to use both of these techniques in a lexical token?
I assume the function could examine the
value
of the match (say, the string in ID) with something likeif t.value == 'if'
, but how to return a different token?The text was updated successfully, but these errors were encountered: