Xtreams: Extending Bootstrap

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

Xtreams: Extending Bootstrap

Sean P. DeNigris
Administrator
I copy-pasted the addr-spec grammar from rfc5322 and was converting it to Xtreams format. One PITA was converting all the decimal values to hex e.g. "%d97" -> "\x000061". I wanted to extend the Xtream grammar to handle "/d97". I extended PEGParserGenerator and PEGParserParser with the following:
    Escape: backslash character: character hexes: hexes
        ...
                character = $d ifTrue: [^(String withAll: hexes) asNumber asCharacter]

But I couldn't figure out how to put this extension into action. PEGParser>>parserBootstrap has a comment "This method was generated with the following code: PEGParser parserPEG parse: 'Grammar' stream: PEGParser grammarPEG actor: PEGParserGenerator new", but evaluating that after extending produced the same output as the original. What am I missing? Thanks.
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Xtreams: Extending Bootstrap

Sean P. DeNigris
Administrator
Sean P. DeNigris wrote
I wanted to extend the Xtream grammar to handle "/d97"
I also wonder:
- is there any specific reason that rules can't contain dashes? This seems pretty common.
- Why use <- instead of = to separate the rule name from the definition? The standards I want to parse use the latter.
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Xtreams: Extending Bootstrap

Sean P. DeNigris
Administrator
In reply to this post by Sean P. DeNigris
Sean P. DeNigris wrote
I wanted to extend the Xtream grammar to handle "/d97".
Okay, I added to PEGParser class>>grammarPEG
    ...
    / BACKSLASH [d] [0-9]+

Sean P. DeNigris wrote
I extended PEGParserGenerator and PEGParserParser with the following:
    Escape: backslash character: character hexes: hexes
Duh, the above method is just the handler for the rule, akin to PetitParser's ==> block
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Xtreams: Extending Bootstrap

Sean P. DeNigris
Administrator
In reply to this post by Sean P. DeNigris
Sean P. DeNigris wrote
- is there any specific reason that rules can't contain dashes? This seems pretty common.
Added by changing #grammrPEG from "Identifier <- [a-zA-Z_] [a-zA-Z0-9_]*" to "Identifier <- [a-zA-Z_] [a-zA-Z0-9_\-]*"

Sean P. DeNigris wrote
- Why use <- instead of = to separate the rule name from the definition? The standards I want to parse use the latter.
Added by changing #grammrPEG from "ASSIGN <- "<-"" to "ASSIGN <- "<-" / "=""

Both seem to be working well.
Cheers,
Sean