scriny 0.4.0 copy "scriny: ^0.4.0" to clipboard
scriny: ^0.4.0 copied to clipboard

A tiny scripting language for Dart. Also supports evaluating simple math expressions.

Scriny

Scriny is a tiny scripting language for Dart (it's actually the concatenation of "script" and "tiny").

Pub Likes Pub Points MIT License

Features #

  • Evaluates simple mathematical expressions.
  • Supports variables of type string, number, boolean, list, map, and null.
  • Includes control structures (if, else, for, while, etc.).
  • Allows custom top-level functions and variables.
  • Easy to use and integrate.

Scriny is already used in two of my projects :

Getting Started #

Add Scriny to your project by following the instructions here.

Usage #

Code #

All the code examples below can be parsed using ScrinyParser.parseProgram and executed using run().

Mathematical expressions

This evaluates to 9 :

(2 + 1) * 3

This evaluates to 8 :

2^3

This evaluates to true :

2 == (1 + 1)

Note

To negate a boolean, use the classic !. You can also use != instead of ==.

This evaluates to Dart’s math.e :

exp(1)

Note

You can find all available built-in functions here. We'll see how to add custom functions later.

Variables

This returns 8 :

a = 10;
b = -2;
return a + b;

This throws an error :

a = 10;
b = -2;
delete a;
return a + b;

This returns "Hello world !" :

list = ["Hello"];
map = {"w": "world"};
return list[0] + " " + map["w"] + " !";

Control statements

This evaluates to 1 :

if (true) {
  return 1;
} else {
  return 2;
}

This prints 0 to 9 and returns null :

for (i in range(10)) {
  print(i);
}

Note

If you don't return a value in your script, then null is returned. This is not the case for simple expressions (eg. 1 + 1 returns 2 once evaluated).

This returns 1998 :

n = 0;
while (true) {
  n = n + 1;
  if (n == 1998) {
    break;
  }
}
return n;

This returns [2, 4] :

list = [];
list = list + [1, 2, 3];
delete list[0];
list[1] = 4;
return list;

Custom top-level variables and functions

Adding custom top-level constants, variables and functions to Scriny is straightforward. All you have to do is to provide a custom EvaluationContext to ScrinyParser.parseProgram.

Check out the example on pub.dev, and see the EvaluationContext class documentation for more information.

Interpreter #

Scriny comes with a built-in interpreter ! If you have a Scriny script file, you can run it with :

dart run scriny --file=<path>

If your script consists of a single line, you can run it with :

dart run scriny --code="<your_code>"

License #

This project is licensed under the MIT License.

Contributions #

There are many ways you can contribute to this project :

1
likes
150
points
68
downloads

Publisher

verified publisherskyost.eu

Weekly Downloads

A tiny scripting language for Dart. Also supports evaluating simple math expressions.

Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

Funding

Consider supporting this project:

ko-fi.com
paypal.me

License

MIT (license)

Dependencies

args, meta, petitparser

More

Packages that depend on scriny