Class: Processor

Inherits:
Object show all
Includes:
Livetext::Standard
Defined in:
lib/livetext/processor.rb

Overview

Class Processor does the actual work of processing input.

Constant Summary collapse

GenericError =
Class.new(StandardError)
Disallowed =
%i[ __binding__        __id__            __send__          class
clone              display           dup               enum_for
eql?               equal?            extend            freeze
frozen?            hash              inspect           instance_eval   
instance_exec      instance_of?      is_a?             kind_of?
method             methods           nil?              object_id          
pretty_inspect     private_methods   protected_methods public_method
public_methods     public_send       respond_to?       send
singleton_class    singleton_method  singleton_methods taint
tainted?           tap               to_enum           to_s
trust              untaint           untrust           untrusted?
define_singleton_method              instance_variable_defined?
instance_variable_get                instance_variable_set
remove_instance_variable             instance_variables ]

Constants included from Livetext::Standard

Livetext::Standard::SimpleFormats, Livetext::Standard::TTY

Constants included from Livetext::Helpers

Livetext::Helpers::Comment, Livetext::Helpers::DollarDot, Livetext::Helpers::DotCmd, Livetext::Helpers::ESCAPING, Livetext::Helpers::Sigil, Livetext::Helpers::Space, Livetext::Helpers::TTY

Instance Attribute Summary collapse

Attributes included from Livetext::Standard

#data

Instance Method Summary collapse

Methods included from Livetext::Standard

#backtrace, #banner, #bits, #br, #cinclude, #cleanup, #comment, #copy, #debug, #dlist, #dot_def, #dot_include, #errout, #func, #h1, #h2, #h3, #h4, #h5, #h6, #heading, #heredoc, #heredoc!, #image, #import, #inherit, #link, #list, #list!, #mixin, #mono, #newpage, #nopara, #nopass, #para, #passthru, #quit, #r, #raw, #reflection, #say, #seek, #set, #shell, #shell!, #ttyout, #variables, #variables!, #xtable

Methods included from Livetext::Helpers

#check_disallowed, #check_file_exists, #debug, #escape_html, #find_file, #friendly_error, #get_name_data, #grab_file, #handle_dollar_dot, #handle_dotcmd, #handle_scomment, #include_file, #invoke_dotcmd, #onoff, #process_file, #process_line, #read_variables, rx, #search_upward, #set_variables, #setfile, #setfile!, #setvar, #showme

Constructor Details

#initialize(parent, output = nil) ⇒ Processor

Returns a new instance of Processor.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/livetext/processor.rb', line 28

def initialize(parent, output = nil)
  @parent = parent
  # STDERR.puts "PARENT.api = #{parent.api.inspect}"
  @parent.api ||= Livetext::UserAPI.new(@parent)
  @nopass = false
  @nopara = false
  # Meh?
  @output = ::Livetext.output = (output || File.open("/dev/null", "w"))
  @sources = []
  @indentation = @parent.indentation
  @_mixins = []
  @_imports = []
  @html = HTML.new(@parent.api)
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



26
27
28
# File 'lib/livetext/processor.rb', line 26

def parent
  @parent
end

#sourcesObject (readonly)

Returns the value of attribute sources.



26
27
28
# File 'lib/livetext/processor.rb', line 26

def sources
  @sources
end

Instance Method Details

#_error!(err, raise_error = false, trace = false) ⇒ Object

FIXME much bullshit happens here

Raises:



59
60
61
62
63
64
# File 'lib/livetext/processor.rb', line 59

def _error!(err, raise_error=false, trace=false)   # FIXME much bullshit happens here
  where = @sources.last || @live.save_location
  error "Error: #{err} (at #{where[1]} line #{where[2]})"
  error(err.backtrace) rescue nil
  raise GenericError.new("Error: #{err}") if raise_error
end

#apiObject



43
44
45
# File 'lib/livetext/processor.rb', line 43

def api
  @parent.api   # FIXME Is this weird??
end

#disallowed?(name) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
69
70
# File 'lib/livetext/processor.rb', line 66

def disallowed?(name)
  flag = Disallowed.include?(name.to_sym)
# api.tty "disa name = #{name.inspect} flag = #{flag}"
  flag
end

#error(*args) ⇒ Object



55
56
57
# File 'lib/livetext/processor.rb', line 55

def error(*args)
  ::STDERR.puts *args
end

#htmlObject



47
48
49
# File 'lib/livetext/processor.rb', line 47

def html
  @html
end

#nextlineObject



89
90
91
92
93
94
95
96
97
# File 'lib/livetext/processor.rb', line 89

def nextline
  return nil if @sources.empty?
  line = @sources.last[0].next
  @sources.last[2] += 1
  line
rescue StopIteration
  @sources.pop
  nil
end

#output=(io) ⇒ Object



51
52
53
# File 'lib/livetext/processor.rb', line 51

def output=(io)
  @output = io
end

#peek_nextlineObject



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/livetext/processor.rb', line 76

def peek_nextline
  return nil if @sources.empty?
  source = @sources.last
  line = source[0].peek
  line
rescue StopIteration
  @sources.pop
  nil
rescue => err
  TTY.puts "#{__method__}: RESCUE err = #{err.inspect}"
  nil
end

#source(enum, file, line) ⇒ Object



72
73
74
# File 'lib/livetext/processor.rb', line 72

def source(enum, file, line)
  @sources.push([enum, file, line])
end