class PythonParser
- PythonParser
- Reference
- Object
Overview
Python source-file parser used by the Flask analyzer to resolve
routing-relevant globals (Blueprint / Namespace / Api instances)
across files. Originally a hand-rolled token consumer paired with
minilexers/python.cr; rewritten to walk the vendored tree-sitter
Python grammar so we shed the legacy lexer (now deleted) and get
accurate handling of multi-line strings, fstrings, parenthesised
imports, and similar shapes that the regex/token approach couldn't
express cleanly.
The public surface kept stable for Flask:
PythonParser.new(path, content, parsers, depth = 0)— same constructor shape minus the now-irrelevanttokensargument.parser.@global_variables : Hash(String, GlobalVariables)— populated for the file at#pathplus every module reachable through itsimport/from … import …statements (recursive, with depth bounded byParserLimit).- Per-variable
GlobalVariablesstruct withname,type,value,#pathfields.typeis"str"for string assignments, the callee identifier forname = Foo(...)calls (including dotted forms likeNamespace.model),nilotherwise.
ImportModel stays in tree but isn't populated by this rewrite —
nothing reads parser.@import_statements. We keep the class for
any external referrers that might construct one for logging.
Defined in:
miniparsers/python.crConstructors
Instance Method Summary
Constructor Detail
def self.new(path : String, content : String, parsers : Hash(String, PythonParser), visited : Array(String) = Array(String).new, depth : Int32 = 0)
#