mustermann 0.1.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +472 -321
  3. data/bench/capturing.rb +4 -4
  4. data/bench/regexp.rb +21 -0
  5. data/lib/mustermann/ast/boundaries.rb +44 -0
  6. data/lib/mustermann/ast/compiler.rb +13 -7
  7. data/lib/mustermann/ast/expander.rb +45 -14
  8. data/lib/mustermann/ast/node.rb +69 -6
  9. data/lib/mustermann/ast/param_scanner.rb +20 -0
  10. data/lib/mustermann/ast/parser.rb +140 -22
  11. data/lib/mustermann/ast/pattern.rb +68 -21
  12. data/lib/mustermann/ast/template_generator.rb +28 -0
  13. data/lib/mustermann/ast/transformer.rb +32 -24
  14. data/lib/mustermann/ast/translator.rb +24 -10
  15. data/lib/mustermann/ast/validation.rb +10 -6
  16. data/lib/mustermann/caster.rb +116 -0
  17. data/lib/mustermann/composite.rb +101 -0
  18. data/lib/mustermann/expander.rb +204 -0
  19. data/lib/mustermann/identity.rb +56 -0
  20. data/lib/mustermann/mapper.rb +94 -0
  21. data/lib/mustermann/pattern.rb +193 -13
  22. data/lib/mustermann/pattern_cache.rb +49 -0
  23. data/lib/mustermann/regexp.rb +1 -0
  24. data/lib/mustermann/regexp_based.rb +19 -2
  25. data/lib/mustermann/regular.rb +29 -0
  26. data/lib/mustermann/router/rack.rb +47 -0
  27. data/lib/mustermann/router/simple.rb +142 -0
  28. data/lib/mustermann/router.rb +9 -0
  29. data/lib/mustermann/simple_match.rb +5 -0
  30. data/lib/mustermann/sinatra.rb +22 -5
  31. data/lib/mustermann/to_pattern.rb +50 -0
  32. data/lib/mustermann/version.rb +1 -1
  33. data/lib/mustermann.rb +102 -19
  34. data/mustermann.gemspec +2 -12
  35. data/spec/ast_spec.rb +14 -0
  36. data/spec/composite_spec.rb +147 -0
  37. data/spec/expander_spec.rb +120 -0
  38. data/spec/identity_spec.rb +44 -0
  39. data/spec/mapper_spec.rb +83 -0
  40. data/spec/mustermann_spec.rb +50 -11
  41. data/spec/pattern_spec.rb +34 -7
  42. data/spec/regexp_based_spec.rb +1 -1
  43. data/spec/regular_spec.rb +61 -0
  44. data/spec/router/rack_spec.rb +39 -0
  45. data/spec/router/simple_spec.rb +32 -0
  46. data/spec/simple_match_spec.rb +1 -1
  47. data/spec/sinatra_spec.rb +197 -9
  48. data/spec/to_pattern_spec.rb +69 -0
  49. metadata +44 -146
  50. data/.gitignore +0 -18
  51. data/.rspec +0 -2
  52. data/.travis.yml +0 -7
  53. data/.yardopts +0 -1
  54. data/Gemfile +0 -2
  55. data/LICENSE +0 -22
  56. data/Rakefile +0 -6
  57. data/internals.md +0 -64
  58. data/lib/mustermann/ast/tree_renderer.rb +0 -29
  59. data/lib/mustermann/rails.rb +0 -17
  60. data/lib/mustermann/shell.rb +0 -22
  61. data/lib/mustermann/simple.rb +0 -35
  62. data/lib/mustermann/template.rb +0 -47
  63. data/spec/rails_spec.rb +0 -521
  64. data/spec/shell_spec.rb +0 -108
  65. data/spec/simple_spec.rb +0 -236
  66. data/spec/support/coverage.rb +0 -18
  67. data/spec/support/env.rb +0 -6
  68. data/spec/support/expand_matcher.rb +0 -27
  69. data/spec/support/match_matcher.rb +0 -39
  70. data/spec/support/pattern.rb +0 -28
  71. data/spec/support.rb +0 -5
  72. data/spec/template_spec.rb +0 -814
