Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/hash.rb

Instance Method Summary collapse

Instance Method Details

#to_parsletObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/hash.rb', line 2

def to_parslet
  case fetch("atom")
    when "entity"
      Parslet::Atoms::Entity.new(fetch("name")).tap do |atom|
        atom.instance_variable_set("@parslet", fetch("parslet").to_parslet)
      end
    when "named"
      Parslet::Atoms::Named.new(fetch("parslet").to_parslet, fetch("name"))
    when "repetition"
      Parslet::Atoms::Repetition.new(fetch("parslet").to_parslet, fetch("min"), fetch("max"))
    when "sequence"
      Parslet::Atoms::Sequence.new(*fetch("parslets").map(&:to_parslet))
    when "re"
      Parslet::Atoms::Re.new(fetch("match")).tap do |atom|
        atom.instance_variable_set("@re", fetch("re"))
      end
    when "str"
      Parslet::Atoms::Str.new(fetch("str"))
  end
end