class

PythonParser

Inherits Reference < Object

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-irrelevant tokens argument.
  • parser.@global_variables : Hash(String, GlobalVariables) — populated for the file at path plus every module reachable through its import / from … import … statements (recursive, with depth bounded by ParserLimit).
  • Per-variable GlobalVariables struct with name, type, value, path fields. type is "str" for string assignments, the callee identifier for name = Foo(...) calls (including dotted forms like Namespace.model), nil otherwise.

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.

Constructors

new(path : String, content : String, parsers : Hash(String, PythonParser), visited : Array(String) = Array(String).new, depth : Int32 = 0)
Source

Instance methods

parse(content : String)
Source
path
Source
path=(path : String)
Source

Nested types