Method: Unicoder::Builder::Scripts#parse!

Defined in:
lib/unicoder/builders/scripts.rb

#parse!Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/unicoder/builders/scripts.rb', line 41

def parse!
  parse_file :property_value_aliases, :line, regex: /^sc ; (?<short>\S+?)\s*; (?<long>\S+?)(?:\s*; (?<short2>\S+))?$/ do |line|
    @index[:SCRIPT_NAMES] << line["long"]
    script_number = @reverse_script_names.size
    @reverse_script_names[line["long"]] = script_number

    @index[:SCRIPT_ALIASES][line["short" ]] = script_number
    @index[:SCRIPT_ALIASES][line["short2"]] = script_number if line["short2"]
    @reverse_script_extension_names[line["short"]] = script_number
  end

  parse_file :scripts, :line, regex: /^(?<from>\S+?)(\.\.(?<to>\S+))?\s+; (?<script>\S+) #.*$/ do |line|
    if line["to"]
      (line["from"].to_i(16)..line["to"].to_i(16)).each{ |codepoint|
        assign_codepoint codepoint, @reverse_script_names[line["script"]], @index[:SCRIPTS]
      }
    else
      assign_codepoint line["from"].to_i(16), @reverse_script_names[line["script"]], @index[:SCRIPTS]
    end
  end

  4.times{ compress! @index[:SCRIPTS] }

  parse_file :script_extensions, :line, regex: /^(?<from>\S+?)(\.\.(?<to>\S+))?\s+; (?<scripts>.+?) #.*$/ do |line|
    if line["to"]
      (line["from"].to_i(16)..line["to"].to_i(16)).each{ |codepoint|
        assign_classic :SCRIPT_EXTENSIONS, codepoint, lookup_extension_names(line["scripts"])
      }
    else
      assign_classic :SCRIPT_EXTENSIONS, line["from"].to_i(16), lookup_extension_names(line["scripts"])
    end
  end
end