metadata CHANGED
@@ -1,187 +1,87 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mustermann
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin Haase
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-12 00:00:00.000000000 Z
11
+ date: 2014-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rspec
14
+ name: tool
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
19
+ version: '0.2'
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: sinatra
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ~>
32
- - !ruby/object:Gem::Version
33
- version: '1.4'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ~>
39
- - !ruby/object:Gem::Version
40
- version: '1.4'
41
- - !ruby/object:Gem::Dependency
42
- name: rack-test
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - '>='
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: rake
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - '>='
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: yard
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - '>='
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - '>='
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: redcarpet
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - '>='
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - '>='
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: simplecov
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - '>='
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - '>='
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: coveralls
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - '>='
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - '>='
123
- - !ruby/object:Gem::Version
124
- version: '0'
26
+ version: '0.2'
125
27
  description: library implementing patterns that behave like regular expressions
126
28
  email: konstantin.mailinglists@googlemail.com
127
29
  executables: []
128
30
  extensions: []
129
- extra_rdoc_files:
130
- - README.md
131
- - internals.md
31
+ extra_rdoc_files: []
132
32
  files:
133
- - .gitignore
134
- - .rspec
135
- - .travis.yml
136
- - .yardopts
137
- - Gemfile
138
- - LICENSE
139
33
  - README.md
140
- - Rakefile
141
34
  - bench/capturing.rb
35
+ - bench/regexp.rb
142
36
  - bench/simple_vs_sinatra.rb
143
37
  - bench/template_vs_addressable.rb
144
- - internals.md
145
38
  - lib/mustermann.rb
39
+ - lib/mustermann/ast/boundaries.rb
146
40
  - lib/mustermann/ast/compiler.rb
147
41
  - lib/mustermann/ast/expander.rb
148
42
  - lib/mustermann/ast/node.rb
43
+ - lib/mustermann/ast/param_scanner.rb
149
44
  - lib/mustermann/ast/parser.rb
150
45
  - lib/mustermann/ast/pattern.rb
46
+ - lib/mustermann/ast/template_generator.rb
151
47
  - lib/mustermann/ast/transformer.rb
152
48
  - lib/mustermann/ast/translator.rb
153
- - lib/mustermann/ast/tree_renderer.rb
154
49
  - lib/mustermann/ast/validation.rb
50
+ - lib/mustermann/caster.rb
51
+ - lib/mustermann/composite.rb
155
52
  - lib/mustermann/error.rb
53
+ - lib/mustermann/expander.rb
156
54
  - lib/mustermann/extension.rb
157
55
  - lib/mustermann/identity.rb
56
+ - lib/mustermann/mapper.rb
158
57
  - lib/mustermann/pattern.rb
159
- - lib/mustermann/rails.rb
58
+ - lib/mustermann/pattern_cache.rb
59
+ - lib/mustermann/regexp.rb
160
60
  - lib/mustermann/regexp_based.rb
161
- - lib/mustermann/shell.rb
162
- - lib/mustermann/simple.rb
61
+ - lib/mustermann/regular.rb
62
+ - lib/mustermann/router.rb
63
+ - lib/mustermann/router/rack.rb
64
+ - lib/mustermann/router/simple.rb
163
65
  - lib/mustermann/simple_match.rb
164
66
  - lib/mustermann/sinatra.rb
165
- - lib/mustermann/template.rb
67
+ - lib/mustermann/to_pattern.rb
166
68
  - lib/mustermann/version.rb
167
69
  - mustermann.gemspec
70
+ - spec/ast_spec.rb
71
+ - spec/composite_spec.rb
72
+ - spec/expander_spec.rb
168
73
  - spec/extension_spec.rb
169
74
  - spec/identity_spec.rb
75
+ - spec/mapper_spec.rb
170
76
  - spec/mustermann_spec.rb
171
77
  - spec/pattern_spec.rb
172
- - spec/rails_spec.rb
173
78
  - spec/regexp_based_spec.rb
174
- - spec/shell_spec.rb
79
+ - spec/regular_spec.rb
80
+ - spec/router/rack_spec.rb
81
+ - spec/router/simple_spec.rb
175
82
  - spec/simple_match_spec.rb
176
- - spec/simple_spec.rb
177
83
  - spec/sinatra_spec.rb
178
- - spec/support.rb
179
- - spec/support/coverage.rb
180
- - spec/support/env.rb
181
- - spec/support/expand_matcher.rb
182
- - spec/support/match_matcher.rb
183
- - spec/support/pattern.rb
184
- - spec/template_spec.rb
84
+ - spec/to_pattern_spec.rb
185
85
  homepage: https://github.com/rkh/mustermann
