Sha256: 373faf35202348bc33d6b122497e1687d49af60c0f456e4006ed718574e09a53
Contents?: true
Size: 1.71 KB
Versions: 8
Compression:
Stored size: 1.71 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
8 entries across 8 versions & 1 rubygems