Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to parse or for both string comparisons. #1

Open
wpoosanguansit opened this issue Sep 11, 2015 · 3 comments
Open

Unable to parse or for both string comparisons. #1

wpoosanguansit opened this issue Sep 11, 2015 · 3 comments

Comments

@wpoosanguansit
Copy link

I have the query as below -

"$filter=item eq '12' or itimeLineItems eq 'new'"

And the result is

Filter(EqualToExp(Property(item),StringLiteral('12' or itimeLineItems eq 'new')))

While "$filter=item eq 12 or itimeLineItems eq 'new'" is parsed correctly:

Filter(OrExp(EqualToExp(Property(item),Number(12)),EqualToExp(Property(itimeLineItems),StringLiteral('new'))))

Also the Property seems to be limited to name without / in the path as item/color. Thanks for your help.

Note: I am updating the code

from

lazy val string: PackratParser[StringLiteral] = ("'" + """([^"\p{Cntrl}\]|\[\/bfnrt]|\u[a-fA-F0-9]{4})*""" + "'").r ^^ StringLiteral | stringLiteral ^^ StringLiteral

to

lazy val string: PackratParser[StringLiteral] = ("""(["'])(?:\1|.)*?\1""").r ^^ StringLiteral

and

from

lazy val idn: PackratParser[Property] = ident ^^ Property

to

lazy val idn: PackratParser[Property] = "[A-Za-z0-9/]+".r ^^ Property | ident ^^ Property

And those seem to fix the issues for limited test cases I have.

@adilakhter
Copy link
Owner

Hi,

Thanks for your post. Intially this project was built as a prototype and only covers limited cases to demostrate the POC.

In future, I have a plan to work on it and make it more concrete with respect to OData spec. If you can comeup with a generic solution, please feel free to open a PR.

Regards, Adil

@wpoosanguansit
Copy link
Author

That would be great. Thanks.

On Sep 25, 2015, at 5:29 AM, Md. Adil AKhter [email protected] wrote:

Hi,

Thanks for your post. Intially this project was built as a prototype and only covers limited cases to demostrate the POC.

In future, I have a plan to work on it and make it more concrete with respect to OData spec. If you can comeup with a generic solution, please feel free to open a PR.

Regards, Adil


Reply to this email directly or view it on GitHub.

@wpoosanguansit
Copy link
Author

I have some time to verify the change with new added test to your suite:

  test("Parse $filter=Name eq 'Tom' and LastName eq 'Jones'") {
    val query = "$filter=Name eq 'Tom' and LastName eq 'Jones'"
    val expectedAST =
      Filter(
        AndExp(
          EqualToExp(
            Property("Name"),
            StringLiteral("'Tom'")
          )
          , EqualToExp(
              Property("LastName"),
              StringLiteral("'Jones'")
            )
        )
      )
    val actualAST:Expression = p.parseThis(mainParser, query).get
    assert(actualAST == expectedAST)
  }

While taking out the change to idn because it fails the ResourcePath parsing. I think the code should be working for the filter and parser with the change. However, it still does not take care of the case where filter name is nested like $filter=User/Name eq 'Tom' and User/LastName eq 'Jones' which is acceptable by the v4 standard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants