Sha256: f6aecfbb12fc3a3f4cf0ad12e8ffea3ffdd411d0908953d2f3bdcd013c27c1be

Contents?: true

Size: 1.71 KB

Versions: 1

Compression:

Stored size: 1.71 KB

Contents

#
#       ActiveFacts CQL Parser.
#       Parse rules relating to ValueType definitions.
#
# Copyright (c) 2009 Clifford Heath. Read the LICENSE file.
#
module ActiveFacts
  module CQL
    grammar DataTypes
      rule data_type
        s name:id
        ( s '=' s / written_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 unit_definition
	numerator:number denominator:(s '/' s number)?
	baseunits:(unit+ (s '/' s unit+)?) s
	offset:(('+' / '-') s number)
	'makes' s ('approximately' s)?
	singular:id plural:(s '/' s id)?
	(s '[' s 'ephemeral' s ']')?
      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

1 entries across 1 versions & 1 rubygems

Version Path
activefacts-0.7.3 lib/activefacts/cql/DataTypes.treetop