Menu

Development Tools

Relevant source files

OwnLang provides a comprehensive set of development tools to support interactive programming, project management, and code quality maintenance. This document covers the interactive REPL system, the package manager, and various command-line utilities that facilitate OwnLang development workflows.

For information about the build system and distribution, see Build and Distribution. For details on the module system that these tools interact with, see Module System.

Interactive REPL

The OwnLang REPL (Read-Eval-Print Loop) provides an interactive development environment for testing code, exploring the language, and debugging. The REPL implementation is built on top of JLine for enhanced console interaction and command completion.

REPL Architecture

Sources: ownlang-utils/src/main/java/com/annimon/ownlang/utils/Repl.java1-186

REPL Features

The REPL provides several built-in commands accessible through the :command syntax:

CommandPurposeImplementation
:helpDisplay available commandsprintHelp() method
:varsList variables and constantsprintVariables() using ScopeHandler
:funcsList user and library functionsprintFunctions() with categorization
:sourceShow accumulated source codeUses PrintVisitor on history
:resetClear input bufferBuffer reset operation
:exitExit REPL sessionLoop termination

The REPL maintains a BlockStatement history of successfully parsed statements and can automatically attempt to wrap expressions in println statements for immediate evaluation display.

Sources: ownlang-utils/src/main/java/com/annimon/ownlang/utils/Repl.java27-33 ownlang-utils/src/main/java/com/annimon/ownlang/utils/Repl.java114-185

Console Implementations

The REPL supports multiple console backends with graceful fallback:

  • JLineConsole: Primary implementation providing command completion and line editing
  • SystemConsole: Fallback implementation using standard input/output
  • OwnLangCompleter: Provides command completion for REPL-specific commands

Sources: ownlang-utils/src/main/java/com/annimon/ownlang/utils/Repl.java101-112

Package Manager

The OwnLang package manager is implemented as an OwnLang script that provides dependency management, project initialization, and script execution capabilities. The package manager operates through the own command and is built using a modular class-based architecture.

Package Manager Architecture

Sources: ownlang-desktop/src/main/resources/scripts/own.own1-41

Core Components

The package manager consists of several key classes that handle different aspects of project and dependency management:

Registry Class

Manages package registry operations including caching and HTTP retrieval:

  • Global Registry: Fetches packages from GitHub repository registry
  • Local Caching: Stores registry data in temporary directory
  • Package Resolution: Resolves package names to downloadable resources

Sources: ownlang-desktop/src/main/resources/scripts/own/Registry.own1-58

Config Class

Handles project configuration through own-package.json:

  • Configuration Loading: Reads and parses JSON configuration
  • Default Generation: Creates default project settings
  • Property Merging: Combines user config with defaults

Sources: ownlang-desktop/src/main/resources/scripts/own/Config.own1-76

Packages Class

Manages dependency installation and package operations:

  • Dependency Resolution: Downloads packages from various sources (GitHub gists)
  • Package Installation: Manages own-modules directory structure
  • Usage Display: Shows package documentation from .usage.own files

Sources: ownlang-desktop/src/main/resources/scripts/own/Packages.own1-145

Package Manager Commands

Sources: ownlang-desktop/src/main/resources/scripts/own.own31-40 ownlang-desktop/src/main/resources/scripts/own/Own.own1-81

Configuration Structure

The package manager uses own-package.json for project configuration with the following structure:

FieldPurposeDefault Value
nameProject identifierDerived from directory name
versionProject version"1.0.0"
authorProject authorSystem username
programMain program file"main.own"
scriptsExecutable commands{"default": ["$ownlang$", "-f", "$program$"]}
dependenciesPackage dependencies{}

Sources: ownlang-desktop/src/main/resources/scripts/own/Config.own42-57

CLI Tools and Utilities

The OwnLang development environment includes various command-line utilities for code processing and quality maintenance. These tools operate on OwnLang source code and provide features like beautification, linting, and optimization.

Error Handling System

The CLI tools utilize a structured error handling system for parse and runtime errors:

Sources: ownlang-parser/src/main/java/com/annimon/ownlang/exceptions/ParseException.java1-21 ownlang-parser/src/main/java/com/annimon/ownlang/exceptions/OwnLangParserException.java1-27 ownlang-parser/src/main/java/com/annimon/ownlang/parser/error/ParseErrors.java1-54

Utility Integration

The development tools integrate with the core language processing pipeline to provide:

  • Code Beautification: Source code formatting and style normalization
  • Static Analysis: Code quality checks and potential issue detection
  • Optimization: Performance improvements and code transformations
  • Interactive Development: REPL integration with completion and help systems

The tools maintain compatibility with the module system and can process code that uses both standard library and external package dependencies.

Sources: ownlang-utils/src/main/java/com/annimon/ownlang/utils/Repl.java86-92