Sha256: 74cbbf89824337524ef36d7eaf5f15fe8b68cdc2c60aa7127f667e9b41c5eed8

Contents?: true

Size: 1.56 KB

Versions: 16

Compression:

Stored size: 1.56 KB

Contents

#
#       ActiveFacts CQL Parser.
#       Parse rules relating to Expressions
#
# Copyright (c) 2009 Clifford Heath. Read the LICENSE file.
#
module ActiveFacts
  module CQL
    grammar Expressions
      rule expression
        sum
      end

      rule sum
        t0:product s tail:( op:add_op s t1:product s )*
        {
	  def ast
	    if tail.elements.empty?
	      t0.ast
	    else
	      Compiler::Sum.new(t0.ast, *tail.elements.map{|e| e.op.text_value == '-' ? Compiler::Negate.new(e.t1.ast) : e.t1.ast})
	    end
	  end
        }
      end

      rule add_op
        '+' / '-'
      end

      rule product
        f0:factor s tail:( op:mul_op s f1:factor s )*
        {
	  def ast
	    if tail.elements.empty?
	      f0.ast
	    else
	      Compiler::Product.new(f0.ast, *tail.elements.map{|e| e.op.text_value != '*' ? Compiler::Reciprocal.new(e.op.text_value, e.f1.ast) : e.f1.ast})
	    end
	  end
        }
      end

      rule factor
        literal u:unit? s
            {
	      def ast
		Compiler::Literal.new(literal.value, u.empty? ? nil : u.text_value)
	      end
            }
        / derived_variable
        / !context_note '(' s sum s ')' s                   { def ast; sum.ast; end }
      end

      rule derived_variable
        derived:term s role_id:(role_name / subscript )?
        {
	  def ast quantifier = nil, value_constraint = nil, literal = nil, nested_clauses = nil
	    role_name = role_id.empty? ? nil : role_id.value
	    derived.ast(quantifier, nil, role_name, value_constraint, literal, nested_clauses)
	  end
        }
      end

    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
activefacts-cql-1.8.1 lib/activefacts/cql/parser/Expressions.treetop
activefacts-cql-1.8.0 lib/activefacts/cql/parser/Expressions.treetop
activefacts-cql-1.7.1 lib/activefacts/cql/parser/Expressions.treetop
activefacts-1.6.0 lib/activefacts/cql/Expressions.treetop
activefacts-1.5.3 lib/activefacts/cql/Expressions.treetop
activefacts-1.5.2 lib/activefacts/cql/Expressions.treetop
activefacts-1.5.1 lib/activefacts/cql/Expressions.treetop
activefacts-1.5.0 lib/activefacts/cql/Expressions.treetop
activefacts-1.3.0 lib/activefacts/cql/Expressions.treetop
activefacts-1.2.1 lib/activefacts/cql/Expressions.treetop
activefacts-1.2.0 lib/activefacts/cql/Expressions.treetop
activefacts-1.1.0 lib/activefacts/cql/Expressions.treetop
activefacts-1.0.2 lib/activefacts/cql/Expressions.treetop
activefacts-1.0.1 lib/activefacts/cql/Expressions.treetop
activefacts-1.0.0 lib/activefacts/cql/Expressions.treetop
activefacts-0.8.18 lib/activefacts/cql/Expressions.treetop