How whiteheadbanger/lunfardo works
Main Components
• Entry Point & Interpreter: The execution begins at run.py (in the src directory), which sets up and invokes the interpreter. The interpreter itself is implemented in interpreter.py.
• Lexical Analysis: The lexer defined in lexer.py tokenizes the Lunfardo source code.
• Parsing: The parser (lunfardo_parser.py) consumes tokens and builds the internal AST (Abstract Syntax Tree). The nodes in the AST are described in nodes.py.
• AST & Node Management: nodes.py represents various AST nodes, while rtresult.py manages runtime results.
• Error Handling: Error modules (found in src/errors) provide error definitions, markings, and some error-handling logic.
• Built-in Functions & Libraries: The src/builtin directory holds Lunfardo’s built-in scripts (with .lunf files) as well as Python library counterparts that help implement built-in functionality.
• Type System: Within src/lunfardo_types you find various modules (like boloodean, chamuyo, cheto, etc.) that indicate the introduction of dynamic types within Lunfardo.
• Library Registry: The file library_registry.py helps register or manage available libraries.
Their Interactions and Relationships
• The run.py file serves as the system’s starting point, initializing the interpreter. It calls modules for lexing (lexer.py) then parsing (lunfardo_parser.py), followed by execution in interpreter.py.
• The lexer transforms source code (potentially coming from example .lunf files inside the examples folder) into tokens, relying on constants defined in the constants directory.
• The parser uses these tokens, builds an AST using definitions in nodes.py and potentially validates grammar or syntax based on structures defined in grammar.txt.
• The interpreter then processes the AST, invoking built-in functions (via the src/builtin folder and library_registry) and managing type conversions with modules in src/lunfardo_types.
• Error and exception handling are integrated within the execution cycle with modules in the src/errors folder.
• The examples folder demonstrates sample Lunfardo programs, which are interpreted in the same runtime context.
Architectural Patterns and Design Principles
• Modular Separation: Components (lexer, parser, interpreter, error handling) are each placed in separate modules to encourage separation of concerns.
• Pipeline Flow: There is a clear sequential processing pipeline: source input → lexing → parsing → interpretation.
• Extensibility: The built-in library mechanism and a registry for libraries suggest that the interpreter is extensible, allowing additional functionalities without disturbing the core components.
• Dynamic Typing: The use of different type modules in lunfardo_types underscores a dynamic type system integrated in the interpreter.
Detail Specific Elements
• Role of the "src" folder as the core system.
• "examples" folder separately to show how example programs are used as input to test or demonstrate the interpreter.