jievro-ast 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/jievro/ast/node.rb +36 -61
- data/lib/jievro/ast/version.rb +1 -1
- metadata +12 -12
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: ebd32482a1dcf426a1e265165b5378b6e7da8bbb
         | 
| 4 | 
            +
              data.tar.gz: 468191cc766d63b829e675fc2792805aca7b8942
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 8431d195cc533931b204b6ff0be6e6eca9f6fa5935ddfdd969497d683719ae13608fe77f3be3071e4ee5838526eb68ccc3b4c282b67cf033594b6d61fc4c50a6
         | 
| 7 | 
            +
              data.tar.gz: 84d519c7f63362c3728698d70672b5383072316c1b4ad08d8396a4a1887e0eaf0f82b9a43c570037a8e7e1b813c7f9e8d13f5a8406d9c855fde2d01c6b4bfaaa
         | 
    
        data/lib/jievro/ast/node.rb
    CHANGED
    
    | @@ -1,58 +1,42 @@ | |
| 1 1 | 
             
            module Jievro
         | 
| 2 2 | 
             
              module Ast
         | 
| 3 3 | 
             
                class Node
         | 
| 4 | 
            +
                  attr_reader :parent, :type, :key, :value
         | 
| 4 5 |  | 
| 5 6 | 
             
                  def initialize(initializer, parent = nil, key = nil)
         | 
| 6 | 
            -
             | 
| 7 7 | 
             
                    @parent = parent
         | 
| 8 8 | 
             
                    @key = key
         | 
| 9 9 |  | 
| 10 | 
            -
                     | 
| 11 | 
            -
             | 
| 12 | 
            -
                       | 
| 13 | 
            -
                     | 
| 14 | 
            -
             | 
| 15 | 
            -
                     | 
| 16 | 
            -
                       | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
                    if valid.include? initializer.class
         | 
| 23 | 
            -
                      @value = initializer
         | 
| 24 | 
            -
                      @type = '__literal'
         | 
| 25 | 
            -
                      return
         | 
| 10 | 
            +
                    case initializer
         | 
| 11 | 
            +
                    when FalseClass, TrueClass, String, Fixnum, Float
         | 
| 12 | 
            +
                      initialize_as_literal(initializer)
         | 
| 13 | 
            +
                    when Array
         | 
| 14 | 
            +
                      initialize_as_array(initializer)
         | 
| 15 | 
            +
                    when Hash
         | 
| 16 | 
            +
                      initialize_as_hash(initializer)
         | 
| 17 | 
            +
                    else
         | 
| 18 | 
            +
                      fail Exception, "The initializer must be
         | 
| 19 | 
            +
                                       FalseClass, TrueClass, String,
         | 
| 20 | 
            +
                                       Fixnum, Float, Array or Hash.
         | 
| 21 | 
            +
                                       #{initializer.class} given"
         | 
| 26 22 | 
             
                    end
         | 
| 27 | 
            -
             | 
| 28 | 
            -
                    raise Exception, "The initializer must be #{valid.join(', ')}, Array or Hash. #{initializer.class} given"
         | 
| 29 23 | 
             
                  end
         | 
| 30 24 |  | 
| 31 | 
            -
                  def [] | 
| 32 | 
            -
                     | 
| 33 | 
            -
                       | 
| 34 | 
            -
                    end
         | 
| 25 | 
            +
                  def [](key)
         | 
| 26 | 
            +
                    fail Exception, "Key '#{key}' is invalid" \
         | 
| 27 | 
            +
                      unless @value.key?(key)
         | 
| 35 28 |  | 
| 36 29 | 
             
                    @value[key]
         | 
| 37 30 | 
             
                  end
         | 
| 38 31 |  | 
| 39 | 
            -
                  def parent
         | 
| 40 | 
            -
                    @parent
         | 
| 41 | 
            -
                  end
         | 
| 42 | 
            -
             | 
| 43 | 
            -
                  def type
         | 
| 44 | 
            -
                    @type
         | 
| 45 | 
            -
                  end
         | 
| 46 | 
            -
             | 
| 47 | 
            -
                  def key
         | 
| 48 | 
            -
                    @key
         | 
