Xtreams: Debugging Grammars

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Xtreams: Debugging Grammars

Sean P. DeNigris
Administrator
I converted parts of rfc 5322 to the following:
    grammarEmailAddress

        ^'addrspec       <-   localpart "@" domain
localpart      <-   dotatom / quotedstring /* obs-local-part */
domain          <-   dotatom / domainliteral /* obs-domain */
domainliteral  <-   [CFWS] "[" *([FWS] dtext) [FWS] "]" [CFWS]
dtext           <- [\x000021-\x000050] / /* Printable US-ASCII */
                                                                                [\x000054-\x00007E] /* characters not including */
                                                                                /* / obs-dtext          ;  "[", "]", or "\" */
       
/* rfc5234 B.1 */
ALPHA          <-  [\x000041-\x00005A] / [\x000061-\x00007A]
DIGIT          <-  [\x000030-\x000039]
HTAB           <-  [\x000009] /* horizontal tab */
SP             <-  [\x000020]
WSP            <-  SP / HTAB

/* 3.2.2. Folding White Space and Comments */
FWS             <-   ([*WSP CRLF] 1*WSP)
/* obs-FWS */
   ctext           <-   [\x000021-\x000027] /
                       [\x00002A-\x00005B] /
                       [\x00005D-\x00007E]

   ccontent        <-   ctext / quotedpair / comment

   comment         <-   "(" *([FWS] ccontent) [FWS] ")"

   CFWS            <-   (1*([FWS] comment) [FWS]) / FWS
