Skip to content

Command script parsing

Martin Helmut Fieber edited this page Aug 17, 2021 · 8 revisions

Example

Command script example from the configuration file:

# litr.toml
build = "echo %{param}"

Parsing

Simplified Backus–Naur form (BNF [reference]):

# Entry point:
script = statement | expression

statement = or_statement | if_statement;

expression = function
  | variable
  | literal;

literal = string;
string = "'" .* "'";

or_statement = if_statement "or" expression;

if_statement = (variable | function) expression;

function = function_name "(" (expression ("," expression)*)? ")";
function_name = alpha (alpha | digit)*;

variable = short_variable | long_variable;
short_variable = strict_alpha;
long_variable = strict_alpha (alpha | digit)+;

digit = 0-9;
alpha = A-Za-z_;
strict_alpha = A-Za-z;

Legend:

  • | Or
  • () Grouping
  • ? Optional
  • * Repeat 0 to n times
  • + Repeat 1 to n times

Examples

# String literal
script = "%{'String'}"
# Variable
script = "%{parameter}"
# If-statement
script = "%{parameter 'String'}"
# Or-statement
script = "%{parameter 'Hello' or 'Bye'}"

After #24 is done also available:

# Function call
script = "%{fn()}"
# Function with parameters and statements
script = "%{fn1(var1, fn2()) 'First option' or fn3('Second option')}"

Clone this wiki locally