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