Class: Oppen::Wadler
- Inherits:
-
Object
- Object
- Oppen::Wadler
- Defined in:
- lib/wadler/print.rb
Overview
Wadler.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#current_indent ⇒ Object
readonly
Returns the value of attribute current_indent.
-
#margin ⇒ Object
readonly
Returns the value of attribute margin.
-
#new_line ⇒ Object
readonly
Returns the value of attribute new_line.
-
#out ⇒ Object
readonly
Returns the value of attribute out.
-
#space ⇒ Object
readonly
Returns the value of attribute space.
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
Instance Method Summary collapse
- #break(offset = 0) ⇒ Nil
- #breakable(str = ' ') ⇒ Nil
- #group(indent = 0, open_obj = '', close_obj = '', break_type = Oppen::Token::BreakType::CONSISTENT) { ... } ⇒ Nil
-
#initialize(config: Config.wadler, space: ' ', margin: 80, new_line: "\n", out: StringIO.new) ⇒ Wadler
constructor
A new instance of Wadler.
- #nest(indent, break_type = Oppen::Token::BreakType::CONSISTENT, &block) ⇒ Nil
- #output ⇒ String
- #text(value) ⇒ Nil
Constructor Details
#initialize(config: Config.wadler, space: ' ', margin: 80, new_line: "\n", out: StringIO.new) ⇒ Wadler
Returns a new instance of Wadler.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/wadler/print.rb', line 25 def initialize(config: Config.wadler, space: ' ', margin: 80, new_line: "\n", out: StringIO.new) @config = config @current_indent = 0 @space = space @margin = margin @new_line = new_line @out = out @tokens = [] end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/wadler/print.rb', line 7 def config @config end |
#current_indent ⇒ Object (readonly)
Returns the value of attribute current_indent.
8 9 10 |
# File 'lib/wadler/print.rb', line 8 def current_indent @current_indent end |
#margin ⇒ Object (readonly)
Returns the value of attribute margin.
10 11 12 |
# File 'lib/wadler/print.rb', line 10 def margin @margin end |
#new_line ⇒ Object (readonly)
Returns the value of attribute new_line.
11 12 13 |
# File 'lib/wadler/print.rb', line 11 def new_line @new_line end |
#out ⇒ Object (readonly)
Returns the value of attribute out.
12 13 14 |
# File 'lib/wadler/print.rb', line 12 def out @out end |
#space ⇒ Object (readonly)
Returns the value of attribute space.
9 10 11 |
# File 'lib/wadler/print.rb', line 9 def space @space end |
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens.
13 14 15 |
# File 'lib/wadler/print.rb', line 13 def tokens @tokens end |
Instance Method Details
#break(offset = 0) ⇒ Nil
108 109 110 |
# File 'lib/wadler/print.rb', line 108 def break(offset = 0) tokens << Oppen.line_break(offset:) end |
#breakable(str = ' ') ⇒ Nil
101 102 103 |
# File 'lib/wadler/print.rb', line 101 def breakable(str = ' ') tokens << Oppen.break(str, offset: current_indent) end |
#group(indent = 0, open_obj = '', close_obj = '', break_type = Oppen::Token::BreakType::CONSISTENT) { ... } ⇒ Nil
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/wadler/print.rb', line 52 def group(indent = 0, open_obj = '', close_obj = '', break_type = Oppen::Token::BreakType::CONSISTENT, &) tokens << case break_type in Oppen::Token::BreakType::CONSISTENT Oppen.begin_consistent(offset: indent) in Oppen::Token::BreakType::INCONSISTENT Oppen.begin_inconsistent(offset: indent) end if !open_obj.empty? self.break text(open_obj) end yield if !close_obj.empty? self.break text(close_obj) end tokens << Oppen.end end |
#nest(indent, break_type = Oppen::Token::BreakType::CONSISTENT, &block) ⇒ Nil
81 82 83 84 85 86 87 88 89 |
# File 'lib/wadler/print.rb', line 81 def nest(indent, break_type = Oppen::Token::BreakType::CONSISTENT, &block) @current_indent += indent raise LocalJumpError if !block_given? block.call ensure @current_indent -= indent end |
#output ⇒ String
37 38 39 40 41 42 |
# File 'lib/wadler/print.rb', line 37 def output if !tokens.last.is_a? Oppen::Token::EOF tokens << Oppen.eof end Oppen.print(tokens:, margin:, new_line:, config:, space:, out:) end |
#text(value) ⇒ Nil
94 95 96 |
# File 'lib/wadler/print.rb', line 94 def text(value) tokens << Oppen.string(value) end |