exprml-dart

exprml_dart is a Dart library implementing an ExprML interpreter. The ExprML is a programming language that can evaluate expressions represented in JSON (and JSON-compatible YAML).

The ExprML language specification is available at https://github.com/exprml/exprml-language .

Features

  • Decoder: Decodes text in JSON (or JSON-compatible YAML) into JSON values in Dart.
  • Encoder: Encodes JSON values into text JSON (or JSON-compatible YAML).
  • Parser: Parses ASTs of ExprML expression from the JSON values decoded from source.
  • Evaluator: Evaluates the ASTs of ExprML expression as JSON values.

Getting started

dart pub add exprml_dart

Examples

import 'package:exprml_dart/exprml.dart';
import 'package:exprml_dart/exprml_pb.dart';

void main() {
  // Decode JSON value from a source string.
  final decodeResult = Decoder()
      .decode(DecodeInput(text: 'cat: ["`Hello`", "`, `", "`ExprML`", "`!`"]'));

  // Parse an AST from the decoded value.
  final parseResult = Parser()
      .parse(ParseInput(value: decodeResult.value));

  // Evaluate the parsed AST as a JSON value.
  final evaluateResult = Evaluator()
      .evaluateExpr(EvaluateInput(expr: parseResult.expr));

  // Encode the evaluated JSON value into a string.
  final encodeResult = Encoder()
      .encode(EncodeInput(value: evaluateResult.value));

  print(encodeResult.text);
  // => "Hello, ExprML!"
}

More examples

API Documentation

https://pub.dev/documentation/exprml_dart/latest/index.html

Libraries

exprml
Provides classes implementing the ExprML API, which includes Encoder, Decoder, Parser, and Evaluator.
exprml_pb
Exports classes generated by protobuf. The source files are provided in https://github.com/exprml/exprml-api .