Skip to content

Latest commit

 

History

History
91 lines (50 loc) · 4.12 KB

File metadata and controls

91 lines (50 loc) · 4.12 KB
graph LR
    PluralRule["PluralRule"]
    Tokenizer["Tokenizer"]
    Parser["Parser"]
    Compiler_Orchestrator["Compiler Orchestrator"]
    Python_Compiler["Python Compiler"]
    JavaScript_Compiler["JavaScript Compiler"]
    Gettext_Compiler["Gettext Compiler"]
    PluralRule -- "initializes/uses" --> Parser
    Parser -- "uses" --> Tokenizer
    Parser -- "passes AST to" --> Compiler_Orchestrator
    Compiler_Orchestrator -- "delegates to" --> Python_Compiler
    Compiler_Orchestrator -- "delegates to" --> JavaScript_Compiler
    Compiler_Orchestrator -- "delegates to" --> Gettext_Compiler
    Python_Compiler -- "provides compiled rule to" --> PluralRule
Loading

CodeBoardingDemoContact

Details

The Plural Rule Engine subsystem is responsible for interpreting and compiling CLDR plural rules into executable code for various target languages, which is crucial for correct pluralization in formatting and message translation within the babel library. The subsystem is primarily encapsulated within the babel.plural module, located in the babel/plural.py file.

PluralRule

The primary public interface for consumers. It encapsulates a compiled plural rule, handling its initialization, parsing, and execution to determine the correct plural category for a given number.

Related Classes/Methods:

Tokenizer

Performs lexical analysis of plural rule strings, breaking them down into a sequence of meaningful tokens.

Related Classes/Methods:

Parser

Performs syntactic and semantic analysis of the token stream, constructing an Abstract Syntax Tree (AST) representing the rule's structure. It orchestrates the tokenization and AST construction process.

Related Classes/Methods:

Compiler Orchestrator

The core compilation function that takes an AST and dispatches it to the appropriate specialized compiler based on the target format (Python, JavaScript, Gettext).

Related Classes/Methods:

Python Compiler

A specialized compiler that traverses the AST and generates executable Python code.

Related Classes/Methods:

JavaScript Compiler

A specialized compiler that traverses the AST and generates JavaScript code from the AST.

Related Classes/Methods:

Gettext Compiler

A specialized compiler that generates a Gettext-compatible C-style expression from the AST.

Related Classes/Methods: