El Viernes, 28 de Marzo de 2008, M. Ranganathan escribió:

> Just out of curiosity, I wonder if there are any automatically
> generated parsers for the SIP ABNF out there. I can make what I did
> with antlr ( which successfully made the sip parser torture tests)
> available but I strongly recommend against that approach and I don't
> intend to debug it even if anybody is interested in picking it up.

I use a Ruby programm that generates Ruby RegExps from a ABNF grammar:
  http://www.a-k-r.org/abnf/

With it I get the RegExp for any SIP grammar and can test it. For example:


SIP_VERSION =
%r{sip/\d+\x2e\d+}xi


or a monster as:


SIP_URI =
%r{[Ss][Ii][Pp]:
   (?:(?:[!'-\x2a\x2d\x2e0-9A-Z_a-z~]|
         %[0-9A-Fa-f][0-9A-Fa-f]|
         [\x24&\x2b,/;=\x3f])+
      (?::
         (?:[!'-\x2a\x2d\x2e0-9A-Z_a-z~]|
            %[0-9A-Fa-f][0-9A-Fa-f]|
            [\x24&\x2b,=])*)?@)?
   (?:(?:(?:[0-9A-Za-z]|[0-9A-Za-z][\x2d0-9A-Za-z]*[0-9A-Za-z])\x2e)*
      (?:[A-Za-z]|[A-Za-z][\x2d0-9A-Za-z]*[0-9A-Za-z])\x2e?|
      \d{1,3}\x2e\d{1,3}\x2e\d{1,3}\x2e\d{1,3}|
      \x5b
      (?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*|
         [0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*::
         (?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?|
         ::(?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)
      (?::\d{1,3}\x2e\d{1,3}\x2e\d{1,3}\x2e\d{1,3})?\x5d)(?::\d+)?
   (?:;
      (?:[Tt][Rr][Aa][Nn][Ss][Pp][Oo][Rr][Tt]=
         (?:[Uu][Dd][Pp]|
            [Tt][Cc][Pp]|
            [Ss][Cc][Tt][Pp]|
            [Tt][Ll][Ss]|
            [!%'\x2a\x2b\x2d\x2e0-9A-Z_-z~]+)|
         [Uu][Ss][Ee][Rr]=
         (?:[Pp][Hh][Oo][Nn][Ee]|[Ii][Pp]|[!%'\x2a\x2b\x2d\x2e0-9A-Z_-z~]+)|
         [Mm][Ee][Tt][Hh][Oo][Dd]=
         (?:INVITE|
            ACK|
            OPTIONS|
            BYE|
            CANCEL|
            REGISTER|
            [!%'\x2a\x2b\x2d\x2e0-9A-Z_-z~]+)|
         [Tt][Tt][Ll]=\d{1,3}|
         [Mm][Aa][Dd][Dd][Rr]=
         (?:(?:(?:[0-9A-Za-z]|[0-9A-Za-z][\x2d0-9A-Za-z]*[0-9A-Za-z])\x2e)*
            (?:[A-Za-z]|[A-Za-z][\x2d0-9A-Za-z]*[0-9A-Za-z])\x2e?|
            \d{1,3}\x2e\d{1,3}\x2e\d{1,3}\x2e\d{1,3}|
            \x5b
            (?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*|
               [0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*::
               (?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?|
               ::(?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)
            (?::\d{1,3}\x2e\d{1,3}\x2e\d{1,3}\x2e\d{1,3})?\x5d)|
         [Ll][Rr]|
         (?:[!\x24&-\x2b\x2d-:A-\x5b\x5d_a-z~]|%[0-9A-Fa-f][0-9A-Fa-f])+
         (?:=
            (?:[!\x24&-\x2b\x2d-:A-\x5b\x5d_a-z~]|
               %[0-9A-Fa-f][0-9A-Fa-f])+)?))*
   (?:\x3f(?:[!\x24'-\x2b\x2d-:\x3fA-\x5b\x5d_a-z~]|%[0-9A-Fa-f][0-9A-Fa-f])+=
      (?:[!\x24'-\x2b\x2d-:\x3fA-\x5b\x5d_a-z~]|%[0-9A-Fa-f][0-9A-Fa-f])*
      (?:&(?:[!\x24'-\x2b\x2d-:\x3fA-\x5b\x5d_a-z~]|%[0-9A-Fa-f][0-9A-Fa-f])+=
         (?:[!\x24'-\x2b\x2d-:\x3fA-\x5b\x5d_a-z~]|
            %[0-9A-Fa-f][0-9A-Fa-f])*)*)?}x


And I can test it:


irb> "sip:[EMAIL PROTECTED]" =~ /^#{SIP_URI}$/
=> 0
irb> "sip: asdasdasd @ asdasdasd" =~ /^#{SIP_URI}$/
=> nil


If there is interest in it I could do a small howto of how to use it. Regards.




-- 
Iñaki Baz Castillo

_______________________________________________
Sip-implementors mailing list
[email protected]
https://lists.cs.columbia.edu/cucslists/listinfo/sip-implementors

Reply via email to