lib/starlark_compiler/writer.rb in starlark_compiler-0.1.0 vs lib/starlark_compiler/writer.rb in starlark_compiler-0.2.0

- old
+ new

@@ -46,10 +46,14 @@ def write_string(str) io << str.str.inspect end + def write_number(number) + io << number.number.to_s + end + def delegate(template, obj) snake_case = lambda do |str| return str.downcase if str =~ /^[A-Z_]+$/ str.gsub(/\B[A-Z]/, '_\&').squeeze('_') =~ /_*(.*)/ @@ -61,11 +65,11 @@ method = template % snake_case[name] return send(method, obj) if respond_to?(method) cls = cls.superclass end - raise Error, "No #{template} for #{obj.class}" + raise "No #{template} for #{obj.class}" end def write_function_call(call) single_line = single_line?(call) io << call.name << '(' @@ -155,9 +159,17 @@ delegate('single_line_%s?', node) end def single_line_string?(str) str.str.size <= 50 + end + + def single_line_number?(_) + true + end + + def single_line_binary_operator?(operator) + single_line?(operator.lhs) && single_line?(operator.rhs) end def single_line_function_call?(call) if call.args.empty? call.kwargs.size <= 1 &&