class MODL::Parser::Parsed::ParsedArray
Class to represent a parsed grammar object
Attributes
abstractArrayItems[RW]
We now have a list of < array_item | nb_array >
Public Class Methods
new(global)
click to toggle source
# File lib/modl/parser/parsed.rb, line 1326 def initialize(global) @global = global @abstractArrayItems = [] end
Public Instance Methods
enterModl_array(ctx)
click to toggle source
# File lib/modl/parser/parsed.rb, line 1352 def enterModl_array(ctx) # Create the new abstractArrayItems list first, sized to the total of array_item.size and nb_array.size i = 0 previous = nil ctx_children = ctx.children ctx_children.each do |pt| if pt.is_a? MODLParser::Modl_array_itemContext array_item = ParsedArrayItem.new @global pt.enter_rule(array_item) @abstractArrayItems[i] = array_item i += 1 elsif pt.is_a? MODLParser::Modl_nb_arrayContext nb_array = ParsedNbArray.new @global pt.enter_rule(nb_array) @abstractArrayItems[i] = nb_array i += 1 elsif pt.is_a? Antlr4::Runtime::TerminalNode if !previous.nil? && previous.is_a?(Antlr4::Runtime::TerminalNode) && pt.is_a?(Antlr4::Runtime::TerminalNode) # If we get here then we have two terminal nodes in a row, so we need to output something unless # the terminal symbols are newlines # prev_symbol = previous.symbol.type current_symbol = pt.symbol.type if prev_symbol == MODLLexer::LSBRAC && current_symbol == MODLLexer::RSBRAC next # This allows empty arrays end if prev_symbol == MODLLexer::STRUCT_SEP && current_symbol == MODLLexer::STRUCT_SEP # Create something for the blank array item # # The problem is that we might not have any context to tell us what type we need to create # so this currently defaults to the nil # # TODO : Is there a way to know the type to create or is nil always acceptable? array_item = Parsed.handle_empty_array_item @abstractArrayItems[i] = array_item i += 1 end end end previous = pt end end
extract_hash()
click to toggle source
# File lib/modl/parser/parsed.rb, line 1342 def extract_hash result = [] abstractArrayItems.each do |i| result << i.extract_hash end result end
find_property(key)
click to toggle source
# File lib/modl/parser/parsed.rb, line 1331 def find_property(key) if key.is_a? Integer return @abstractArrayItems[key] else @abstractArrayItems.each do |mi| return mi.arrayValueItem.pair if mi.arrayValueItem.pair && mi.arrayValueItem.pair.key == key end nil end end