Class: MODL::Parser::Parsed::ParsedArray
- Inherits:
-
MODLParserBaseListener
- Object
- Antlr4::Runtime::ParseTreeListener
- MODLParserListener
- MODLParserBaseListener
- MODL::Parser::Parsed::ParsedArray
- Defined in:
- lib/modl/parser/parsed.rb
Overview
Class to represent a parsed grammar object
Instance Attribute Summary collapse
-
#abstractArrayItems ⇒ Object
We now have a list of < array_item | nb_array >.
Instance Method Summary collapse
- #enterModl_array(ctx) ⇒ Object
- #extract_hash ⇒ Object
- #find_property(key) ⇒ Object
-
#initialize(global) ⇒ ParsedArray
constructor
A new instance of ParsedArray.
Methods inherited from MODLParserBaseListener
#enterModl, #enterModl_array_conditional, #enterModl_array_conditional_return, #enterModl_array_item, #enterModl_array_value_item, #enterModl_condition, #enterModl_condition_group, #enterModl_condition_test, #enterModl_map, #enterModl_map_conditional, #enterModl_map_conditional_return, #enterModl_map_item, #enterModl_nb_array, #enterModl_operator, #enterModl_pair, #enterModl_primitive, #enterModl_structure, #enterModl_top_level_conditional, #enterModl_top_level_conditional_return, #enterModl_value, #enterModl_value_conditional, #enterModl_value_conditional_return, #enterModl_value_item, #enter_every_rule, #exitModl, #exitModl_array, #exitModl_array_conditional, #exitModl_array_conditional_return, #exitModl_array_item, #exitModl_array_value_item, #exitModl_condition, #exitModl_condition_group, #exitModl_condition_test, #exitModl_map, #exitModl_map_conditional, #exitModl_map_conditional_return, #exitModl_map_item, #exitModl_nb_array, #exitModl_operator, #exitModl_pair, #exitModl_primitive, #exitModl_structure, #exitModl_top_level_conditional, #exitModl_top_level_conditional_return, #exitModl_value, #exitModl_value_conditional, #exitModl_value_conditional_return, #exitModl_value_item, #exit_every_rule, #visit_error_node, #visit_terminal
Methods inherited from MODLParserListener
#enterModl, #enterModl_array_conditional, #enterModl_array_conditional_return, #enterModl_array_item, #enterModl_array_value_item, #enterModl_condition, #enterModl_condition_group, #enterModl_condition_test, #enterModl_map, #enterModl_map_conditional, #enterModl_map_conditional_return, #enterModl_map_item, #enterModl_nb_array, #enterModl_operator, #enterModl_pair, #enterModl_primitive, #enterModl_structure, #enterModl_top_level_conditional, #enterModl_top_level_conditional_return, #enterModl_value, #enterModl_value_conditional, #enterModl_value_conditional_return, #enterModl_value_item, #exitModl, #exitModl_array, #exitModl_array_conditional, #exitModl_array_conditional_return, #exitModl_array_item, #exitModl_array_value_item, #exitModl_condition, #exitModl_condition_group, #exitModl_condition_test, #exitModl_map, #exitModl_map_conditional, #exitModl_map_conditional_return, #exitModl_map_item, #exitModl_nb_array, #exitModl_operator, #exitModl_pair, #exitModl_primitive, #exitModl_structure, #exitModl_top_level_conditional, #exitModl_top_level_conditional_return, #exitModl_value, #exitModl_value_conditional, #exitModl_value_conditional_return, #exitModl_value_item
Constructor Details
#initialize(global) ⇒ ParsedArray
Returns a new instance of ParsedArray.
1326 1327 1328 1329 |
# File 'lib/modl/parser/parsed.rb', line 1326 def initialize(global) @global = global @abstractArrayItems = [] end |
Instance Attribute Details
#abstractArrayItems ⇒ Object
We now have a list of < array_item | nb_array >
1324 1325 1326 |
# File 'lib/modl/parser/parsed.rb', line 1324 def abstractArrayItems @abstractArrayItems end |
Instance Method Details
#enterModl_array(ctx) ⇒ Object
1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 |
# 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 ⇒ Object
1342 1343 1344 1345 1346 1347 1348 1349 1350 |
# 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) ⇒ Object
1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 |
# 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 |