Sha256: 5b48b0998b54b18e81d3baa34bfed09038d77256bc788cb04986cf8eb5434d9d

Contents?: true

Size: 1.46 KB

Versions: 2

Compression:

Stored size: 1.46 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 / 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.7.1 lib/activefacts/cql/DataTypes.treetop
activefacts-0.7.2 lib/activefacts/cql/DataTypes.treetop