/* 3.2.1.  Quoted characters */
   quotedpair     <-   ("\" (VCHAR / WSP)) /* / obs-qp */
/* 3.2.3.  Atom */
atext           <-   ALPHA / DIGIT /
                       "!" / "#" /
                       "$" / "%" /
                       "&" / "''" /
                       "*" / "+" /
                       "-" / "/" /
                       "=" / "?" /
                       "^" / "_" /
                       "`" / "{" /
                       "|" / "}" /
                       "~"

   atom            <-   [CFWS] 1*atext [CFWS]

   dotatomtext   <-   1*atext *("." 1*atext)

   dotatom        <-   [CFWS] dotatomtext [CFWS]

/* 3.2.4.  Quoted Strings */
qtext           <-   [\x000021] / /* Printable US-ASCII */
                     [\x000023-\x00005B] / /* characters not including */
                     [\x00005D-\x00007E] /* "\" or the quote character */
                       /* obs-qtext */
qcontent        <-   qtext / quotedpair
quotedstring   <-   [CFWS] DQUOTE *([FWS] qcontent) [FWS] DQUOTE [CFWS]'

When I evaluate:
    parser := PEGParser parserPEG parse: 'Grammar' stream: PEGParser grammarEmailAddress actor: PEGParserParser new.

I get: KeyNotFound: key 'quotedstring' not found in Dictionary

How am I supposed to debug that to find the typo in my giant string above?!
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Xtreams: Debugging Grammars

stepharo
Hi sean

Xtreams? Just to be sure is PEGParser built using Xtreams?


Stef

Le 23/6/16 à 02:20, Sean P. DeNigris a écrit :

> I converted parts of rfc 5322 to the following:
>      grammarEmailAddress
>
> ^'addrspec       <-   localpart "@" domain
> localpart      <-   dotatom / quotedstring /* obs-local-part */
> domain          <-   dotatom / domainliteral /* obs-domain */
> domainliteral  <-   [CFWS] "[" *([FWS] dtext) [FWS] "]" [CFWS]
> dtext           <- [\x000021-\x000050] / /* Printable US-ASCII */
> [\x000054-\x00007E] /* characters not including */
> /* / obs-dtext          ;  "[", "]", or "\" */
>
> /* rfc5234 B.1 */
> ALPHA          <-  [\x000041-\x00005A] / [\x000061-\x00007A]
> DIGIT          <-  [\x000030-\x000039]
> HTAB           <-  [\x000009] /* horizontal tab */
> SP             <-  [\x000020]
> WSP            <-  SP / HTAB
>
> /* 3.2.2. Folding White Space and Comments */
> FWS             <-   ([*WSP CRLF] 1*WSP)
> /* obs-FWS */
>     ctext           <-   [\x000021-\x000027] /
>                         [\x00002A-\x00005B] /
>                         [\x00005D-\x00007E]
>
>     ccontent        <-   ctext / quotedpair / comment
>
>     comment         <-   "(" *([FWS] ccontent) [FWS] ")"
>
>     CFWS            <-   (1*([FWS] comment) [FWS]) / FWS
> /* 3.2.1.  Quoted characters */
>     quotedpair     <-   ("\" (VCHAR / WSP)) /* / obs-qp */
> /* 3.2.3.  Atom */
> atext           <-   ALPHA / DIGIT /
>                         "!" / "#" /
>                         "$" / "%" /
>                         "&" / "''" /
>                         "*" / "+" /
>                         "-" / "/" /
>                         "=" / "?" /
>                         "^" / "_" /
>                         "`" / "{" /
>                         "|" / "}" /
>                         "~"
>
>     atom            <-   [CFWS] 1*atext [CFWS]
>
>     dotatomtext   <-   1*atext *("." 1*atext)
>
>     dotatom        <-   [CFWS] dotatomtext [CFWS]
>
> /* 3.2.4.  Quoted Strings */
> qtext           <-   [\x000021] / /* Printable US-ASCII */
>                       [\x000023-\x00005B] / /* characters not including */
>                       [\x00005D-\x00007E] /* "\" or the quote character */
>                         /* obs-qtext */
> qcontent        <-   qtext / quotedpair
> quotedstring   <-   [CFWS] DQUOTE *([FWS] qcontent) [FWS] DQUOTE [CFWS]'
>
> When I evaluate:
>      parser := PEGParser parserPEG parse: 'Grammar' stream: PEGParser
> grammarEmailAddress actor: PEGParserParser new.
>
> I get: KeyNotFound: key 'quotedstring' not found in Dictionary
>
> How am I supposed to debug that to find the typo in my giant string above?!
>
>
>
> -----
> Cheers,
> Sean
> --
> View this message in context: http://forum.world.st/Xtreams-Debugging-Grammars-tp4902581.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Xtreams: Debugging Grammars

Tudor Girba-2
Hi,

If you are looking for PEG parsers, you can also try using PetitParser as it comes with several debugging and inspection tools.

Cheers,
Doru


> On Jun 23, 2016, at 10:23 PM, stepharo <[hidden email]> wrote:
>
> Hi sean
>
> Xtreams? Just to be sure is PEGParser built using Xtreams?
>
>
> Stef
>
> Le 23/6/16 à 02:20, Sean P. DeNigris a écrit :
>> I converted parts of rfc 5322 to the following:
>>     grammarEmailAddress
>>
>> ^'addrspec       <-   localpart "@" domain
>> localpart      <-   dotatom / quotedstring /* obs-local-part */
>> domain          <-   dotatom / domainliteral /* obs-domain */
>> domainliteral  <-   [CFWS] "[" *([FWS] dtext) [FWS] "]" [CFWS]
>> dtext           <- [\x000021-\x000050] / /* Printable US-ASCII */
>> [\x000054-\x00007E] /* characters not including */
>> /* / obs-dtext          ;  "[", "]", or "\" */
>>
>> /* rfc5234 B.1 */
>> ALPHA          <-  [\x000041-\x00005A] / [\x000061-\x00007A]
>> DIGIT          <-  [\x000030-\x000039]
>> HTAB           <-  [\x000009] /* horizontal tab */
>> SP             <-  [\x000020]
>> WSP            <-  SP / HTAB
>>
>> /* 3.2.2. Folding White Space and Comments */
>> FWS             <-   ([*WSP CRLF] 1*WSP)
>> /* obs-FWS */
>>    ctext           <-   [\x000021-\x000027] /
>>                        [\x00002A-\x00005B] /
>>                        [\x00005D-\x00007E]
>>
>>    ccontent        <-   ctext / quotedpair / comment
>>
>>    comment         <-   "(" *([FWS] ccontent) [FWS] ")"
>>
>>    CFWS            <-   (1*([FWS] comment) [FWS]) / FWS
>> /* 3.2.1.  Quoted characters */
>>    quotedpair     <-   ("\" (VCHAR / WSP)) /* / obs-qp */
>> /* 3.2.3.  Atom */
>> atext           <-   ALPHA / DIGIT /
>>                        "!" / "#" /
>>                        "$" / "%" /
>>                        "&" / "''" /
>>                        "*" / "+" /
>>                        "-" / "/" /
>>                        "=" / "?" /
>>                        "^" / "_" /
>>                        "`" / "{" /
>>                        "|" / "}" /
>>                        "~"
>>
>>    atom            <-   [CFWS] 1*atext [CFWS]
>>
>>    dotatomtext   <-   1*atext *("." 1*atext)
>>
>>    dotatom        <-   [CFWS] dotatomtext [CFWS]
>>
>> /* 3.2.4.  Quoted Strings */
>> qtext           <-   [\x000021] / /* Printable US-ASCII */
>>                      [\x000023-\x00005B] / /* characters not including */
>>                      [\x00005D-\x00007E] /* "\" or the quote character */
>>                        /* obs-qtext */
>> qcontent        <-   qtext / quotedpair
>> quotedstring   <-   [CFWS] DQUOTE *([FWS] qcontent) [FWS] DQUOTE [CFWS]'
>>
>> When I evaluate:
>>     parser := PEGParser parserPEG parse: 'Grammar' stream: PEGParser
>> grammarEmailAddress actor: PEGParserParser new.
>>
>> I get: KeyNotFound: key 'quotedstring' not found in Dictionary
>>
>> How am I supposed to debug that to find the typo in my giant string above?!
>>
>>
>>
>> -----
>> Cheers,
>> Sean
>> --
>> View this message in context: http://forum.world.st/Xtreams-Debugging-Grammars-tp4902581.html
>> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>>
>>
>
>

--
www.tudorgirba.com
www.feenk.com

"Things happen when they happen,
not when you talk about them happening."


Reply | Threaded
Open this post in threaded view
|

Re: Xtreams: Debugging Grammars

Sean P. DeNigris
Administrator
In reply to this post by stepharo
stepharo wrote
Xtreams? Just to be sure is PEGParser built using Xtreams?
Yes, there's some kind of bootstrapping process but I'm not clear how it works and haven't found any documentation.
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Xtreams: Debugging Grammars

Sean P. DeNigris
Administrator
In reply to this post by Tudor Girba-2
Tudor Girba-2 wrote
If you are looking for PEG parsers, you can also try using PetitParser as it comes with several debugging and inspection tools.
I used Xtreams because I wanted to copy/paste the grammar from the spec instead of rewriting it in Smalltalk. I don't think that is possible in PP, is it?
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Xtreams: Debugging Grammars

Sean P. DeNigris
Administrator
In reply to this post by Sean P. DeNigris
Sean P. DeNigris wrote
How am I supposed to debug that to find the typo in my giant string above?!
Two problems I found copy/pasting grammars from standard docs:
- Repititions (*) were prefix instead of postfix
- "\" had to be escaped to "\\"

I still wonder about debugging techniques, though. If one was building a grammar from scratch, it might be easy to start with blocks that are constantly working, but the grammar in RFC 5322 is very interwoven. It's hard to see which rules are necessary up front.
Cheers,
Sean