class Z3::Printer
Constants
- DEFAULT_TRAILING_ARG
-
Z3always spells the starting offset out, Ruby’s String#index / Array#index default it to 0 - so a trailing 0 is noise, and ‘s.index(“a”)` is what anyone would have written - FLIPPED_METHOD_CALL_NAMES
-
Same idea, but
Z3takes the prefix/suffix first and the string second, where Ruby’s String#start_with? / end_with? take it the other way round - so it’s the second argument that prints as the receiver. - METHOD_CALL_NAMES
-
Z3decl name => Ruby method, printed as ‘receiver.method` or `receiver.method(rest)` with the first argument as the receiver.Z3names the same operation `str.foo` for Strings and `seq.foo` for every other Seq, so both spellings map to the one Ruby method - except `replace_all`, whichZ3calls `str.replace_all` even for sequences of non-characters. - OPERATOR_NAMES
-
Lexicographic string comparison. These are operators in Ruby, but their
Z3names contain letters, so the generic operator path doesn’t catch them. - RE_ASSOCIATIVE_NAMES
-
Concat, union and intersection are associative, and
Z3hands them back as a nested binary tree however many arguments they were built with - RE_CONSTANT_NAMES
-
The regexes with no arguments at all, named after the constructors that build them.
Z3calls the empty language ‘re.none` over Strings and `re.empty` over every other sequence sort. - RE_METHOD_NAMES
-
…and the ones that print as methods, since Ruby has no operators to spare
- RE_OPERATOR_NAMES
-
Regex operations that print as Ruby operators on
ReExpr. ‘re.++` is concatenation and `re.+` is one-or-more - differentZ3names, so no clash. - SEQ_CONCAT_NAMES
-
‘str.++` is the same operation as `seq.++`,
Z3just names it differently for String - SEQ_ELEMENT_ARGS
-
Argument positions that take an element-or-subsequence. ‘xs.include?(7)` builds `(seq.contains xs (seq.unit 7))`, and printing that back as `xs.include?()` is correct but isn’t what anyone wrote - Ruby’s Array#include? takes the element, so a lone unit in one of these positions prints as the element it wraps.
Public Instance Methods
Source
# File lib/z3/printer.rb, line 11 def format_value(value) return value.to_s unless value.is_a?(Hash) cases = value.map { |args, result| "(#{args.join(", ")}) => #{result}" } "{#{(cases << "else => #{value.default}").join(", ")}}" end
A model value, which is an Expr for a constant but a Hash for a function. Hash#inspect leaves the default out, and for a function interpretation the default is the answer everywhere the model didn’t say otherwise, so printing without it would be printing the least useful half.