Git Product home page Git Product logo

sibyl's Introduction

Sibyl

This is a parser and interpreter for smart answers that aims to address a few challenges with our current embedded Ruby implementations, specifically:

  • Verifying correctness: no cycles, dead ends, or unreachable nodes
  • Retaining readability and terseness
  • Facilitate proofing by showing all steps
  • Have some kind of form that we can share over an API

It's named after the prophets of antiquity. Why Sibyl? Well, I could hardly call it Oracle or Delphi, could I?

Syntax

The syntax is relatively simple, and consists of metadata, steps, and outcomes. The grammar is specified in the file lib/sibyl/parser.rb; some examples follow. Note that white space is not really significant (the indentation and line breaks are just a convention) and that anything between { and } is evaluated as Ruby against a context object.

-- Metadata
metadata need 1660
metadata status published

-- Define a multiple-choice step
step multiple "step a"
  option foo -> "step b"
  option bar -> "step c"

-- Define a direct transition that sets a variable
step number "step c"
  set x { input }
  go -> "step d"

-- Choose a step based on a calculation
step number "step d"
  set y { input }
  go ->
    if { y > x } -> "step e"
    otherwise    -> "step f"

-- or
step multiple "step f"
  option baz ->
    if { something? } -> "step g"
    if { something_else? } -> "step h"
    otherwise -> "step i"
  option quux -> "step j"

-- Reject values that fail a logical test
step number "step k"
  reject { input.odd? }
  go -> "step l"

-- Define final steps
outcome "step l"

Usage

require "sibyl/graph"
graph = Sibyl::Graph.new(source)
graph.validate! # raises an exception if the graph is incorrect
step = graph.at(["yes", "a", "1"])

Validation

Validation checks that:

  • There are steps
  • Each step is valid
  • No step is unreachable
  • Every possible exit leads somewhere
  • The graph is acyclic

sibyl's People

Contributors

threedaymonk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.