lib/demiurge/name_generator.rb
# Add rules to this generator from the given string
#
# @attr [String] rules The block of rule content in DemiRule format.
# @return [void]
# @since 0.4.0
Add rules to this generator from the given string
Add rules to this generator from the given string
def load_rules_from_andor_string(rules)
      defn_parser = AndorDefnParser.new
      rules.split("\n").each_with_index do |line, line_no|
        content, _ = line.split("#", 2)
        next if content == nil
        next if content.strip == ""
        name, defn = content.split(":", 2)
        unless name && defn
          raise ::Demiurge::Errors::DemiRuleFormatError.new("Badly-formed name definition line in DemiRule format on line #{line_no.inspect}", "name" => name, "defn" => defn, "line_no" => line_no)
        end
        unless name =~ NAME_REGEXP
          raise ::Demiurge::Errors::DemiRuleFormatError.new("Illegal name #{name.inspect} in DemiRule format on line #{line_no.inspect}", "name" => name, "line_no" => line_no)
        end
        if @rules[name]
          raise ::Demiurge::Errors::DemiRuleFormatError.new("Duplicate name #{name.inspect} in DemiRule format on line #{line_no.inspect}", "name" => name, "line_no" => line_no)
        end
        begin
          symbols = defn_parser.parse(defn)
        rescue Parslet::ParseFailed => error
          raise ::Demiurge::Errors::DemiRuleFormatError.new("Can't parse Andor name definition for #{name.inspect}", "definition" => defn, "name" => name, "line_no" => line_no, "error" => error.parse_failure_cause.ascii_tree)
        end
        @rules[name] = symbols  
      end
      nil
    end
def load_rules_from_andor_string ( rules ) defn_parser = AndorDefnParser . new rules . split ( "\n" ) . each_with_index do | line , line_no | content , _ = line . split ( "#" , 2 ) next if content == nil next if content . strip == "" name , defn = content . split ( ":" , 2 ) unless name && defn raise :: Demiurge :: Errors :: DemiRuleFormatError . new ( "Badly-formed name definition line in DemiRule format on line #{line_no.inspect}" , "name" => name , "defn" => defn , "line_no" => line_no ) end unless name =~ NAME_REGEXP raise :: Demiurge :: Errors :: DemiRuleFormatError . new ( "Illegal name #{name.inspect} in DemiRule format on line #{line_no.inspect}" , "name" => name , "line_no" => line_no ) end if @rules [ name ] raise :: Demiurge :: Errors :: DemiRuleFormatError . new ( "Duplicate name #{name.inspect} in DemiRule format on line #{line_no.inspect}" , "name" => name , "line_no" => line_no ) end begin symbols = defn_parser . parse ( defn ) rescue Parslet :: ParseFailed => error raise :: Demiurge :: Errors :: DemiRuleFormatError . new ( "Can't parse Andor name definition for #{name.inspect}" , "definition" => defn , "name" => name , "line_no" => line_no , "error" => error . parse_failure_cause . ascii_tree ) end @rules [ name ] = symbols end nil end
Add rules to this generator from the given string
Add rules to this generator from the given string
# Need to transform to proper ast
None
void
rules
attr
rules The block of rule content in DemiRule format.
rules The block of rule content in DemiRule format .
since
None