Parser

The Parser converts tokens into an Abstract Syntax Tree (AST). It supports three statement types:

  • TRAIN WITH: Training data selection.

  • PREDICT VALUE: Prediction targets and task types.

  • VALIDATE WITH: Validation data selection.

Example

from tlsql.tlsql.parser import Parser

parser = Parser("PREDICT VALUE(users.Age, CLF) FROM users WHERE users.Gender = 'F'")
ast = parser.parse()

if ast.predict:
    print(f"Target Column: {ast.predict.value.target.column}")
    print(f"Target Table: {ast.predict.value.target.table}")
    print(f"Task Type: {ast.predict.value.predict_type.type_name}")
class Parser(text)[source]

Bases: object

Parser for TLSQL syntax.

Uses a recursive descent parser that supports TRAIN, PREDICT, and VALIDATE statements.

tokens

Token list.

token_pos

Current token index.

current_token

Token currently being processed.

__init__(text)[source]

Initialize parser.

Parameters:

text – Input text to parse.

parse()[source]

Parse a complete TLSQL statement.

Determines statement type based on first keyword:

TRAIN WITH: training statement.

PREDICT VALUE: prediction statement.

VALIDATE WITH: validation statement.

Returns:

Statement AST root node.