krieselreihe / litr

Litr (Language Independent Task Runner) lets you configure and then run any tasks you want for any language.
MIT License
8 stars 0 forks source link

String comparison would be quite handy #51

Open MartinHelmut opened 2 years ago

MartinHelmut commented 2 years ago

Currently there is no easy way to compare in a script against a string value passed by parameter. This would be quite handy though, and there are different ways to tackle this. What this would enable is getting rid of parameters currently used like release, profile or debug, as they could be dependent on the actual build target.

Option 1

One would be adding a comparison operator to the script syntax, that could look like this:

script = "%{target == 'release' 'do this' or 'do that'}"

This would mean introducing a new == operator. BNF would be:

# Entry point:
script = statement | expression

statement = or_statement | if_statement;

expression = comparison
  | function
  | variable
  | literal;

comparison = expression "==" expression

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

or_statement = if_statement "or" expression;

if_statement = expression 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;

Option 2

After implementing #24 there could be a equal(first, second) function serving this. This would look like this:

script = "%{equal(target, 'release') 'do this' or 'do that'}"