How donzgold/justmc_compilator works
Project Type & Purpose
• JMCC is a command‐line compiler/transpiler written in Python.
• It takes .jc source files (JustMC script language) and produces JSON snippets for the JustMC server, optionally uploading them to a cloud service.
• It also provides decompilation (JSON → .jc), documentation generation, code‐completion assets, and NBT manipulations.
File‐Structure Analysis
Top‐level components:
• jmcc.py – CLI entry point & argument parser
• compilator.py – main compile engine (lexing, parsing, AST, semantic checks, codegen)
• decompilator.py – reverse engine (JSON → .jc)
• nbtworker.py – handles NBT (Minecraft data tags) transformations
• md_generator.py – renders documentation/Markdown from templates & data
• data/ & new_data/ – JSON + .properties files defining actions, blocks, events, languages, values
• assets/completions.json – code‐completion metadata for editors
• documentation/ – handwritten docs in English & Russian (for users)
• jmcc.properties – configuration for the compiler
Architectural Insights from README
• Single‐process, plug‐in style modules
• Pipeline pattern in compilator.py: parse → semantic analysis → generate JSON → write or upload
• Optional sub‐commands: compile, decompile, docs, etc.
• Uses standard Python + requests for HTTP uploads
Main Components & Interactions
a. Components
1. CLI Layer (jmcc.py)
2. Parser & AST Builder (inside compilator.py)
3. Semantic Analyzer (type checking, symbol tables)
4. Code Generator (JSON emitter)
5. Data Repository (data/, new_data/)
6. NBT Worker (nbtworker.py)
7. Output Module
– File Writer (writes .json)
– Uploader (HTTP client via requests)
8. Decompiler (decompilator.py)
9. Documentation Generator (md_generator.py)
10. Code‐Completion Asset Builder (assets/completions.json)
b. Relationships & Data Flow
• User invokes jmcc.py → compile
• CLI loads configuration, command‐dispatches to the Compiler Engine
• Compiler Engine pulls definitions from Data Repository → feeds into Parser & Semantic phases
• NBT Worker is called by Code Generator to produce correct NBT JSON segments
• Generated JSON goes to Output Module → either disk (.json) or Uploader → Cloud API
• Decompiler is a separate command path in CLI, reading JSON + Data Repository → reconstructing .jc
• Documentation Generator reads Data Repository & documentation/ templates → builds updated MD docs
c. Architectural Patterns & Principles
• Pipeline / Chain of Responsibility for compile phases
• Single‐responsibility modules (parsing vs. codegen vs. NBT vs. docs)
• Data‐driven design: all commands, events, blocks, etc. defined in JSON under data/
• Plugin‐like subcommands within a single‐process CLI
d. Key Technologies
• Python3 modules & packages
• JSON & Java‐style .properties for data/config
• requests for HTTP uploads
• Markdown for documentation