Class: SlowBlink::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/slow_blink/group.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idInteger? (readonly)

Returns:

  • (Integer, nil)


32
33
34
# File 'lib/slow_blink/group.rb', line 32

def id
  @id
end

#locationString (readonly)

Location string formatted as: [ FILENAME, ':' ], LINE_NUMBER, ':', COLUMN_NUMBER

Returns:

  • (String)


38
39
40
# File 'lib/slow_blink/group.rb', line 38

def location
  @location
end

#nameString (readonly)

Returns qualified name.

Returns:

  • (String)

    qualified name



35
36
37
# File 'lib/slow_blink/group.rb', line 35

def name
  @name
end

Class Method Details

.===(other) ⇒ Object



27
28
29
# File 'lib/slow_blink/group.rb', line 27

def self.===(other)
    self == other                
end

Instance Method Details

#ancestorsArray<Group>

Returns super groups in order of most super.

Returns:

  • (Array<Group>)

    super groups in order of most super



71
72
73
74
75
76
77
78
79
# File 'lib/slow_blink/group.rb', line 71

def ancestors
    result = []
    ptr = superGroup
    while ptr do
        result << ptr
        ptr = ptr.superGroup
    end
    result
end

#fieldsArray<Field>

Returns:



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
# File 'lib/slow_blink/group.rb', line 41

def fields

    # collect all ancestors
    ancestors = []
    ptr = superGroup
    while ptr do
        ancestors.unshift ptr
        ptr = ptr.superGroup
    end

    result = {}

    ancestors.each do |g|
        g.rawFields.each do |f|
            result[f.name] = f                    
        end
    end

    @fields.each do |fn, fv|
        if result[fn]
            raise ParseError.new "#{fv.location}: field name shadowed by supergroup"
        else
            result[fn] = fv
        end
    end

    result.values
end

#superGroupGroup?

Returns:



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/slow_blink/group.rb', line 82

def superGroup

    result = nil

    if @super

        ptr = @super.resolve
        stack = []
        sequence = false
        dynamic = false

        while ptr and ptr.is_a? Definition and ptr.type.is_a? REF do

            if stack.include? ptr
                raise ParseError.new "#{@super.location}: supergoup circular reference"
            else
                if ptr.type.dynamic?
                    dynamic = true
                end
                if ptr.type.sequence?
                    if sequence
                        raise ParseError.new "#{@super.location}: sequence of sequence detected at '#{ptr.type.location}'"
                    end
                    sequence = true                            
                end
                stack << ptr
                ptr = ptr.type.resolve                        
            end
        end

        if ptr.nil?
            raise ParseError.new "#{@super.location}: supergroup reference '#{@super.ref}' does not resolve"
        elsif ptr.is_a? Definition
            if dynamic
                raise ParseError.new "#{@super.location}: supergroup reference cannot resolve dynamic reference to a #{ptr.type.class} makes no sense"
            end
            raise ParseError.new "#{@super.location}: supergroup reference must resolve to a group"
        else
            if dynamic
                raise ParseError.new "#{@super.location}: supergroup reference cannot be dynamic"
            end
            if sequence
                raise ParseError.new "#{@super.location}: supergroup reference cannot be a sequence"
            end
            if ptr == self
                raise ParseError.new "#{@super.location}: supergroup cannot be own group"
            end
            result = ptr
        end
    end

    result
end