Module: Oppen

Defined in:
lib/oppen.rb,
lib/oppen/token.rb,
lib/oppen/utils.rb,
lib/wadler/print.rb,
lib/oppen/printer.rb,
lib/oppen/version.rb,
lib/oppen/scan_stack.rb,
lib/oppen/print_stack.rb

Overview

Oppen.

Defined Under Namespace

Modules: Utils Classes: Config, PrintStack, Printer, ScanStack, Token, Wadler

Constant Summary collapse

VERSION =

Oppen version

Returns:

  • (String)

    current version

'0.9.1'

Class Method Summary collapse

Class Method Details

.begin_consistent(offset: 2) ⇒ Oppen::Token::Begin

Returns a new consistent Begin token.

Parameters:

  • offset (Integer) (defaults to: 2)

Returns:



132
133
134
# File 'lib/oppen.rb', line 132

def self.begin_consistent(offset: 2)
  Token::Begin.new(break_type: Token::BreakType::CONSISTENT, offset:)
end

.begin_inconsistent(offset: 2) ⇒ Oppen::Token::Begin

Returns a new inconsistent Begin token.

Parameters:

  • offset (Integer) (defaults to: 2)

Returns:



139
140
141
# File 'lib/oppen.rb', line 139

def self.begin_inconsistent(offset: 2)
  Token::Begin.new(break_type: Token::BreakType::INCONSISTENT, offset:)
end

.break(str = ' ', line_continuation: '', offset: 0, width: str.length) ⇒ Oppen::Token::Break

Returns a new Break token.

Parameters:

  • str (String) (defaults to: ' ')
  • line_continuation (String) (defaults to: '')

    If a new line is needed display this string before the new line

  • offset (Integer) (defaults to: 0)
  • width (Integer) (defaults to: str.length)

    token width that defaults to str.length

Returns:



117
118
119
# File 'lib/oppen.rb', line 117

def self.break(str = ' ', line_continuation: '', offset: 0, width: str.length)
  Token::Break.new(str, width:, line_continuation:, offset:)
end

.endOppen::Token::End

Returns a new End token.

Returns:



144
145
146
# File 'lib/oppen.rb', line 144

def self.end
  Token::End.new
end

.eofOppen::Token::EOF

Returns a new EOF token.

Returns:



149
150
151
# File 'lib/oppen.rb', line 149

def self.eof
  Token::EOF.new
end

.line_break(line_continuation: '', offset: 0) ⇒ Oppen::Token::LineBreak

Returns a new LineBreak token.

Parameters:

  • line_continuation (String) (defaults to: '')

    If a new line is needed display this string before the new line

  • offset (Integer) (defaults to: 0)

Returns:



125
126
127
# File 'lib/oppen.rb', line 125

def self.line_break(line_continuation: '', offset: 0)
  Token::LineBreak.new(line_continuation:, offset:)
end

Entry point of the pretty printer.

Parameters:

  • config (Config) (defaults to: Config.oppen)
  • space (String, Proc) (defaults to: ' ')

    could be a String or a callable. If it's a string, spaces will be generated with the the lambda ->(n){ n * space }, where n is the number of columns to indent. If it's a callable, it will receive n and it needs to return a string.

  • new_line (String) (defaults to: "\n")

    the delimiter between lines

  • out (Object) (defaults to: StringIO.new)

    should have a write and string method

  • tokens (Array[Token]) (defaults to: [])

    the list of tokens to be printed

  • width (Integer) (defaults to: 80)

    maximum line width desired

Returns:

  • (String)

    output of the pretty printer



27
28
29
30
31
32
33
34
# File 'lib/oppen.rb', line 27

def self.print(config: Config.oppen, space: ' ',
               new_line: "\n", out: StringIO.new, tokens: [], width: 80)
  printer = Printer.new width, new_line, config, space, out
  tokens.each do |token|
    printer.print token
  end
  printer.output
end

.string(value, width: value.length) ⇒ Oppen::Token::String

Returns a new String token.

Parameters:

  • value (String)
  • width (Integer) (defaults to: value.length)

    token width that defaults to value.length

Returns:



107
108
109
# File 'lib/oppen.rb', line 107

def self.string(value, width: value.length)
  Token::String.new(value, width:)
end