| 49 | 
            -
                  end
         | 
| 50 | 
            -
             | 
| 51 32 | 
             
                  def keys
         | 
| 52 33 | 
             
                    @value.keys
         | 
| 53 34 | 
             
                  end
         | 
| 54 35 |  | 
| 55 36 | 
             
                  def value
         | 
| 37 | 
            +
                    fail Exception, 'Cannot get value from a non literal node' \
         | 
| 38 | 
            +
                      unless @type == '__literal'
         | 
| 39 | 
            +
             | 
| 56 40 | 
             
                    @value
         | 
| 57 41 | 
             
                  end
         | 
| 58 42 |  | 
| @@ -62,44 +46,35 @@ module Jievro | |
| 62 46 |  | 
| 63 47 | 
             
                  private
         | 
| 64 48 |  | 
| 65 | 
            -
                  def  | 
| 49 | 
            +
                  def initialize_as_literal(initializer)
         | 
| 50 | 
            +
                    @value = initializer
         | 
| 51 | 
            +
                    @type = '__literal'
         | 
| 52 | 
            +
                  end
         | 
| 66 53 |  | 
| 67 | 
            -
             | 
| 68 | 
            -
             | 
| 69 | 
            -
                     | 
| 54 | 
            +
                  def initialize_as_array(initializer)
         | 
| 55 | 
            +
                    @value = {}
         | 
| 56 | 
            +
                    @type = '__collection'
         | 
| 70 57 |  | 
| 71 | 
            -
                     | 
| 72 | 
            -
                       | 
| 58 | 
            +
                    initializer.each_with_index do |e, i|
         | 
| 59 | 
            +
                      @value[i] = Node.new(e, self, i)
         | 
| 73 60 | 
             
                    end
         | 
| 61 | 
            +
                  end
         | 
| 74 62 |  | 
| 75 | 
            -
             | 
| 76 | 
            -
                     | 
| 63 | 
            +
                  def initialize_as_hash(initializer)
         | 
| 64 | 
            +
                    fail Exception, 'Initializer is missing __type value' \
         | 
| 65 | 
            +
                      unless initializer.key?(:__type)
         | 
| 77 66 |  | 
| 78 | 
            -
                     | 
| 67 | 
            +
                    @value = {}
         | 
| 68 | 
            +
                    @type = initializer[:__type]
         | 
| 79 69 |  | 
| 70 | 
            +
                    initializer.keys.each do |k|
         | 
| 80 71 | 
             
                      key = k.to_s
         | 
| 81 72 |  | 
| 82 73 | 
             
                      # skip all the meta info
         | 
| 83 | 
            -
                      if key.to_s.start_with?('__')
         | 
| 84 | 
            -
                        next
         | 
| 85 | 
            -
                      end
         | 
| 74 | 
            +
                      next if key.to_s.start_with?('__')
         | 
| 86 75 |  | 
| 87 76 | 
             
                      @value[k] = Node.new(initializer[k], self, key)
         | 
| 88 | 
            -
                    }
         | 
| 89 | 
            -
                  end
         | 
| 90 | 
            -
             | 
| 91 | 
            -
                  def initialize_using_array(initializer)
         | 
| 92 | 
            -
             | 
| 93 | 
            -
                    unless initializer.is_a?(Array)
         | 
| 94 | 
            -
                      raise Exception, 'The initializer is not an Array'
         | 
| 95 77 | 
             
                    end
         | 
| 96 | 
            -
             | 
| 97 | 
            -
                    @value = Hash.new
         | 
| 98 | 
            -
                    @type = '__collection'
         | 
| 99 | 
            -
             | 
| 100 | 
            -
                    initializer.each_with_index { |e, i|
         | 
| 101 | 
            -
                      @value[i] = Node.new(e, self, i)
         | 
| 102 | 
            -
                    }
         | 
| 103 78 | 
             
                  end
         | 
| 104 79 | 
             
                end
         | 
| 105 80 | 
             
              end
         | 
    
        data/lib/jievro/ast/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: jievro-ast
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.2.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Stefano Azzalini
         | 
