kevinpt / opbasm

Open PicoBlaze Assembler
http://kevinpt.github.io/opbasm/
MIT License
60 stars 13 forks source link

Use simpler regex for matching C-style constructs #18

Closed nrother closed 7 years ago

nrother commented 7 years ago

The current regex for matching a C-style if is if\s*\(([^)]*)\)(?:\s*;.*\n)*\s*{. This causes problems with code like if (regupper(rx) == 0) { because of additional parentheses. When using this following, simpler regex, this works without problems: if\s*\((.*)\)(?:\s*;.*\n)*\s*{.

Is there any specific reason for the first form of the regex? This method also removes the special handling for the signed() macro.

kevinpt commented 7 years ago

I was avoiding the greedy match behavior of ".*" as it could potentially consume more text than intended. I have revised the regexes to use non-greedy matching so that nested parens can be used in expressions.