1.3.0 • Published 3 years ago

@covopen/covscript v1.3.0

Weekly downloads
38
License
See license file
Repository
github
Last release
3 years ago

covscript

This repo contains a parser and a generator for Covscript, a minimal language used for formulating Covquestions questionaires.

The language is compiled to a subset of JSON-logic. JSON-logic expressions can be converted back to Covscript.

Syntax and supported ops

A program in Covscript is always a single expression. The result of the expression is the result of the program.

The following literals are supported:

  • Numeric constants (1, -2, 3.5, 1e+3)
  • Boolean constants (true, false)
  • Quote-Delimeted String constants ("Hello")
  • Vaiables (question3.value)

The following binary operations are supported:

  • Arithmetic operands (+, -, *, /)
  • Logical operands (and, or)
  • Comparisons (>, <, <=, >=, ==, !=)
  • In-Operator for lists (in)
  • Unary logical negation (!)

Also, there is an inline If, parantheses are supported.

The operator precedence follows JavaScript precedence, or in other words, it does what you would expect.

Examples

If work.value == "medical" Then
    "ShowMedicalAdvisory"
Else
    If has_fever.value Then
        "ShowHighRisk"
    Else
        "ShowLowRisk"
    EndIf
EndIf
If contact_date.value > symptoms_date.value Then "StayHome" Else "AlsoStayHome" EndIf

For more examples, please have a look at the unit tests.

Using the Parser

import { CovscriptToJsonLogicConverter } from "../src";

const parser = new CovscriptToJsonLogicConverter();

const res = parser.parse("1 + 2");

console.log(res); // { '+': [1, 2] }

Converting back to Covscript

import { CovscriptGenerator } from "../src/generator";

const generator = new CovscriptGenerator();

const rendered = generator.generate({ "+": [1, 2] });

console.log(res); // '1 + 2'
1.3.0

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.13

3 years ago

1.0.11

3 years ago

1.0.12

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.10

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.2

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.0.0-dev

3 years ago