colis-anr / morbig

A static parser for POSIX Shell
Other
190 stars 8 forks source link

Arithmetic expression parsing #120

Open ishaangandhi opened 3 years ago

ishaangandhi commented 3 years ago

Adds arithmetic expressions to the concrete syntax tree. Previously they were treated as word literals, and not being parsed correctly, especially in cases of nested expressions. IE, $((x += $((2*3)) )) had [(Literal "2"); GlobAll; (Literal "3")] in its parse tree.

I added a new test case, and fixed some existing ones.

This is for ongoing work with @mgree integrating Morbig with the SMOOSH shell.

ishaangandhi commented 3 years ago

Also, please note that the current way of tracking the nested levels of double parenthesis might not be complete. For example, $(( ((2 + 1) * 3) + 4 )) has two double left parenthesis, and only 1 double right parenthesis, but is still a valid arithmetic expression. However, the current function requires # double left = # double right.

I'd be happy to fix this. Since this is an orthogonal bug, however, it might make sense to do so in a new pull request. Let me know what you think.