search_syntax 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,70 @@
1
+ grammar SearchSyntaxGrammar
2
+ rule root
3
+ space* expressions space* {
4
+ def value
5
+ elements[1].value
6
+ end
7
+ }
8
+ end
9
+
10
+ rule expressions
11
+ ((quoted_value / param / bare_value) space?)* {
12
+ def value
13
+ elements.map{|e| e.elements[0].value.merge({
14
+ raw: e.elements[0].text_value,
15
+ start: e.elements[0].interval.begin,
16
+ finish: e.elements[0].interval.end
17
+ }) }
18
+ end
19
+ }
20
+ end
21
+
22
+ rule space
23
+ [ \t]+
24
+ end
25
+
26
+ rule quoted_value
27
+ ('"' ('\"' / !'"' .)* '"' / '\'' ('\\\'' / !'\'' .)* '\'') {
28
+ def value
29
+ quote = elements[0].text_value
30
+ {
31
+ type: :quoted,
32
+ value: elements[1].text_value.gsub("\\#{quote}", quote)
33
+ }
34
+ end
35
+ }
36
+ end
37
+
38
+ rule bare_value
39
+ (!space .)+ '' {
40
+ def value
41
+ {
42
+ type: :bare,
43
+ value: elements[0].text_value
44
+ }
45
+ end
46
+ }
47
+ end
48
+
49
+ rule predicate
50
+ ">=" / "<=" / "=>" / "=<" / "!=" / ">" / "<"
51
+ end
52
+
53
+ rule param
54
+ (!(space / ":") .)+ ":" predicate? (quoted_value / bare_value) {
55
+ def value
56
+ result = {
57
+ type: :param,
58
+ name: elements[0].text_value,
59
+ value: elements[3].value[:value]
60
+ }
61
+ predicate = elements[2].text_value
62
+ if predicate != ""
63
+ result[:predicate] = predicate.to_sym
64
+ end
65
+ result
66
+ end
67
+ }
68
+ end
69
+
70
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SearchSyntax
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "search_syntax/version"
4
+ require_relative "search_syntax/errors"
5
+ require_relative "search_syntax/parser"
6
+ require_relative "search_syntax/ransack"
7
+
8
+ module SearchSyntax
9
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/search_syntax/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "search_syntax"
7
+ spec.version = SearchSyntax::VERSION
8
+ spec.authors = ["stereobooster"]
9
+ spec.email = ["stereobooster@gmail.com"]
10
+
11
+ spec.summary = "Advanced search string"
12
+ spec.description = "Advanced search string"
13
+ spec.homepage = "https://github.com/stereobooster/search_syntax"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org/"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/stereobooster/search_syntax"
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(__dir__) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
27
+ end
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ # Uncomment to register a new dependency of your gem
34
+ # spec.add_dependency "example-gem", "~> 1.0"
35
+
36
+ # For more information and examples about making a new gem, check out our
37
+ # guide at: https://bundler.io/guides/creating_gem.html
38
+ end
@@ -0,0 +1,4 @@
1
+ module SearchSyntax
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: search_syntax
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - stereobooster
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-10-18 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Advanced search string
14
+ email:
15
+ - stereobooster@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".ruby-version"
21
+ - ".standard.yml"
22
+ - CODE_OF_CONDUCT.md
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - lib/search_syntax.rb
29
+ - lib/search_syntax/errors.rb
30
+ - lib/search_syntax/parser.rb
31
+ - lib/search_syntax/ransack.rb
32
+ - lib/search_syntax/ransack_transformer.rb
33
+ - lib/search_syntax/search_syntax_grammar.rb
34
+ - lib/search_syntax/search_syntax_grammar.tt
35
+ - lib/search_syntax/version.rb
36
+ - search_syntax.gemspec
37
+ - sig/search_syntax.rbs
38
+ homepage: https://github.com/stereobooster/search_syntax
39
+ licenses:
40
+ - MIT
41
+ metadata:
42
+ allowed_push_host: https://rubygems.org/
43
+ homepage_uri: https://github.com/stereobooster/search_syntax
44
+ source_code_uri: https://github.com/stereobooster/search_syntax
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 2.6.0
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubygems_version: 3.3.7
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: Advanced search string
64
+ test_files: []