186
86
  licenses:
187
87
  - MIT
@@ -192,36 +92,34 @@ require_paths:
192
92
  - lib
193
93
  required_ruby_version: !ruby/object:Gem::Requirement
194
94
  requirements:
195
- - - '>='
95
+ - - ">="
196
96
  - !ruby/object:Gem::Version
197
- version: 2.0.0
97
+ version: 2.1.0
198
98
  required_rubygems_version: !ruby/object:Gem::Requirement
199
99
  requirements:
200
- - - '>='
100
+ - - ">="
201
101
  - !ruby/object:Gem::Version
202
102
  version: '0'
203
103
  requirements: []
204
104
  rubyforge_project:
205
- rubygems_version: 2.0.0
105
+ rubygems_version: 2.4.3
206
106
  signing_key:
207
107
  specification_version: 4
208
108
  summary: use patterns like regular expressions
209
109
  test_files:
110
+ - spec/ast_spec.rb
111
+ - spec/composite_spec.rb
112
+ - spec/expander_spec.rb
210
113
  - spec/extension_spec.rb
211
114
  - spec/identity_spec.rb
115
+ - spec/mapper_spec.rb
212
116
  - spec/mustermann_spec.rb
213
117
  - spec/pattern_spec.rb
214
- - spec/rails_spec.rb
215
118
  - spec/regexp_based_spec.rb
216
- - spec/shell_spec.rb
119
+ - spec/regular_spec.rb
120
+ - spec/router/rack_spec.rb
121
+ - spec/router/simple_spec.rb
217
122
  - spec/simple_match_spec.rb
218
- - spec/simple_spec.rb
219
123
  - spec/sinatra_spec.rb
220
- - spec/support.rb
221
- - spec/support/coverage.rb
222
- - spec/support/env.rb
223
- - spec/support/expand_matcher.rb
224
- - spec/support/match_matcher.rb
225
- - spec/support/pattern.rb
226
- - spec/template_spec.rb
124
+ - spec/to_pattern_spec.rb
227
125
  has_rdoc:
data/.gitignore DELETED
@@ -1,18 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- .test_queue_stats
7
- .coverage
8
- Gemfile.lock
9
- InstalledFiles
10
- _yardoc
11
- doc/
12
- lib/bundler/man
13
- pkg
14
- rdoc
15
- spec/reports
16
- test/tmp
17
- test/version_tmp
18
- tmp
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --tty
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- rvm:
2
- - 2.0.0
3
- - ruby-head
4
- # - jruby-head
5
- #matrix:
6
- # allow_failures:
7
- # - rvm: jruby-head
data/.yardopts DELETED
@@ -1 +0,0 @@
1
- - README.md internals.md
data/Gemfile DELETED
@@ -1,2 +0,0 @@
1
- source 'https://rubygems.org'
2
- gemspec
data/LICENSE DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2013 Konstantin Haase
2
-
3
- Permission is hereby granted, free of charge, to any person
4
- obtaining a copy of this software and associated documentation
5
- files (the "Software"), to deal in the Software without
6
- restriction, including without limitation the rights to use,
7
- copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- copies of the Software, and to permit persons to whom the
9
- Software is furnished to do so, subject to the following
10
- conditions:
11
-
12
- The above copyright notice and this permission notice shall be
13
- included in all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
- OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- ENV['JRUBY_OPTS'] = '--2.0'
2
- ENV['RBXOPT'] = '-X20'
3
-
4
- task(:spec) { ruby '-w -S rspec' }
5
- task(:doc_stats) { ruby '-S yard stats' }
6
- task(default: [:spec, :doc_stats])
data/internals.md DELETED
@@ -1,64 +0,0 @@
1
- # Internal API
2
-
3
- This document describes how to use [Mustermann](README.md)'s internal API.
4
-
5
- It is a secondary goal to keep the internal API as stable as possible, in a state where it would well be possible to interface with it.
6
- However, the internal API is not covered by Semantic Versioning. As a rule of thumb, no backwards incompatible changes should be introduced to the API in minor releases (starting from 1.0.0).
7
-
8
- Should the internal API gain widespread/production use, we might consider moving parts of it over into the public API.
9
-
10
- Here is a quick example of what you can do with this:
11
-
12
- ``` ruby
13
- require 'mustermann/ast/pattern'
14
-
15
- class MyPattern < Mustermann::AST::Pattern
16
- on("~") { |c| node(:capture, buffer[1]) if expect(/\{(\w+)\}/) }
17
- on("+") { |c| node(:named_splat, buffer[1]) if expect(/\{(\w+)\}/) }
18
- on("?") { |c| node(:optional, node(:capture, buffer[1])) if expect(/\{(\w+)\}/) }
19
- end
20
-
21
- pattern = MyPattern.new("/+{prefix}/~{page}/?{optional}")
22
- pattern.params("/a/") # => nil
23
- pattern.params("/a/b/") # => { "prefix" => "a", "page" => "b", "optional" => nil }
24
- pattern.params("/a/b/c") # => { "prefix" => "a", "page" => "b", "optional" => "c" }
25
- pattern.params("/a/b/c/") # => { "prefix" => "a/b", "page" => "c", "optional" => nil }
26
-
27
- pattern.expand(prefix: "a", page: "foo") # => "/a/foo/"
28
- pattern.expand(prefix: "a/b", page: "c/d") # => "/a/b/c%2Fd/"
29
-
30
- require 'mustermann'
31
- Mustermann.register(:my_pattern, MyPattern, load: false)
32
- Mustermann.new('/+{prefix}/~{page}/?{optional}', type: :my_pattern) # => #<MyPattern:"/+{prefix}/~{page}/?{optional}">
33
-
34
- require 'sinatra/base'
35
- class MyApp < Sinatra::Base
36
- register Mustermann
37
- set :pattern, type: :my_pattern
38
-
39
- get '/hello/~{name}' do
40
- "Hello #{params[:name].capitalize}!"
41
- end
42
- end
43
-
44
- require 'mustermann/ast/tree_renderer'
45
- ast = MyPattern::Parser.parse(pattern.to_s)
46
- puts Mustermann::AST::TreeRenderer.render(ast)
47
-
48
- ```
49
-
50
- ## Pattern Registration
51
-
52
- ...
53
-
54
- ## Build Your Own Pattern
55
-
56
- ...
57
-
58
- ## Patterns Based on Regular Expressions
59
-
60
- ...
61
-
62
- ## AST-Based Patterns
63
-
64
- ...
@@ -1,29 +0,0 @@
1
- require 'mustermann/ast/translator'
2
-
3
- module Mustermann
4
- module AST
5
- # Turns an AST into a human readable string.
6
- # @!visibility private
7
- class TreeRenderer < Translator
8
- # @example
9
- # Mustermann::AST::TreeRenderer.render Mustermann::Sinatra::Parser.parse('/foo')
10
- #
11
- # @!visibility private
12
- def self.render(ast)
13
- new.translate(ast)
14
- end
15
-
16
- translate(Object) { inspect }
17
- translate(Array) { map { |e| "\n" << t(e) }.join.gsub("\n", "\n ") }
18
- translate(:node) { "#{t.type(node)} #{t(payload)}" }
19
- translate(:with_look_ahead) { "#{t.type(node)} #{t(head)} #{t(payload)}" }
20
-
21
- # Turns a class name into a node identifier.
22
- #
23
- # @!visibility private
24
- def type(node)
25
- node.class.name[/[^:]+$/].split(/(?<=.)(?=[A-Z])/).map(&:downcase).join(?_)
26
- end
27
- end
28
- end
29
- end
@@ -1,17 +0,0 @@
1
- require 'mustermann/ast/pattern'
2
-
3
- module Mustermann
4
- # Rails style pattern implementation.
5
- #
6
- # @example
7
- # Mustermann.new('/:foo', type: :rails) === '/bar' # => true
8
- #
9
- # @see Mustermann::Pattern
10
- # @see file:README.md#rails Syntax description in the README
11
- class Rails < AST::Pattern
12
- on(nil, ?)) { |c| unexpected(c) }
13
- on(?*) { |c| node(:named_splat) { scan(/\w+/) } }
14
- on(?() { |c| node(:optional, node(:group) { read unless scan(?)) }) }
15
- on(?:) { |c| node(:capture) { scan(/\w+/) } }
16
- end
17
- end
@@ -1,22 +0,0 @@
1
- require 'mustermann/pattern'
2
- require 'mustermann/simple_match'
3
-
4
- module Mustermann
5
- # Matches strings that are identical to the pattern.
6
- #
7
- # @example
8
- # Mustermann.new('/*.*', type: :shell) === '/bar' # => false
9
- #
10
- # @see Mustermann::Pattern
11
- # @see file:README.md#shell Syntax description in the README
12
- class Shell < Pattern
13
- FLAGS ||= File::FNM_PATHNAME | File::FNM_DOTMATCH | File::FNM_EXTGLOB
14
-
15
- # @param (see Mustermann::Pattern#===)
16
- # @return (see Mustermann::Pattern#===)
17
- # @see (see Mustermann::Pattern#===)
18
- def ===(string)
19
- File.fnmatch? @string, unescape(string), FLAGS
20
- end
21
- end
22
- end
@@ -1,35 +0,0 @@
1
- require 'mustermann/regexp_based'
2
-
3
- module Mustermann
4
- # Sinatra 1.3 style pattern implementation.
5
- #
6
- # @example
7
- # Mustermann.new('/:foo', type: :simple) === '/bar' # => true
8
- #
9
- # @see Mustermann::Pattern
10
- # @see file:README.md#simple Syntax description in the README
11
- class Simple < RegexpBased
12
- supported_options :greedy, :space_matches_plus
13
-
14
- def compile(string, greedy: true, uri_decode: true, space_matches_plus: true, **options)
15
- pattern = string.gsub(/[^\?\%\\\/\:\*\w]/) { |c| encoded(c, uri_decode, space_matches_plus) }
16
- pattern.gsub!(/((:\w+)|\*)/) do |match|
17
- match == "*" ? "(?<splat>.*?)" : "(?<#{$2[1..-1]}>[^/?#]+#{?? unless greedy})"
18
- end
19
- /\A#{Regexp.new(pattern)}\Z/
20
- rescue SyntaxError, RegexpError => error
21
- type = error.message["invalid group name"] ? CompileError : ParseError
22
- raise type, error.message, error.backtrace
23
- end
24
-
25
- def encoded(char, uri_decode, space_matches_plus)
26
- return Regexp.escape(char) unless uri_decode
27
- parser = URI::Parser.new
28
- encoded = Regexp.union(parser.escape(char), parser.escape(char, /./).downcase, parser.escape(char, /./).upcase)
29
- encoded = Regexp.union(encoded, encoded('+', true, true)) if space_matches_plus and char == " "
30
- encoded
31
- end
32
-
33
- private :compile, :encoded
34
- end
35
- end
@@ -1,47 +0,0 @@
1
- require 'mustermann/ast/pattern'
2
-
3
- module Mustermann
4
- # URI template pattern implementation.
5
- #
6
- # @example
7
- # Mustermann.new('/{foo}') === '/bar' # => true
8
- #
9
- # @see Mustermann::Pattern
10
- # @see file:README.md#template Syntax description in the README
11
- # @see http://tools.ietf.org/html/rfc6570 RFC 6570
12
- class Template < AST::Pattern
13
- on ?{ do |char|
14
- variable = proc do
15
- match = expect(/(?<name>\w+)(?:\:(?<prefix>\d{1,4})|(?<explode>\*))?/)
16
- node(:variable, match[:name], prefix: match[:prefix], explode: match[:explode])
17
- end
18
-
19
- operator = buffer.scan(/[\+\#\.\/;\?\&\=\,\!\@\|]/)
20
- expression = node(:expression, [variable[]], operator: operator) { variable[] if scan(?,) }
21
- expression if expect(?})
22
- end
23
-
24
- on(?}) { |c| unexpected(c) }
25
-
26
- # @!visibility private
27
- def compile(*args, **options)
28
- @split_params = {}
29
- super(*args, split_params: @split_params, **options)
30
- end
31
-
32
- # @!visibility private
33
- def map_param(key, value)
34
- return super unless variable = @split_params[key]
35
- value = value.split variable[:separator]
36
- value.map! { |e| e.sub(/\A#{key}=/, '') } if variable[:parametric]
37
- value.map! { |e| super(key, e) }
38
- end
39
-
40
- # @!visibility private
41
- def always_array?(key)
42
- @split_params.include? key
43
- end
44
-
45
- private :compile, :map_param, :always_array?
46
- end
47
- end