opened
ericman314
username_0
What characters are allowed in variable names (`SymbolNode`)? I couldn't find anything in the docs.
What are the allowed characters in variable names?
issue
created
ericman314
username_0
After digging through `parse.js`, I have come up with the following. Please correct any inaccuracies.

Variables must:
* Begin with an "alpha character", which is:
     * A latin letter (upper or lower case) Ascii: a-z, A-Z
     * A underscore                         Ascii: _
     * A latin letter with accents          Unicode: \u00C0 - \u02AF
     * A greek letter                       Unicode: \u0370 - \u03FF
     * A mathematical alphanumeric symbol   Unicode: \u{1D400} - \u{1D7FF} excluding invalid code      points
* Contain only alpha characters (above) and digits 0-9
* Not be any of the following: `mod`, `to`, `in`, `and`, `xor`, `or`, `not` (Actually it is possible to assign to some of these, but that's probably not recommended)
comment
created
josdejong
username_1
Good point, we should describe the allowed characters to the docs. 

It would also be cool to somehow provide your own `isValidCharacter` function, allowing to extend for example with a character like `²` or other sets of characters.
comment
created
rafaljanicki
username_2
+1 for the isValidCharacter

In our case, we use variables which may start with a number, but it's not a number, but a string. Currently, the MathJS throws an "Undefined symbol" error.

So, we'd need either isValidCharacter function (or isValidSymbol) or a possibility to escape a symbol
comment
created
josdejong
username_1
hm, that won't work with the parser since a variable starting with a number, say `1foo` will be parsed as an implicit multiplication `1 * foo`. I think you will have to look into a different direction to allow symbols starting with a number. If you know the defined symbols beforehand, you could preprocess your expression with a regexp and replace them with say `_1bar` for example.
comment
created
rafaljanicki
username_2
That's exactly what I've done for now, but I'm not happy with the solution - it requires two additional loops (per level) on the object. That's why it'd be nice to specify own parser rules, so it can be adjusted for custom cases (additionally, we don't use shorthand for 1*foo, so the feature is "useless" for us)
comment
created
josdejong
username_1
Yes, it' not ideal having to do pre-processing steps like that, but this is something we can't change in the parser to fit your needs. If your needs are too different from the parser of math.js, you could consider generating your own parser, have a look at [jison](http://zaa.ch/jison/) and [peg](http://pegjs.org/).
comment