At 07:03 PM 11/28/00 +0000, Tom Hughes wrote:
>In message <[EMAIL PROTECTED]>
>           Dan Sugalski <[EMAIL PROTECTED]> wrote:
>
> > The third parameter is the flags parameter, and it's optional. If omitted
> > or set to PERL_CHAR_SOURCE, the second parameter is treated as a standard
> > null-terminated string. If set to PERL_COUNTED_SOURCE, the second parameter
> > is treated as if it points to a stream of bytes, where the first four are
> > the length of the source to be read followed by the source. If set to
> > PERL_FILE_SOURCE it's assumed to be a FILE *, while if set to
> > PERL_GENERATED_SOURCE it's assumed to be a pointer to a function that
> > returns a char pointer. If it's OR'd with PERL_UTF8_SOURCE then the stream
> > is assumed to be in UTF-8 format instead of platform native.
>
>This all seems a bit horrible to me. That kind of overloading of
>multiple meanings onto an argument is often a sign of a bad design
>that could be improved.

Sure, that's distinctly possible. I'm shooting for extreme simplicity in 
the standard case here, but that doesn't mean I'm hitting it. (Or anything 
else for that matter)

>Applying the maxim that any software design problem can be solved
>with sufficient levels of abstraction I'd suggest that passing some
>sort of abstract stream pointer would be better. Then there could
>be different sorts of streams that provided the source from a string
>or a file or whatever other wonderful data source somebody comes up
>with.

Right, and I called my abstract stream "void *source". :)

>The common case of parsing a string could of course be simplified
>with a small wrapper function that created a string based stream
>and then called the main parser entry point.

That means another function in the API. I suppose perl_parse_string() and 
perl_parse_file() are valid options. I'd rather keep the API that embedders 
will be using as small as possible, but two functions with simple names and 
pameters may be better than one function with mildly odd parameters in the 
non-trivial case.

                                        Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
[EMAIL PROTECTED]                         have teddy bears and even
                                      teddy bears get drunk

Reply via email to