[squeak-dev] Xtreams: Debugging Grammars
Chris Cunnington
brasspen at gmail.com
Fri Oct 21 15:28:28 UTC 2016
>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?!
Hi Sean,
Your error is saying is that there is no key called 'quotedstring' in
the dictionary in the grammar ivar of your parser.
In each parser is a grammar ivar. It contains a dictionary. The values
of the dictionary are graphs of compiled blocks. Each node of the graph
is a block with arguments that are blocks that have arguments that are
blocks, etc. It's a graph of compiled blocks.
Try this. Add in PEGParser class.
grammar3Names
" a grammar to create a parser to sort three names as per page 24 of
Grune's book Parsing Techniques (1990)"
^'Sentence <- NAME
NAME <- "tom" / "dick" / "harry"
'
Now execute this.
(PEGParser parserBootstrap) parse: 'Grammar' stream: PEGParser
grammar3Names reading actor: PEGParserGenerator new.
That will show you the code that will create the dictionary in the
grammar ivar. Now make a change.
myparser := (PEGParser parserBootstrap) parse: 'Grammar' stream:
PEGParser grammar3Names reading actor: PEGParserParser new.
You generated the parser, not the code for the parser.
To use the parser.
myparser parse: 'Sentence' stream: 'harry' reading actor: nil
Now let's look at the same thing in three ways.
PEGParser>>#grammarPEG this is the grammar
PEGParser>>#parserBootstrap this is the code generated by the
PEGParserGenerator from grammarPEG
PEGParser>>#parserPEG this is the parser returned by PEGParserParser
from grammarPEG
You will see that PEGParser parserBootstrap and PEGParser parserPEG are
interchangeable anywhere. In fact, if the goal is to populate the
grammar ivar with a dictionary to make a parser, then #parserPEG starts
to grate on one's nerves, because you already have what you need in the
grammar ivar by evaluating PEGParser parserBootstrap. #parserPEG
compiles the grammarPEG using PEGParserParser into the grammar ivar to
make a parser, but it's the exact same as what was already there. It's
irritating.
I'll release some examples in a package called Xtreamly some time before
Christmas to help start understanding Xtreams-Parsing.
HTH,
Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20161021/ea4a3735/attachment-0001.htm
More information about the Squeak-dev
mailing list
|