michael-buschbeck / mychs-macro-magic

A simple, sane, and friendly little scripting language for your Roll20 macros.
MIT License
1 stars 1 forks source link

Add `for` syntax variant to iterate over number ranges #115

Open michael-buschbeck opened 3 years ago

michael-buschbeck commented 3 years ago

With the new list[idx] operator and the upcoming delay command (#114), looping over indices and arbitrary number ranges (e.g. coordinates) becomes useful.

michael-buschbeck commented 3 years ago

Syntax proposal:

...which poses a problem to the current command parser, which isn't really all that clever about expression syntax (so right now expressions are always the last part of any command).

The new expression parser (see #85) would be more than capable of recognizing a command token (like to or step) at a position where the expression could validly end (i.e. where the endOfExpression rule is in the expected set).

The command parser should be made aware of higher-level constructs (e.g. "here comes a variable name" instead of "here comes this arbitrary regex"). At a point where the first expression is expected, it should use the expression tokenizer on the rest of the line and invoke the expression parser on the pre-tokenized line giving a set of valid "stop tokens" to accept in place of endOfExpression (and the parser should return the matched stop token and its position on the list).