Expression lexer

Write codeMedium30 minDatabricks and Snowflake style

Your task

Write a lexer for a small expression language. Given a source string, produce a list of [type, value] tokens. Token types: 'NUM' for integer or decimal numbers (digits with at most one optional internal dot, e.g. '12', '3.14'), 'ID' for identifiers (a letter or underscore followed by letters/digits/underscores), 'OP' for any of the single chars + - * / ( ) = , and 'WS' is skipped (spaces and tabs are ignored, never emitted). The value of a NUM/ID token is the matched substring; the value of an OP is the single char. Unknown characters never occur. Return the token list in order.

Examples

tokenize_expr(src: str) -> list[list]
Example 1
Inputtokenize_expr("x = 3.14 + y2")
Output[["ID", "x"], ["OP", "="], ["NUM", "3.14"], ["OP", "+"], ["ID", "y2"]]