language-bash
language-bash copied to clipboard
Arithmetic is not parsed
Looks like arithmetic becomes an ArithSubst String
, and it isn't parsed any further. What's the plan there? Should I instead try to parse the arithmetic strings as C?
I admit that I didn't implement it because my original use case (parsing config files) didn't use arithmetic expressions.
According to the docs, the innards of a $((...))
undergo variable expansion etc before the arithmetic is parsed. So really, we should parse the innards as a Word
instead of a String
. Since this expansion can only be performed at runtime, we can't parse the actual arithmetic expression when we parse the script.
However, it would be nice if we have a side module that can parse arithmetic from a string (similar to the Cond
and Expand
modules). For now, using a C parser could work (like the language-c package).
The fact that there could be command substitutions etc in the arithmetic expression is a little annoying. If you're writing a static analysis tool or a transpiler, maybe you could only accept Word
s that are plain strings in the arithmetic expression to rule out any funny business.
Took me a while to find it so including it here: the bash arithmetic parser: http://git.savannah.gnu.org/cgit/bash.git/tree/expr.c
Entry point from bash is evalexp
.
~~Nope, that's the src to expr
.~~ (Actually it's both!)