llmcc_python/
token.rs

1use llmcc_core::define_tokens;
2use llmcc_core::graph_builder::BlockKind;
3use llmcc_core::ir::HirKind;
4use llmcc_core::paste;
5use llmcc_core::{Parser, Tree};
6
7define_tokens! {
8    Python,
9    // Text tokens (Python keywords and punctuation) - use actual tree-sitter-python kind_ids
10    (Text_def,              37,  "def",                  HirKind::Text),
11    (Text_class,            45,  "class",                HirKind::Text),
12    (Text_import,           3,   "import",               HirKind::Text),
13    (Text_from,             5,   "from",                 HirKind::Text),
14    (Text_as,               10,  "as",                   HirKind::Text),
15    (Text_return,           16,  "return",               HirKind::Text),
16    (Text_LPAREN,           7,   "(",                    HirKind::Text),
17    (Text_RPAREN,           8,   ")",                    HirKind::Text),
18    (Text_COLON,            23,  ":",                    HirKind::Text),
19    (Text_EQ,               44,  "=",                    HirKind::Text),
20    (Text_COMMA,            9,   ",",                    HirKind::Text),
21    (Text_DOT,              4,   ".",                    HirKind::Text),
22    (Text_ARROW,            38,  "->",                   HirKind::Text),
23    (Text_AT,               48,  "@",                    HirKind::Text),
24
25    // Identifier tokens
26    (identifier,            1,   "identifier",           HirKind::Identifier),
27
28    // Root node
29    (source_file,           108, "module",               HirKind::File,      BlockKind::Root),
30
31    // Scope-creating nodes
32    (function_definition,   145, "function_definition",  HirKind::Scope,     BlockKind::Func),
33    (class_definition,      154, "class_definition",     HirKind::Scope,     BlockKind::Class),
34    (decorated_definition,  158, "decorated_definition", HirKind::Scope),
35    (block,                 160, "block",                HirKind::Scope,     BlockKind::Scope),
36
37    // Import statements
38    (import_statement,      111, "import_statement",     HirKind::Internal),
39    (import_from,           115, "import_from_statement",HirKind::Internal),
40    (aliased_import,        117, "aliased_import",      HirKind::Internal),
41    (dotted_name,           162, "dotted_name",         HirKind::Internal),
42
43    // Function-related
44    (parameters,            146, "parameters",          HirKind::Internal),
45    (typed_parameter,       207, "typed_parameter",     HirKind::Internal),
46    (typed_default_parameter, 182, "typed_default_parameter", HirKind::Internal),
47
48    // Decorators
49    (decorator,             159, "decorator",           HirKind::Internal),
50
51    // Call and attribute
52    (call,                  206, "call",                HirKind::Internal,  BlockKind::Call),
53    (attribute,             203, "attribute",           HirKind::Internal),
54
55    // Expressions
56    (assignment,            198, "assignment",          HirKind::Internal),
57    (binary_operator,       191, "binary_operator",     HirKind::Internal),
58    (comparison_operator,   195, "comparison_operator", HirKind::Internal),
59
60    // Type annotations
61    (type_node,             208, "type",                HirKind::Internal),
62    (type_parameter,        155, "type_parameter",      HirKind::Internal),
63
64    // Other statements
65    (expression_statement,  122, "expression_statement", HirKind::Internal),
66    (return_statement,      125, "return_statement",    HirKind::Internal),
67    (pass_statement,        128, "pass_statement",      HirKind::Internal),
68    (if_statement,          131, "if_statement",        HirKind::Internal),
69    (for_statement,         137, "for_statement",       HirKind::Internal),
70    (while_statement,       138, "while_statement",     HirKind::Internal),
71    (try_statement,         139, "try_statement",       HirKind::Internal),
72
73    // Collections
74    (argument_list,         157, "argument_list",       HirKind::Internal),
75    (expression_list,       161, "expression_list",     HirKind::Internal),
76    (keyword_argument,      214, "keyword_argument",    HirKind::Internal),
77
78    // Field IDs (tree-sitter field IDs for accessing named children)
79    (field_name,            19,  "name",                HirKind::Internal),
80    (field_parameters,      31,  "parameters",         HirKind::Internal),
81    (field_body,            6,   "body",               HirKind::Internal),
82    (field_type,            32,  "type",               HirKind::Internal),
83    (field_left,            17,  "left",               HirKind::Internal),
84    (field_right,           25,  "right",              HirKind::Internal),
85    (field_function,        14,  "function",           HirKind::Internal),
86    (field_arguments,       11,  "arguments",          HirKind::Internal),
87    (field_object,          20,  "object",             HirKind::Internal),
88    (field_attribute,       21,  "attribute",          HirKind::Internal),
89}