| @@ -14,42 +14,42 @@ dependencies: | |
| 14 14 | 
             
              name: bundler
         | 
| 15 15 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 16 | 
             
                requirements:
         | 
| 17 | 
            -
                - -  | 
| 17 | 
            +
                - - ~>
         | 
| 18 18 | 
             
                  - !ruby/object:Gem::Version
         | 
| 19 19 | 
             
                    version: '1.9'
         | 
| 20 20 | 
             
              type: :development
         | 
| 21 21 | 
             
              prerelease: false
         | 
| 22 22 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 23 | 
             
                requirements:
         | 
| 24 | 
            -
                - -  | 
| 24 | 
            +
                - - ~>
         | 
| 25 25 | 
             
                  - !ruby/object:Gem::Version
         | 
| 26 26 | 
             
                    version: '1.9'
         | 
| 27 27 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 28 28 | 
             
              name: rake
         | 
| 29 29 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 30 | 
             
                requirements:
         | 
| 31 | 
            -
                - -  | 
| 31 | 
            +
                - - ~>
         | 
| 32 32 | 
             
                  - !ruby/object:Gem::Version
         | 
| 33 33 | 
             
                    version: '10.0'
         | 
| 34 34 | 
             
              type: :development
         | 
| 35 35 | 
             
              prerelease: false
         | 
| 36 36 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 37 | 
             
                requirements:
         | 
| 38 | 
            -
                - -  | 
| 38 | 
            +
                - - ~>
         | 
| 39 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| 40 40 | 
             
                    version: '10.0'
         | 
| 41 41 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 42 42 | 
             
              name: rspec
         | 
| 43 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 44 | 
             
                requirements:
         | 
| 45 | 
            -
                - -  | 
| 45 | 
            +
                - - ~>
         | 
| 46 46 | 
             
                  - !ruby/object:Gem::Version
         | 
| 47 47 | 
             
                    version: '3.2'
         | 
| 48 48 | 
             
              type: :development
         | 
| 49 49 | 
             
              prerelease: false
         | 
| 50 50 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 51 | 
             
                requirements:
         | 
| 52 | 
            -
                - -  | 
| 52 | 
            +
                - - ~>
         | 
| 53 53 | 
             
                  - !ruby/object:Gem::Version
         | 
| 54 54 | 
             
                    version: '3.2'
         | 
| 55 55 | 
             
            description: 
         | 
| @@ -58,8 +58,8 @@ executables: [] | |
| 58 58 | 
             
            extensions: []
         | 
| 59 59 | 
             
            extra_rdoc_files: []
         | 
| 60 60 | 
             
            files:
         | 
| 61 | 
            -
            -  | 
| 62 | 
            -
            -  | 
| 61 | 
            +
            - .gitignore
         | 
| 62 | 
            +
            - .travis.yml
         | 
| 63 63 | 
             
            - Gemfile
         | 
| 64 64 | 
             
            - Gemfile.lock
         | 
| 65 65 | 
             
            - LICENSE.txt
         | 
| @@ -79,17 +79,17 @@ require_paths: | |
| 79 79 | 
             
            - lib
         | 
| 80 80 | 
             
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 81 81 | 
             
              requirements:
         | 
| 82 | 
            -
              - -  | 
| 82 | 
            +
              - - ~>
         | 
| 83 83 | 
             
                - !ruby/object:Gem::Version
         | 
| 84 84 | 
             
                  version: '2.0'
         | 
| 85 85 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 86 86 | 
             
              requirements:
         | 
| 87 | 
            -
              - -  | 
| 87 | 
            +
              - - '>='
         | 
| 88 88 | 
             
                - !ruby/object:Gem::Version
         | 
| 89 89 | 
             
                  version: '0'
         | 
| 90 90 | 
             
            requirements: []
         | 
| 91 91 | 
             
            rubyforge_project: 
         | 
| 92 | 
            -
            rubygems_version: 2. | 
| 92 | 
            +
            rubygems_version: 2.0.14
         | 
| 93 93 | 
             
            signing_key: 
         | 
| 94 94 | 
             
            specification_version: 4
         | 
| 95 95 | 
             
            summary: AST model used internally by jievro-parser
         |