class MODL::Parser::Parsed
This class represents a MODL
parse tree for a given MODL
object. It tries to process the parse tree as it is generated as much as possible to save revisiting nodes unnecessarily.
Many of the method names are generated by ANTLR4 so are not ruby style.
Attributes
global[RW]
structures[RW]
Public Class Methods
additional_string_processing(text)
click to toggle source
# File lib/modl/parser/parsed.rb, line 73 def self.additional_string_processing(text) # Special case for a possibly empty graved string `` unless text.nil? match_data = /^`([^`]*)`$/.match text return match_data[1] if match_data&.length&.positive? end text end
handle_empty_array_item()
click to toggle source
# File lib/modl/parser/parsed.rb, line 1307 def self.handle_empty_array_item # 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 value # # TODO : Is there a way to know the type to create or is nil always acceptable? array_item = ParsedArrayItem.new @global array_item.arrayValueItem = ParsedArrayValueItem.new @global array_item.arrayValueItem.primitive = ParsedPrimitive.new @global array_item.arrayValueItem.primitive.nilVal = ParsedNull.instance array_item end
new(global = nil)
click to toggle source
# File lib/modl/parser/parsed.rb, line 52 def initialize(global = nil) @global = global @structures = [] end
Public Instance Methods
enterModl(ctx)
click to toggle source
# File lib/modl/parser/parsed.rb, line 57 def enterModl(ctx) @global = GlobalParseContext.new if @global.nil? ctx_modl_structure = ctx.modl_structure ctx_modl_structure.each do |str| structure = ParsedStructure.new @global str.enter_rule(structure) @structures << structure end @structures = @global.structures + @structures @global end
extract_hash()
click to toggle source
Convert the parse tree to a simpler structure suitable for JSON.generate.
# File lib/modl/parser/parsed.rb, line 1449 def extract_hash result = [] if @structures.length.positive? @structures.each do |s| value = s.extract_hash result << value unless value.nil? end else result = {} end case result.length when 0 return nil when 1 return result[0] end result end