class TestML::Compiler::Pegex::AST

Attributes

function[RW]
points[RW]

Public Class Methods

new() click to toggle source
# File lib/testml/compiler/pegex/ast.rb, line 10
def initialize
  @points = []
  @function = TestML::Function.new
end

Public Instance Methods

got_assertion_call(call) click to toggle source
# File lib/testml/compiler/pegex/ast.rb, line 67
def got_assertion_call(call)
  name, expr = nil, nil
  %w( eq has ok ).each do |a|
    if expr = call["assertion_#{a}"]
      name = a.upcase
      expr =
        expr.fetch("assertion_operator_#{a}", [])[0] ||
        expr.fetch("assertion_function_#{a}", [])[0]
      break
    end
  end
  return TestML::Assertion.new(name, expr)
end
got_assertion_function_ok(ok) click to toggle source
# File lib/testml/compiler/pegex/ast.rb, line 81
def got_assertion_function_ok(ok)
  return { 'assertion_function_ok' => [] }
end
got_assignment_statement(match) click to toggle source
# File lib/testml/compiler/pegex/ast.rb, line 19
def got_assignment_statement(match)
  return TestML::Assignment.new(match[0], match[1])
end
got_block_point(point) click to toggle source
# File lib/testml/compiler/pegex/ast.rb, line 142
def got_block_point(point)
  return { point[0] => point[1] }
end
got_call_argument_list(list) click to toggle source
# File lib/testml/compiler/pegex/ast.rb, line 124
def got_call_argument_list(list)
  return list
end
got_call_indicator(dummy) click to toggle source
# File lib/testml/compiler/pegex/ast.rb, line 128
def got_call_indicator(dummy)
  return
end
got_call_name(name) click to toggle source
# File lib/testml/compiler/pegex/ast.rb, line 104
def got_call_name(name)
  return TestML::Call.new(name)
end
got_call_object(object) click to toggle source
# File lib/testml/compiler/pegex/ast.rb, line 108
def got_call_object(object)
  call = object[0]
  args = object[1] && object[1][-1]
  if args
    args = args.map do |arg|
      (arg.kind_of?(TestML::Expression) and arg.calls.size == 1 and
      (
         arg.calls[0].kind_of?(TestML::Point) ||
         arg.calls[0].kind_of?(TestML::Object)
      )) ? arg.calls[0] : arg
    end
    call.args = args
  end
  return call
end
got_code_expression(list) click to toggle source
# File lib/testml/compiler/pegex/ast.rb, line 41
def got_code_expression(list)
  calls = []
  calls.push(list.shift) if !list.empty?
  list = !list.empty? ? list.shift : []
  list.each do |e|
    call = e[1]   # XXX this is e[0] in perl
    calls.push(call)
  end
  return calls[0] if calls.size == 1
  return TestML::Expression.new(calls)
end
got_code_section(code) click to toggle source
# File lib/testml/compiler/pegex/ast.rb, line 15
def got_code_section(code)
  @function.statements = code
end
got_code_statement(list) click to toggle source
# File lib/testml/compiler/pegex/ast.rb, line 23
def got_code_statement(list)
  expression, assertion = nil, nil
  points = @points
  @points = []
  list.each do |e|
    if e.kind_of? TestML::Assertion
      assertion = e
    else
      expression = e
    end
  end
  return TestML::Statement.new(
    expression,
    assertion,
    !points.empty? ? points : nil,
  )
end
got_data_block(block) click to toggle source
# File lib/testml/compiler/pegex/ast.rb, line 136
def got_data_block(block)
  label = block[0][0][0]
  points = block[1].inject({}){|r, h| r.merge!(h)}
  return TestML::Block.new(label, points)
end
got_data_section(data) click to toggle source
# File lib/testml/compiler/pegex/ast.rb, line 132
def got_data_section(data)
  @function.data = data
end
got_function_object(object) click to toggle source
# File lib/testml/compiler/pegex/ast.rb, line 92
def got_function_object(object)
  function = @function
  @function = function.outer

  if object[0].kind_of? Array and object[0][0].kind_of? Array
    function.signature = object[0][0]
  end
  function.statements = object[-1]

  return function
end
got_function_start(dummy) click to toggle source
# File lib/testml/compiler/pegex/ast.rb, line 85
def got_function_start(dummy)
  function = TestML::Function.new
  function.outer = @function
  @function = function
  return true
end
got_number_object(number) click to toggle source
# File lib/testml/compiler/pegex/ast.rb, line 57
def got_number_object(number)
  return TestML::Num.new(number.to_i)
end
got_point_object(point) click to toggle source
# File lib/testml/compiler/pegex/ast.rb, line 61
def got_point_object(point)
  point.sub!(/^\*/, '') or fail
  @points.push(point)
  return TestML::Point.new(point)
end
got_string_object(string) click to toggle source
# File lib/testml/compiler/pegex/ast.rb, line 53
def got_string_object(string)
  return TestML::Str.new(string)
end