The NAppEngine Compiler is a high-performance, modular, multi-target transpiler designed to compile unified NApp projects into responsive, native desktop applications and modern, single-page web applications (SPAs).
By strictly decoupling declarative UI layouts (NaXML), structured layouts/styling (NaStyle), typed logic/state management (NaCode), and hardware/media interaction (GlobalSystem API), the NAppEngine allows you to write once and deploy natively to the Web, Windows, Linux, and macOS.
- Multi-Target Compilation: Transpile the same front-end UI and mid-end logic to highly performant Single Page Web Applications (WebJS) or native OS Desktop Windows (PySide6 / Qt6).
- Strict Compiler Pipeline: Powered by
Lark-based grammar parsing, abstract syntax tree (AST) construction, comprehensive semantic verification, and a unified intermediate representation (IR). - Comprehensive Global System (
gs) API: Transparent unified bindings for Terminal, Local Storage, Network, Clipboard, Sensors, Audio, and Video. - Auto-Generated Terminal Mode: Build CLI/Console applications with zero UI configuration, supporting styled terminal emulation in the browser and native system shells on desktops.
- Smart Development CLI: Built-in HTTP development server, native app launcher, and an auto-unlocking/kill system to safely release locked files and ports under Windows and Linux.
The NAppEngine Compiler processes source files through a strict, multi-stage compilation pipeline:
+----------------------------------------+
| NApp Project Source Files |
| (app.yaml, *.naxml, *.nacode, res/) |
+----------------------------------------+
|
v
+----------------------------------------+
| Parser & AST Generator (Lark) |
| - grammar.lark (NaCode) |
| - nastyle_grammar.lark (NaStyle) |
+----------------------------------------+
|
v
+----------------------------------------+
| Semantic Analyzer & Resolvers |
| - Type checking (TypeManager) |
| - Static UI bindings validation |
| - Style structure alignment |
+----------------------------------------+
|
v
+----------------------------------------+
| Unified Intermediate Representation |
| (In-Memory IR AST Structures) |
+----------------------------------------+
|
+------------------+------------------+
| |
v v
+-------------------------------+ +-------------------------------+
| WebJS Code Emitter | | PySide6 Code Emitter |
| - SPA index.html/CSS | | - Qt6 layouts generation |
| - Vanilla JS Logic/State | | - Native Python structures |
| - Canvas & Media bindings | | - System I/O integration |
+-------------------------------+ +-------------------------------+
- Parser Engine (compiler.py): Parses raw files using unified grammar schemas (grammar.lark and nastyle_grammar.lark) and builds the syntax tree via transformer.py.
- Semantic Verification (analyzer.py): Performs strong-type resolution, variable/function declarations checking, and enforces architectural boundaries.
- UI & Style Resolution (static_ui_resolver.py & style_analyzer.py): Evaluates declarative XML trees and maps styles to elements.
- Unified Type Manager (type_manager.py): Manages native and complex types (
str,int32,float,bool,void,any,dict, arrays, and custom classes) throughout the compiler life cycle. - Emitter Pipeline:
- WebJS Emitter (emitter.py): Generates extremely fast, dependency-free vanilla JS, HTML, and styling.
- PySide6 Emitter (emitter.py): Generates a native Python script structure leveraging the Qt6 graphics libraries.
A standard, valid NApp project follows this structure:
my_napp_project/
βββ app.yaml # Required: Project metadata, entry points, and mode
βββ naxml/ # Required (unless Terminal mode): Declarative UI layout XML files
βββ res/ # Required: Assets and media resources (referenced via 'res://...')
βββ nacode/ # Optional: mid-end typed logic files (*.nacode)
- src/: Main compiler implementation.
- src/main.py: CLI Orchestrator and entry point.
- src/parser/: Lark files, grammars, and syntax-to-AST translation layers.
- src/semantics/: Strong-type compiler validations and binding checking.
- src/ir/: Core In-Memory Intermediate Representation data structures.
- src/emitters/: Emitter logic for WebJS, PySide6, and abstract baseline class definitions.
- tests_examples/: A rich suite of tests showcasing functionalities.
Compile and execute your NApp projects using a unified CLI.
# General CLI Signature
python -m src.main <PROJECT_PATH> [FLAGS]| Flag | Long Flag | Default | Description |
|---|---|---|---|
| positional | project_path |
Required | Path to the root directory of your NApp project. |
-t |
--target |
webjs |
Emitter target platform: webjs or pyside6. |
-o |
--output |
[project]/build/[target]/ |
Destination folder for compiled resources. |
-p |
--port |
8000 |
Local network port to serve the WebJS emitter output. |
-r |
--run |
False | Compiles, outputs, and immediately executes the target app. |
# 1. Compile a project for the Web and output to the default build folder
python -m src.main ./tests_examples/test4_gui1 --target webjs
# 2. Compile and run a native PySide6 Desktop application immediately
python -m src.main ./tests_examples/test5_gui2 --target pyside6 --run
# 3. Serve a WebJS application on a specific local port and launch a browser automatically
python -m src.main ./tests_examples/test7_hardware_network_media --target webjs --port 8080 --runNote
Windows Port and File Auto-Unlocking:
If a server or application session is already running on a requested port or folder, the compiler's auto-unlocking mechanic (_attempt_force_unlock in main.py) automatically detects, terminates the orphan listener process, frees target system handles, and seamlessly retries the emission.
The gs (Global System) object is the standard built-in proxy in NaCode. It represents the unified interface to interact with target systems.
Used for command-line interaction. In mode: terminal, the compiler automatically generates a fully customized macOS-like terminal window overlay in the browser, or uses standard terminal I/O natively.
// Prints a line to standard output
gs.print(text="Initialized session.");
// Prints a red-colored warning line to standard error
gs.print_err(text="Failed to fetch hardware state.");
// Prompt for standard keyboard string input (Yields and awaits execution on WebJS)
str username = gs.input(prompt="Please enter username: ");
// Prompt and automatically parse the standard input as an integer (fallback to 0)
int32 age = gs.input_int(prompt="Enter your age: ");
Persist and retrieve simple data across app sessions. WebJS utilizes browser localStorage, whereas PySide6 leverages secure direct file IO under the hood.
// Write text values linked to a target namespace key
gs.storage.write_text(key="settings_theme", content="dark");
// Read values back; returns empty string if key does not exist
str current_theme = gs.storage.read_text(key="settings_theme");
Handle asynchronous HTTP network operations safely.
// Performs a standard synchronous/asynchronous HTTP request.
// Returns a dictionary containing 'status' (int) and 'body' (str).
any response = gs.network.fetch(url="https://jsonplaceholder.typicode.com/todos/1");
if (response["status"] == 200) {
gs.print("Fetch Success!");
} else {
gs.print_err("Fetch failed.");
}
Unified, platform-independent access to device clipboards and positioning sensors.
// Write/Copy text data directly into the system clipboard
gs.hardware.clipboard_write(text="Hello from NaCode!");
// Read/Paste text data directly out of the system clipboard
str clipboard_text = gs.hardware.clipboard_read();
// Fetch geographical coordinate information
// Returns a dictionary containing 'lat', 'lng', and 'accuracy'
any location = gs.hardware.get_location();
float latitude = location["lat"];
Control sound, speakers, and background tracks via logical triggers.
// Loads an audio file into memory and registers its logical ID
gs.media.audio_load(id="click_sfx", src="res://click.mp3");
// Register a callback function name that executes automatically once playback finishes
gs.media.audio_set_on_finish_handler(id="click_sfx", handler_name="on_audio_finish");
// Trigger playback of the loaded audio clip
gs.media.audio_play(id="click_sfx");
The long-term multi-platform roadmap and current implementation status:
| Subsystem / Feature | WebJS Status | PySide6 Status | C & Qt6 / Rust | Mobile (iOS/Android) |
|---|---|---|---|---|
Logic (NaCode) |
Supported | Supported | Planned | Planned |
| Dynamic Localization | Full (name_en / name_fr) |
Planned | Planned | |
| Terminal I/O | Mac-style DOM emulation | Native terminal wrapper | Planned | Emulated screen layout |
| Canvas / Graphics | WebGL & 2D Canvas | QOpenGLWidget wrapper | Planned | SurfaceView/Metal |
| Undo / Redo | History stack | History stack | Planned | Planned |
| Storage & Persistence | localStorage |
Local File I/O (open) |
Planned | Scoped Storage |
| Networking & HTTP | fetch() API wrapper |
π§ Development | Planned | Planned |
| Clipboard IO | navigator.clipboard |
π§ Development | Planned | Planned |
| Media & Audio Players | Web Audio & HTML5 | π§ Development | Planned | Planned |
| GPS / NFC Sensors | HTML5 Geolocation / NFC | π Sandboxed / N/A | Planned | Native SDK |
The workspace comes pre-configured with clear examples detailing step-by-step functionality:
- test1_very_simple_hello_world: The simplest logic demo outputting a terminal line.
- test2_greeting_hello_world: Introduces variables and interactive prompt input.
- test3_gs_methods: Comprehensive verification of the base global system proxy.
- test4_gui1: First window layout displaying multi-column grid alignment and translations.
- test5_gui2: Rich layouts displaying styling overrides via NaStyle.
- test6_legacy_compat: Regression testing verifying standard compiler parser modes.
- test7_hardware_network_media: Interactive testing for all advanced Network, Hardware, and Audio player features.
For deeper design specifications and architectural blueprints, see:
- NApp Engine Architecture Blueprint: High-level decoupling rules and layouts.
- NaStyle Styling Spec: Parser grammar and styling structure rules.
- NaXML Layouts Spec: Complete list of supported XML front-end tag components.
- NAssembly Compiler Spec: Low-level hardware representations.
- Hardware, Media, & Network Spec: Specifications for
gs.hardware,gs.media, andgs.networknamespaces.