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.7.0 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.6.16 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.6.15 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.6.14 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.6.13 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.6.12 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.6.11 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.6.10 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.6.9 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.6.8 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.6.7 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.6.6 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.6.5 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.6.4 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.6.3 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.6.1 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.5.16 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.5.15 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.5.14 lib/appfuel/storage/repository/search_parser.rb
appfuel-0.5.13 lib/appfuel/storage/repository/search_parser.rb