Lightweight Python interpreter in Rust.
Go to file
hkau 5fade5e530 [add] modules::time::now
[add] modules::methods::string::replace
[add] modules::methods::string::replacen
[add] modules::methods::string::replaceall
2024-02-20 22:18:21 -05:00
src [add] modules::time::now 2024-02-20 22:18:21 -05:00
.gitignore [add] interpret: in-place reassignment 2024-02-09 21:20:17 -05:00
Cargo.toml [add] modules::math 2024-02-19 17:20:12 -05:00
LICENSE Initial 2024-01-25 20:00:23 -05:00
README.md [add] modules::standard::require 2024-02-18 22:38:20 -05:00

README.md

🔮🐍 Amethystine

Amethystine (named after the "Amethystine Python") is a lightweight interpretter for a mix of Python and Lua written in Rust. It interprets an AST tree generated by a PEG parser.

Documentation is available at https://docs.stellular.org/amethystine/index.html, and can be built locally with cargo doc --no-deps --document-private-items.

Usage

amethystine input.py (flags)
amethystine input.lua (flags) # experimental

Flags

The Amethystine CLI supports the following flags:

  • --benchmark: log the time between interpretation start and end
  • --ast: log the generated AST to the standard output
  • --text: log the modified text content to the standard output (logs before parsing begins)

Features

Amethystine currently supports the following language features:

  • Variable declaration
  • Function declaration
    • All blocks that are expected to contain body content consisting of other blocks are transformed to contain an ending block during parsing. This block can be manually inserted by adding end after your function/conditional
  • Basic standard functions
    • The type function will return types defined in the grammar file, not Python types (example: string, number, null)
  • (QUICK_CONDITIONAL_IF) Mathematical operations
  • Conditional blocks
  • table values

The features below are planned:

  • for/while loops
  • Support for & (AND) and | (OR) in QUICK_CONDITIONAL_IF
  • Module importing
    • Imported modules will have a RETURN statement at the end, which will be read by the interpreter (reading the value of the return variable)

Amethystine supports the following datatypes:

  • bool
  • string
  • number
  • null
  • array
  • tuple
  • table
  • any

Amethystine also supports using Lua-like syntax as well as Python-like syntax:

# python input
x = "Hello, world!"

def log(y):
    print(y)

log(x.upper())

# read as
x = "Hello, world!"

def log(y):
    print(y)

dump()
<end>

log(string::upper(x))
-- lua input
local x = "Hello, world!"
print(x.upper())

function log(y):
    print(y)
end

log(x.upper())

-- read as
x = "Hello, world!"

function log(y):
    print(y)
    
dump()
<end>

log(string::upper(x))

Standard Library

Standard library documentation available at https://docs.stellular.org/amethystine/modules/index.html. The provided methods and functions differ greatly from Python and Lua in some specific areas, so reading the documentation is advised.