Why type "float" and negative floats don't match?

Poster Content
nk4um User
Posts: 168
June 1, 2010 11:11Thank you
Hi Chris,

Indeed, the problem was on my side.

Thank you,
Gregoire
Like · Post Reply
nk4um User
Posts: 177
June 1, 2010 10:14'.' = Any character
Looks like this regex is missing a slash on the ''.''. So should be:

<grammar>res:/services/test/
  <groupname="myFloat">
    <regex>[+-]?\\d+(\\.\\d+)?</regex>
  </group>
</grammar>


Hope that helps,

Chris
Like · Post Reply
nk4um User
Posts: 168
June 1, 2010 08:31/ is seen as part of \d
Hi Tony,

I saw that, when I use :

<grammar>res:/services/test/
  <groupname="myFloat">
    <regex>[+-]?\\d+(.\\d+)?</regex>
  </group>
</grammar>


the following matches :

res:/services/test/10/2


and so "myFloat" contains "10/2".

Is this intented that "\\d" grabs "/"? I thought that it was [0-9].

Thanks,
Gregoire
Like · Post Reply
nk4um User
Posts: 168
May 31, 2010 15:00Ok
Hi Tony,

It works with the given regex. Thank you.

Gregoire
Like · Post Reply
nk4um Administrator
Posts: 607
May 31, 2010 12:14
Ah, I see you were looking at the grammar quick reference in the grammar kitchen!
The regex element has no encoding attribute (it is only on the group element)
It looks like that reference is out of date - look at the detailed doc (linked at top of quick ref) I''ll get the quick reference synchronized.

Cheers, Tony
Like · Post Reply
nk4um Administrator
Posts: 607
May 31, 2010 12:09
Sorry the regex examples I showed contain double backslashes (java literal encoding) the real regex''s are just a single backslash!
Like · Post Reply
nk4um Administrator
Posts: 607
May 31, 2010 12:03
As far as the documentation. Yes we''re always looking to improve and add detail.

The grammar parser always returns strings back as it is simply a matter of break up the identifier into substrings. Encoding is a not-quite pluggable mechanism for allowing types of encoding/decoding of these substrings. I.e. the escaping that is done to nested identifiers inside identifiers in the active URI syntax. Currently that is the only supported encoding.

Cheers, Tony
Like · Post Reply
nk4um Administrator
Posts: 607
May 31, 2010 11:59Looks like a bug
Yep it looks like a bug -regex is "\\\\d+(\\\\.\\\\d+)?" Looks like integer is ok - regex is "[+-]?\\\\d+". I guess integer needs the "[+-]?" added to the start.

Thanks for reporting. As a workaround you can use <regex>[+-]?\\\\d+(\\\\.\\\\d+)?</regex>

Cheers, Tony
Like · Post Reply
nk4um User
Posts: 168
May 31, 2010 11:11Why type "float" and negative floats don't match?
Hi,

I need to be able to parse negative floats in my URL, so I have written this grammar:

<grammar>res:/test/
  <groupname="myfloat">
    <regextype="float" />
  </group>
</grammar>


1) However, the following test in the grammar''s kitchen doesn''t work :

res:/test/-1.3


Is this a bug?

2) The documentation could be more explicit about whether negative values are accepted or not.

builtin types:   <regex type="xxxx" encoding="yyyyy"/>
Where type is optional and can be...

    * uri - matches a URI
    * active-escaped-uri - strictly matches an Active URI argument
    * active-escaped-uri-loose - matches an Active URI argument and is tolerant
    * relative-path - matches a URI relative path
    * relative-directory-path - matches a relative directory path
    * integer - matches an integer
    * float - matches an float
    * nmtoken - BNF nmtoken
    * alphanum - matches alphanumeric characters
    * anything - matches anything
    * nothing - matches nothing


3) Another good documentation improvement would be to tell what is the Java class returned by the parser.

4) And it wouuld be good to explain what is possible with the "encoding" attribute of the <regex> element.

Thanks,
Gregoire
Like · Post Reply