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.
1269 1270 1271 1272 |
# File 'lib/modl/parser/parsed.rb', line 1269 def initialize(global) @global = global @abstractArrayItems = [] end |
Instance Attribute Details
#abstractArrayItems ⇒ Object
We now have a list of < array_item | nb_array >
1267 1268 1269 |
# File 'lib/modl/parser/parsed.rb', line 1267 def abstractArrayItems @abstractArrayItems end |
Instance Method Details
#enterModl_array(ctx) ⇒ Object
1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 |
# File 'lib/modl/parser/parsed.rb', line 1295 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
1285 1286 1287 1288 1289 1290 1291 1292 1293 |
# File 'lib/modl/parser/parsed.rb', line 1285 def extract_hash result = [] abstractArrayItems.each do |i| result << i.extract_hash end result end |
#find_property(key) ⇒ Object
1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 |
# File 'lib/modl/parser/parsed.rb', line 1274 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 |