Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

93 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

NaCode & NaXML Compiler

Platform: Cross-Platform Parser: Lark Emitter: WebJS Emitter: PySide6

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.


Key Features

  • 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.

Compiler Architecture

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     |
+-------------------------------+     +-------------------------------+

Key Modules

  • 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.

πŸ“‚ Project Structure & Workspace Layout

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)

Compiler Repository Structure

  • 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.

πŸ› οΈ Getting Started & CLI Usage

Compile and execute your NApp projects using a unified CLI.

# General CLI Signature
python -m src.main <PROJECT_PATH> [FLAGS]

CLI Arguments & Options

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.

Compilation Examples

# 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 --run

Note

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.


Global System (gs) APIs Reference

The gs (Global System) object is the standard built-in proxy in NaCode. It represents the unified interface to interact with target systems.

1. Terminal & Standard I/O

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: ");

2. Local Storage

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");

3. Network operations (gs.network)

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.");
}

4. Hardware Sensors & Devices (gs.hardware)

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"];

5. Media & Sound Systems (gs.media)

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");

Emitters & Subsystems Matrix

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) ⚠️ Single-language fallback 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

Test & Example Suite

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.

Language References

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, and gs.network namespaces.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages