diff --git a/lib/unparser/writer/binary.rb b/lib/unparser/writer/binary.rb index db2025ab..907b622a 100644 --- a/lib/unparser/writer/binary.rb +++ b/lib/unparser/writer/binary.rb @@ -52,9 +52,13 @@ def symbol_name end def dispatch - left_emitter.write_to_buffer - write(' ', MAP.fetch(effective_symbol), ' ') - visit(right) + if node.type.eql?(:and) && left.type.equal?(:or) + emit_with(KEYWORD_TOKENS) + else + left_emitter.write_to_buffer + write(' ', MAP.fetch(effective_symbol), ' ') + visit(right) + end end private diff --git a/test/corpus/semantic/and.rb b/test/corpus/semantic/and.rb index 43d17124..bdfa8bcd 100644 --- a/test/corpus/semantic/and.rb +++ b/test/corpus/semantic/and.rb @@ -6,3 +6,13 @@ if a...b and c...d end + +a and b and c +(a and b) and c +a and (b and c) +a and b or c +(a and b) or c +a and (b or c) +a or b and c +(a or b) and c +a or (b and c) diff --git a/test/corpus/semantic/or.rb b/test/corpus/semantic/or.rb new file mode 100644 index 00000000..5d404df1 --- /dev/null +++ b/test/corpus/semantic/or.rb @@ -0,0 +1 @@ +a[:x] = b[:x] || c[:x] || d(:new)