1.1.2 • Published 2 years ago

muffin-js v1.1.2

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

🧁 Muffin

MuffinJS is a node.js library that lets you compile and run Muffin scripts on your machine.

Set up and compile

npm i -g muffin-js
muffin entry_point.js

Use it with Node.JS

WARNING: You need to provide "prompt", "confirm" and "localStorage" objects for it to work properly. This is the one that comes with the bundle:

/* to download the libraries: 
npm i readline-sync@1.4.10 chalk@4.1.2
*/
const readline = require('readline-sync');
const chalk = require('chalk'); /* NEEDS chalk@4.0.0 */
const fs = require('fs');
const prompt = ((data) => readline.question(chalk.green(data.toUpperCase()) + chalk.green('\n\nINPUT> ')));
const confirm = ((...rest) => { console.clear(); console.log(...rest.map(e => chalk.green(e.toString()toUpperCase()))); readline.question(chalk.green('\nPRESS ENTER> ')); return true; });
const localStorage = ({
    getItem: ((name = '') => fs.existsSync('./storage/' + name + '.txt') ? JSON.parse(fs.readFileSync('storage/' + name + '.txt', 'utf8')) : undefined),
    setItem: ((name = '', value = '') => fs.writeFileSync('./storage/' + name + '.txt', JSON.stringif(value)),
    clear: (() => { fs.rmdirSync('./storage', { recursive: true }); fs.mkdirSync('./storage'); })
});

You can compile the code with the script below but you will need to install the mentioned dependencies!

const muffin = require('muffin');
const my_code = `print "Your code goes here..."`;
// Outputs javascript code! Run it right away btw!
const output = muffin(my_code);
/*
Run it! However, Remember: EVAL IS EVIL!
You also need to include "prompt", "confirm" and "localStorage".
or, Use the specified code above!
*/
eval(output);

Documentation

This is the more updated documentation, It's better than the in-script documentation.

Parser

The parser basically seperates the text line-by-line, HOWEVER, THE PARSER DOES NOT COUNT LINES THAT HAVE A SEMICOLON AT THE END A NEWLINE! Example:

print "This is " + ;
    "Not a new line!!!"

Comments

A comment:

# Hello! This is a comment!

# Multiline comments...
# Technically exist!

Including other scripts

Including an external file:

link ./path/to/file.muffin

Adding an internal library:

link muffin.<library>

Example (1.1 only):

link gui.muffin
execute muffin.gui.menu [ "prompt", "Hello world!" ],;
[ "print 'Hey there!'", "Hi!" ],;
[ "print 'See you later!'", "Goodbye!" ]

Input/Output

Show a notice to the user:

print <javascript syntax>

Example:

print "Hello " + "World!"

Ask the user for input:

prompt <variable name> <javascript syntax>

Example:

prompt hello_word_2000 "Hello, Whats your name?"

Quitting

When you want to quit your job:

# Yea, It's just that.
exit

Variables

Create a variable anyways (saved to disk too):

var <name> <javascript syntax>

Create a variable only if it doesn't exist even on disk (life saver):

cvar <name> <javascript syntax>

Loops/Conditions/Functions

Yes, We have a ton of alternates!

Functions:

sector <name>
    # how to get arguments?
    print "First argument: " + input[0]
    # yep!
    <code with fixed indent>

function <name>
    <code with fixed indent>

# calling a function!
execute <name> <arguments separated by ",">
# now for when you need js:
_ <javascript syntax for the name> <arguments separated by ",">

Conditions:

if <javascript syntax>
    <code with fixed indent>
elif <javascript syntax>
    <code with fixed indent>
elseif <javascript syntax>
    <code with fixed indent>
else_if <javascript syntax>
    <code with fixed indent>
else
    <code with fixed indent>

Loops:

for <javascript syntax>
    <code with fixed indent>
while <javascript syntax>
    <code with fixed indent>

Anything else unlisted:

pop <condition or loop or function name> <javascript syntax>
    <code with fixed indent>

Erasing all data

For when you need it.

purge

[Old] documentation

This doesn't go into your actual code.

docs confirm
1.1.2

2 years ago

1.1.1-2

2 years ago

1.1.1-1

2 years ago

1.1.1

2 years ago

1.1.0-1

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago