Commit 759aa4d
Changed files (2)
lib
scim
kit
v2
spec
scim
kit
lib/scim/kit/v2/parser.rb
@@ -5,13 +5,14 @@ require 'parslet'
module Scim
module Kit
module V2
+ # Parses SCIM filter queries
class Parser < Parslet::Parser
root :filter
# FILTER = attrExp / logExp / valuePath / *1"not" "(" FILTER ")"
rule(:filter) do
(attribute_expression | logical_expression | value_path) |
- (not_op? >> lparen >> filter >> rparen)
+ (not_op >> lparen >> filter >> rparen)
end
# valuePath = attrPath "[" valFilter "]" ; FILTER uses sub-attributes of a parent attrPath
@@ -23,7 +24,7 @@ module Scim
rule(:value_filter) do
attribute_expression |
logical_expression |
- (not_op? >> lparen >> value_filter >> rparen)
+ (not_op >> lparen >> value_filter >> rparen)
end
# attrExp = (attrPath SP "pr") / (attrPath SP compareOp SP compValue)
@@ -63,8 +64,7 @@ module Scim
rule(:presence) { str('pr') }
rule(:and_op) { str('and') }
rule(:or_op) { str('or') }
- rule(:not_op) { str('not') }
- rule(:not_op?) { not_op.maybe }
+ rule(:not_op) { str('not').repeat(0, 1) }
rule(:falsey) { str('false') }
rule(:truthy) { str('true') }
rule(:null) { str('null') }
@@ -84,13 +84,13 @@ module Scim
rule(:rparen) { str(')') }
rule(:lbracket) { str('[') >> space? }
rule(:rbracket) { str(']') >> space? }
- rule(:digit) { match(/\d/) }
+ rule(:digit) { match('\d') }
rule(:at) { str('@') }
rule(:quote) { str('"') }
rule(:single_quote) { str("'") }
rule(:space) { match('\s') }
rule(:space?) { space.maybe }
- rule(:alpha) { match('[a-zA-Z]') }
+ rule(:alpha) { match['a-zA-Z'] }
rule(:dot) { str('.') }
rule(:colon) { str(':') }
rule(:hyphen) { str('-') }
spec/scim/kit/v2/parser_spec.rb
@@ -48,8 +48,8 @@ RSpec.describe Scim::Kit::V2::Parser do
[
'firstName eq "Tsuyoshi"',
- 'firstName pr',
- #'firstName eq "Tsuyoshi" and lastName eq "Garret"'
+ 'firstName pr'
+ # 'firstName eq "Tsuyoshi" and lastName eq "Garret"'
].each do |x|
specify { expect(subject.value_filter).to parse(x) }
end
@@ -65,7 +65,7 @@ RSpec.describe Scim::Kit::V2::Parser do
'firstName eq "Tsuyoshi" and lastName eq "Garret"',
'firstName eq "Tsuyoshi" or lastName eq "Garret"',
'title pr and userType eq "Employee"',
- 'title pr or userType eq "Employee"',
+ 'title pr or userType eq "Employee"'
].each do |x|
specify { expect(subject.logical_expression).to parse(x) }
end
@@ -106,7 +106,9 @@ RSpec.describe Scim::Kit::V2::Parser do
specify { expect(subject.presence).to parse('pr') }
specify { expect(subject.and_op).to parse('and') }
specify { expect(subject.or_op).to parse('or') }
- specify { expect(subject.not_op?).to parse('not') }
+ specify { expect(subject.not_op).to parse('not') }
+ specify { expect(subject.not_op).to parse('') }
+ specify { expect(subject.not_op).not_to parse('not not') }
specify { expect(subject.falsey).to parse('false') }
specify { expect(subject.truthy).to parse('true') }
specify { expect(subject.null).to parse('null') }
@@ -120,15 +122,15 @@ RSpec.describe Scim::Kit::V2::Parser do
end
[
- 'title pr',
- #'title pr and userType eq "Employee"',
- #'title pr or userType eq "Intern"',
- #'',
- #'userType eq "Employee" and (emails co "example.com" or emails.value co "example.org")',
- #'userType ne "Employee" and not (emails co "example.com" or emails.value co "example.org")',
- #'userType eq "Employee" and (emails.type eq "work") ',
- #'userType eq "Employee" and emails[type eq "work" and value co "@example.com"]',
- #'emails[type eq "work" and value co "@example.com"] or ims[type eq "xmpp" and value co "@foo.com"]'
+ 'title pr'
+ # 'title pr and userType eq "Employee"',
+ # 'title pr or userType eq "Intern"',
+ # '',
+ # 'userType eq "Employee" and (emails co "example.com" or emails.value co "example.org")',
+ # 'userType ne "Employee" and not (emails co "example.com" or emails.value co "example.org")',
+ # 'userType eq "Employee" and (emails.type eq "work") ',
+ # 'userType eq "Employee" and emails[type eq "work" and value co "@example.com"]',
+ # 'emails[type eq "work" and value co "@example.com"] or ims[type eq "xmpp" and value co "@foo.com"]'
].each do |x|
specify { expect(subject).to parse(x) }
end