Announce: Enki 1.0

pragma pragma_member at pathlink.com
Fri Jun 9 05:54:38 PDT 2006


In article <e6aag6$1gml$1 at digitaldaemon.com>, BCS says...
>
>pragma wrote:
>> 
>> All of the imports that a generated parser needs should be in the enki SDK
>> distribution - my apologies for not including that with the binary.
>
>Which imports should be used? For now I can hand edit them into the 
>parser.d file.

You should probably start off with types.d and BaseParser.d from the SDK:

private import enki.types;
private import enki.BaseParser;

Alternately, you can extend BaseParser to build up any additional functionality
you may need.  This is the approach that Enki itself uses.  Also, if you're
really gung-ho, you can simply implement IParser from scratch and use that as a
base parser class instead.

In leiu of a proper tutorial, here's a little more information on where to go
from there:

In your program, create a new instance of your parser, and initalize it with
your input data.  To begin parsing, simply call the starting rule; this will
have the same name as what you specified in your EBNF, prefixed by "parse_".

auto myParser = new Parser();
myParser.initalize(inputString);
auto parseResult = myParser.parse_StartRule();

(I'll be cleaning this up some in the next release)

Now 'parseResult' is an instance of ResultT!() which has two members: 'result'
and 'success'.  'success' indicates if the rule was satisfied or not, and
'result' is the binding type indicated in your grammar definition.  If you do
not indicate a result type in your grammar, 'result' will default to a bool that
also contains the success status.

if(parseResult .success){
// do something with parseResult.result 
}

I'll be the first to admit: Enki's error reporting could stand some improvement.
But for what it's worth, it does help you zero in on why your grammar isn't
parsing.  To use it, simply get the error report from the parser should the
start rule flag a failure:

if(!parseResult.success){
writefln("Error: %s",parser.getErrorReport());
}

BCS, I hope that clears things up a bit. :)

- EricAnderton at yahoo



More information about the Digitalmars-d-announce mailing list