Class: Nasl::Function

Inherits:
Node
  • Object
show all
Defined in:
lib/nasl/parser/function.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#ctx, #tokens

Instance Method Summary collapse

Methods inherited from Node

#context, #region, #to_xml

Constructor Details

#initialize(tree, *tokens) ⇒ Function

Returns a new instance of Function.



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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/nasl/parser/function.rb', line 33

def initialize(tree, *tokens)
  super

  @body = @tokens.last
  @fn_type = @tokens[1]

  if @fn_type == "obj"
    if @tokens.length == 8 
      @name = @tokens[3]
      @attribute = @tokens[0]
      @params = @tokens[5]          
    elsif @tokens.length == 7
      if @tokens[0].is_a?(Token) && @tokens[0].type == :FUNCTION
        @attribute = nil
        @params = @tokens[4]
        @name = @tokens[2]
      else
        @name = @tokens[3]
        @attribute = @tokens[0]
        @params = []
      end
	elsif @tokens.length == 6
      @attribute = nil
      @params = []
      @name = @tokens[2]
    end
  else
    @name = @tokens[2]
    @attribute = []
    if @tokens.length == 7
      @params = @tokens[4]
    else
      @params = []
    end
  end

  @children << :name
  @children << :attribute
  @children << :params
  @children << :body
  @children << :fn_type
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



31
32
33
# File 'lib/nasl/parser/function.rb', line 31

def attribute
  @attribute
end

#bodyObject (readonly)

Returns the value of attribute body.



31
32
33
# File 'lib/nasl/parser/function.rb', line 31

def body
  @body
end

#fn_typeObject (readonly)

Returns the value of attribute fn_type.



31
32
33
# File 'lib/nasl/parser/function.rb', line 31

def fn_type
  @fn_type
end

#nameObject (readonly)

Returns the value of attribute name.



31
32
33
# File 'lib/nasl/parser/function.rb', line 31

def name
  @name
end

#paramsObject (readonly)

Returns the value of attribute params.



31
32
33
# File 'lib/nasl/parser/function.rb', line 31

def params
  @params
end

Instance Method Details

#eachObject



76
77
78
# File 'lib/nasl/parser/function.rb', line 76

def each
  @body.each{ |stmt| yield stmt }
end