Sha256: 74a869721f90c9a9491b9179a58e1165eef0369ac9682d1aa4b4a7355aa942d1

Contents?: true

Size: 1.24 KB

Versions: 50

Compression:

Stored size: 1.24 KB

Contents

module Appfuel
  module Repository
    class SearchParser < ExprParser
      rule(:filter_identifier) { stri('filter') }
      rule(:order_identifier)  { stri('order') }
      rule(:limit_identifier)  { stri('limit') }

      rule(:order_dir) do
        (stri('asc') | stri('desc')).as(:order_dir)
      end

      rule(:domain_name) do
        attr_label.as(:feature) >> str('.') >> attr_label.as(:basename)
      end

      rule(:limit_expr) do
        (
          limit_identifier >> space >> space? >> integer.as(:value)
        ).as(:limit)
      end

      rule(:order_expr) do
        (
          (domain_attr >> space >> order_dir) | domain_attr
        ).as(:order_expr)
      end

      # order id
      # order id asc
      # order foo.id asc
      # order foo.id, code desc, foo.bar.id asc
      rule(:order_by) do
        (
          order_identifier >> space >> space? >>
          (order_expr >> (comma >> order_expr).repeat).maybe
        ).as(:order)
      end

      rule(:search) do
        (
          domain_name.as(:domain) >> space >> space? >>
          filter_identifier >> space >> space? >>
          or_operation.as(:filters) >> order_by.maybe >> space? >> limit_expr.maybe
        ).as(:search)
      end

      root(:search)
    end
  end
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
appfuel-0.5.12 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.5.11 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.5.10 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.5.9 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.5.8 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.5.7 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.5.6 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.5.5 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.5.4 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.5.3 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.5.2 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.5.1 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.5.0 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.4.5 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.4.4 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.4.3 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.4.2 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.4.1 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.4.0 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.3.4 lib/appfuel/storage/repository/search_parser.rb