Class: SeeingIsBelieving

Inherits:
Object
  • Object
show all
Includes:
TracksLineNumbersSeen
Defined in:
lib/seeing_is_believing.rb,
lib/seeing_is_believing/error.rb,
lib/seeing_is_believing/queue.rb,
lib/seeing_is_believing/binary.rb,
lib/seeing_is_believing/result.rb,
lib/seeing_is_believing/version.rb,
lib/seeing_is_believing/has_exception.rb,
lib/seeing_is_believing/expression_list.rb,
lib/seeing_is_believing/syntax_analyzer.rb,
lib/seeing_is_believing/hard_core_ensure.rb,
lib/seeing_is_believing/binary/arg_parser.rb,
lib/seeing_is_believing/binary/line_formatter.rb,
lib/seeing_is_believing/evaluate_by_moving_files.rb,
lib/seeing_is_believing/tracks_line_numbers_seen.rb,
lib/seeing_is_believing/binary/print_results_next_to_lines.rb

Overview

note:

reserve -e for script in an argument
reserve -I for setting load path
reserve -r for requiring another file

Defined Under Namespace

Modules: HasException, TracksLineNumbersSeen Classes: Binary, EvaluateByMovingFiles, ExpressionList, HardCoreEnsure, Queue, Result, SyntaxAnalyzer, TempFileAlreadyExists

Constant Summary collapse

BLANK_REGEX =
/\A\s*\Z/
SeeingIsBelievingError =

all our errors will inherit from this so that a user can catch any error generated by this lib

Class.new StandardError
VERSION =
'0.0.10'

Constants included from TracksLineNumbersSeen

TracksLineNumbersSeen::INITIAL_LINE_NUMBER

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TracksLineNumbersSeen

#max_line_number, #min_line_number, #track_line_number

Constructor Details

#initialize(string_or_stream, options = {}) ⇒ SeeingIsBelieving

Returns a new instance of SeeingIsBelieving.



18
19
20
21
22
23
24
25
# File 'lib/seeing_is_believing.rb', line 18

def initialize(string_or_stream, options={})
  @string          = string_or_stream
  @stream          = to_stream string_or_stream
  @matrix_filename = options[:matrix_filename]
  @filename        = options[:filename]
  @stdin           = to_stream options.fetch(:stdin, '')
  @line_number     = 1
end

Class Method Details

.call(*args) ⇒ Object



14
15
16
# File 'lib/seeing_is_believing.rb', line 14

def self.call(*args)
  new(*args).call
end

Instance Method Details

#callObject

:( refactor me



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/seeing_is_believing.rb', line 28

def call
  @memoized_result ||= begin
    # extract leading comments, leading =begin and magic comments can't be wrapped for exceptions without breaking
    leading_comments = ''
    while next_line_queue.peek =~ /^\s*#/
      leading_comments << next_line_queue.dequeue << "\n"
      @line_number += 1
    end
    while next_line_queue.peek == '=begin'
      lines = next_line_queue.dequeue << "\n"
      @line_number += 1
      until SyntaxAnalyzer.begin_and_end_comments_are_complete? lines
        lines << next_line_queue.dequeue << "\n"
        @line_number += 1
      end
      leading_comments << lines
    end

    # extract program
    program = ''
    until next_line_queue.peek.nil? || data_segment?
      expression, expression_size = expression_list.call
      program << expression
      track_line_number @line_number
      @line_number += expression_size
    end
    program = leading_comments + record_exceptions_in(program)

    # extract data segment
    program << "\n" << the_rest_of_the_stream if data_segment?
    result_for program, min_line_number, max_line_number
  end
end