stupid

A stupid scripting language for Java/JVM

Лицензия

Лицензия

Группа

Группа

com.madisp.stupid
Идентификатор

Идентификатор

stupid
Последняя версия

Последняя версия

0.1.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

stupid
A stupid scripting language for Java/JVM
Ссылка на сайт

Ссылка на сайт

http://github.com/madisp/stupid
Система контроля версий

Система контроля версий

http://github.com/madisp/stupid

Скачать stupid

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.madisp.stupid/stupid/ -->
<dependency>
    <groupId>com.madisp.stupid</groupId>
    <artifactId>stupid</artifactId>
    <version>0.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.madisp.stupid/stupid/
implementation 'com.madisp.stupid:stupid:0.1.0'
// https://jarcasting.com/artifacts/com.madisp.stupid/stupid/
implementation ("com.madisp.stupid:stupid:0.1.0")
'com.madisp.stupid:stupid:jar:0.1.0'
<dependency org="com.madisp.stupid" name="stupid" rev="0.1.0">
  <artifact name="stupid" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.madisp.stupid', module='stupid', version='0.1.0')
)
libraryDependencies += "com.madisp.stupid" % "stupid" % "0.1.0"
[com.madisp.stupid/stupid "0.1.0"]

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
org.antlr : antlr4-runtime jar 4.1

Модули Проекта

Данный проект не имеет модулей.

stupid Build Status

A simple scripting language with a Java runtime and interoperability. Works with Android.

Usage

Imports are omitted for brevity.

Compiling and evaluating an expression (essentially a glorified calculator):

// create a new parser
ExpressionFactory parser = new ExpressionFactory();
// parse a string into an expression tree
Value expr = parser.parseExpression("3 + 5");
// evaluate the expression and print the result
System.out.println(expr.value(new BaseContext())); // prints "8"

Lets spice things up and use a context with some variables instead of the plain BaseContext.

ExpressionFactory parser = new ExpressionFactory();
Value expr = parser.parseExpression("pi*r*r)");
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("pi", Math.PI);
vars.put("r", 2.0f);
// prints "Area of a circle with r=2: 12.566370614359172"
System.out.println("Area of a circle with r=2: " + expr.value(new VarContext(vars)));

Lets also bind it to the System.out object so we can call the println method from the script:

ExpressionFactory parser = new ExpressionFactory();
Value expr = parser.parseExpression("println('Area of a circle with r=2: ' + pi*r*r)");
// a stack context to keep both our vars and binding to System.out
StackContext ctx = new StackContext();
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("pi", Math.PI);
vars.put("r", 2.0f);
ctx.pushExecContext(new VarContext(vars));
// push a reflection context that binds to system.out onto the stack
ctx.pushExecContext(new ReflectionContext(System.out));
// prints "Area of a circle with r=2: 12.566370614359172"
expr.value(ctx);

The Language

Mostly really similar to Java. The grammar lives in src/main/antlr4/Stupid.g4. A short introduction is available in a blogpost.

License

MIT License, see the LICENSE file.

Версии библиотеки

Версия
0.1.0