lex#

astropy.utils.parsing.lex(lextab, package, reflags=64)[source]#

Create a lexer from local variables.

It automatically compiles the lexer in optimized mode, writing to lextab in the same directory as the calling file.

This function is thread-safe. The returned lexer is not thread-safe, but if it is used exclusively with a single parser returned by yacc() then it will be safe.

It is only intended to work with lexers defined within the calling function, rather than at class or module scope.

Parameters:
lextabstr

Name for the file to write with the generated tables, if it does not already exist (without .py suffix).

packagestr

Name of a test package which should be run with pytest to regenerate the output file. This is inserted into a comment in the generated file.

reflagsint

Passed to ply.lex.