metasm/preprocessor.rb in metasm-1.0.3 vs metasm/preprocessor.rb in metasm-1.0.4

- old
+ new

@@ -1174,11 +1174,11 @@ return end op = op.dup op.raw << ntok.raw # ok - when '^', '+', '-', '*', '/', '%', '>>', '<<', '>=', '<=', '||', '&&', '!=', '==' + when '^', '+', '-', '*', '/', '%', '>>', '<<', '>=', '<=', '||', '&&', '!=', '==', '?' # unknown else lexer.unreadtok tok return end @@ -1269,9 +1269,24 @@ while op = readop(lexer) nil while ntok = lexer.readtok and ntok.type == :space lexer.unreadtok ntok until opstack.empty? or Expression::OP_PRIO[op.value][opstack.last] stack << Expression.new(opstack.pop, stack.pop, stack.pop) + end + + if op.value == :'?' + a1 = parse(lexer) + if not tok = lexer.readtok or tok.type != :punct or tok.raw != ':' + raise op, 'expected ":" ternary operator' + end + a2 = parse(lexer) + case Expression[stack.pop].reduce + when 0; stack << a2 + when ::Integer; stack << a1 + else; stack << a2 + end + + next end opstack << op.value raise op, 'need rhs' if not e = parse_value(lexer)