Sha256: ac582c23c5d427e47fecce740a63095922d84289ce0a6f2b9e89d0e2d1b588a9

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 KB

Contents

module ActiveFacts
  module CQL
    grammar DataTypes
      rule data_type
        s name:id
        ( s '=' s / defined_as )
        base:id s
        '(' s tpl:type_parameter_list? ')' s
        u0:(!restricted u1:unit s)?
        r:restriction?
        s ';' s
        {
          def defined_type
            [
              :data_type,
              base.text_value,
              tpl.empty? ? [] : tpl.value,
              !u0.empty? ? u0.u1.text_value : nil,
              !r.empty? ? r.ranges : [],
            ]
          end

          def value
            [ name.text_value,
              defined_type
            ]
          end
        }
      end

      rule type_parameter_list
        head:number s tail:( ',' s number s )*
        {
          def value
            [head.value] + tail.elements.map{|i| i.number.value}
          end
        }
      end

      rule unit
        unit_name:id ('^' '-'? [0-9])?
      end

      rule restriction
        restricted s to s range_list s unit?
        {
          def ranges
            range_list.ranges
          end
        }
      end

      rule range_list
        '{' s
          head:range s tail:( ',' s range )*
        '}' s
        {
          def ranges
            [head.value] + tail.elements.map{|e| e.range.value }
          end
        }
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activefacts-0.6.0 lib/activefacts/cql/DataTypes.treetop
activefacts-0.7.0 lib/activefacts/cql/DataTypes.treetop