Expressions improvements: escape chars and unicode #1333
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New features:
Includes unit tests and documentation
Escaping characters
If variables have names which include symbols like + then expressions need to escape the symbols to avoid treating them as arithmetic operators. This can be important when evolving variables with names
like "H+" or "He+2".
Two mechanisms currently allowed:
A backslash () escapes the following character, so an expression could include something like "h2+:density" as a symbol
Backquotes escape a sequence of characters, so "
h2+:density
" or "h2+
:density" could be used.Note that the colon symbol always indicates section, and is not escaped. This is to avoid ambiguity. The options reader therefore checks if keys include
:
and throws if they do.Unicode names
The reader has been made less strict about what it accepts as a valid symbol. Rules are:
:
(as reserved for sections).
(or it will be read as a number). These can be escaped.When referred to in an expression, arithmetic operators, brackets, commas (
+-*/^(){}[],
) and whitespace must be escaped.Implicit multiplication
If a number is followed by a symbol or an opening bracket, then a multiplication is assumed. This is a nice (I think) feature of Julia which reduces clutter in expressions.
3sin(2π*x)
or3 sin(2 π * x)
are equivalent to3*sin(2*pi*x)
.