3 ms·
I wrote one of these a while back: http://knot.appspot.com/e/simple-python-scanner http://knot.appspot.com/e/simple-python-scanner For his example, it needs on
by blinks 18y ago
I wrote one of these a while back: http://knot.appspot.com/e/simple-python-scanner http://knot.appspot.com/e/simple-python-scanner
For his example, it needs one more line:
simple = Scan(
IDENTIFIER = r'[\w_]\w*',
OPERATOR = r'[-+\*=]',
DIGIT = r'\d+(\.\d+)?',
END_STATEMENT = r';',
SPACE = r'\s+',
)
simple.ignore('SPACE')
simple('foo = 5 * 30; bar = bar - 60;')
# generates tokens.