Class: Einstein::PrettyPrinter
- Defined in:
- lib/einstein/pretty_printer.rb
Overview
This processor walks the AST and builds a “pretty print” of the values. This means that it returns an unambiguous string representation of the tree. All binary expressions are wrapped in parentheses.
Instance Method Summary collapse
-
#process_add(exp) ⇒ Object
Example: (5 + 8).
-
#process_bitwise_and(exp) ⇒ Object
Example: (4 & 16).
-
#process_bitwise_not(exp) ⇒ Object
Example: ~4.
-
#process_bitwise_or(exp) ⇒ Object
Example: (4 | 6).
-
#process_bitwise_xor(exp) ⇒ Object
Example: (4 ^ 6).
-
#process_divide(exp) ⇒ Object
Example: (6 / 3).
-
#process_exponent(exp) ⇒ Object
Example: (2 ** 3).
-
#process_lit(exp) ⇒ Object
Example: 4.
-
#process_lshift(exp) ⇒ Object
Example: (8 << 2).
-
#process_modulus(exp) ⇒ Object
Example: (7 % 3).
-
#process_multiply(exp) ⇒ Object
Example: (2 * 3).
-
#process_resolve(exp) ⇒ Object
Example: x.
-
#process_rshift(exp) ⇒ Object
Example: (8 >> 2).
-
#process_subtract(exp) ⇒ Object
Example: (6 - 3).
-
#process_unary_minus(exp) ⇒ Object
Example: -4.
-
#process_unary_plus(exp) ⇒ Object
Example: +4.
Methods inherited from Processor
Instance Method Details
#process_add(exp) ⇒ Object
Example: (5 + 8)
49 50 51 |
# File 'lib/einstein/pretty_printer.rb', line 49 def process_add(exp) binary_op("+", exp) end |
#process_bitwise_and(exp) ⇒ Object
Example: (4 & 16)
69 70 71 |
# File 'lib/einstein/pretty_printer.rb', line 69 def process_bitwise_and(exp) binary_op("&", exp) end |
#process_bitwise_not(exp) ⇒ Object
Example: ~4
24 25 26 |
# File 'lib/einstein/pretty_printer.rb', line 24 def process_bitwise_not(exp) unary_op("~", exp) end |
#process_bitwise_or(exp) ⇒ Object
Example: (4 | 6)
79 80 81 |
# File 'lib/einstein/pretty_printer.rb', line 79 def process_bitwise_or(exp) binary_op("|", exp) end |
#process_bitwise_xor(exp) ⇒ Object
Example: (4 ^ 6)
74 75 76 |
# File 'lib/einstein/pretty_printer.rb', line 74 def process_bitwise_xor(exp) binary_op("^", exp) end |
#process_divide(exp) ⇒ Object
Example: (6 / 3)
39 40 41 |
# File 'lib/einstein/pretty_printer.rb', line 39 def process_divide(exp) binary_op("/", exp) end |
#process_exponent(exp) ⇒ Object
Example: (2 ** 3)
29 30 31 |
# File 'lib/einstein/pretty_printer.rb', line 29 def process_exponent(exp) binary_op("**", exp) end |
#process_lit(exp) ⇒ Object
Example: 4
9 10 11 |
# File 'lib/einstein/pretty_printer.rb', line 9 def process_lit(exp) exp[1].to_s end |
#process_lshift(exp) ⇒ Object
Example: (8 << 2)
59 60 61 |
# File 'lib/einstein/pretty_printer.rb', line 59 def process_lshift(exp) binary_op("<<", exp) end |
#process_modulus(exp) ⇒ Object
Example: (7 % 3)
44 45 46 |
# File 'lib/einstein/pretty_printer.rb', line 44 def process_modulus(exp) binary_op("%", exp) end |
#process_multiply(exp) ⇒ Object
Example: (2 * 3)
34 35 36 |
# File 'lib/einstein/pretty_printer.rb', line 34 def process_multiply(exp) binary_op("*", exp) end |
#process_resolve(exp) ⇒ Object
Example: x
84 85 86 |
# File 'lib/einstein/pretty_printer.rb', line 84 def process_resolve(exp) exp[1] end |
#process_rshift(exp) ⇒ Object
Example: (8 >> 2)
64 65 66 |
# File 'lib/einstein/pretty_printer.rb', line 64 def process_rshift(exp) binary_op(">>", exp) end |
#process_subtract(exp) ⇒ Object
Example: (6 - 3)
54 55 56 |
# File 'lib/einstein/pretty_printer.rb', line 54 def process_subtract(exp) binary_op("-", exp) end |
#process_unary_minus(exp) ⇒ Object
Example: -4
19 20 21 |
# File 'lib/einstein/pretty_printer.rb', line 19 def process_unary_minus(exp) unary_op("-", exp) end |
#process_unary_plus(exp) ⇒ Object
Example: +4
14 15 16 |
# File 'lib/einstein/pretty_printer.rb', line 14 def process_unary_plus(exp) unary_op("+", exp) end |