Class: Korekto::Statements

Inherits:
Object
  • Object
show all
Defined in:
lib/korekto/statements.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStatements

Returns a new instance of Statements.



5
6
7
8
9
10
# File 'lib/korekto/statements.rb', line 5

def initialize
  @statements = []
  @heap = Heap.new Korekto.heap
  @symbols = Symbols.new
  @syntax = Syntax.new
end

Instance Attribute Details

#heapObject (readonly)

Returns the value of attribute heap.



3
4
5
# File 'lib/korekto/statements.rb', line 3

def heap
  @heap
end

#symbolsObject (readonly)

Returns the value of attribute symbols.



3
4
5
# File 'lib/korekto/statements.rb', line 3

def symbols
  @symbols
end

#syntaxObject (readonly)

Returns the value of attribute syntax.



3
4
5
# File 'lib/korekto/statements.rb', line 3

def syntax
  @syntax
end

Instance Method Details

#add(statement, code, title, filename) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/korekto/statements.rb', line 16

def add(statement,code,title,filename)
  c = code[0]; w = c=='W'
  if (restatement=@statements.detect{(w || _1.type==c) && _1.to_s==statement})
    unless 'DXSPTCR'.include?(restatement.type)
      # Only allow heap-able statements to be restated.
      raise Error, "restatement: #{restatement.code}"
    end
    @heap.add restatement
    code, = restatement.code
    title ||= restatement.title
    return code, title
  end
  statement_number = yield
  statement=Statement.new(statement,code,title,filename,statement_number,self)
  @statements.push statement
  @symbols.define! statement if 'AIEMLDXS'.include?(statement.type)
  @heap.add statement if 'DXSPTCR'.include?(statement.type)
  [statement.code, statement.title]
end

#lastObject



14
# File 'lib/korekto/statements.rb', line 14

def last    = @statements.last

#lengthObject



13
# File 'lib/korekto/statements.rb', line 13

def length  = @statements.length

#type(c) ⇒ Object



12
# File 'lib/korekto/statements.rb', line 12

def type(c) = @statements.select{_1.type==c}