New yecc:file/2 option: parserpackage

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

New yecc:file/2 option: parserpackage

Alceste Scalas-3
Hello,

the following patch adds a new option to yecc:file/2:

        {parserpackage, ParserPackage}.
                Use ParserPackage as the package of the Erlang parser
                code that is generated. The default ("") is not to put
                package names in front of the parser module.

This option allows to generate parsers within Erlang packages: for
example, given the file src/foo/bar/parser.yrl, a call like

        yecc:file(parser, [{parserpackage, 'foo.bar'}])

will generate parser.erl with module 'foo.bar.parser' (instead of
'parser' alone).

Regards,

alceste
--
Alceste Scalas <alceste>
CRS4 - http://www.crs4.it/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: yecc-parserpackage.diff
Type: text/x-patch
Size: 2570 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-patches/attachments/20080214/a37ba2ce/attachment.bin>

Reply | Threaded
Open this post in threaded view
|

Absolute module references in Yecc parsers (was: New yecc:file/2 option: parserpackage)

Alceste Scalas-3
Il giorno gio, 14/02/2008 alle 14.43 +0100, Alceste Scalas ha scritto:
> This option allows to generate parsers within Erlang packages: for
> example, given the file src/foo/bar/parser.yrl, a call like
>
>         yecc:file(parser, [{parserpackage, 'foo.bar'}])
>
> will generate parser.erl with module 'foo.bar.parser' (instead of
> 'parser' alone).

The following patch may help, too: it makes the generated parsers always
use absolute module references, by adding a leading dot to some function
calls (both in yecc.erl and yeccpre.hrl).

I chose this solution over two other approaches:

     1. adding -import(lists) and -import(io_lib) to yeccpre.hrl;
     2. asking the Yecc users to explicitly add -import(lists) and
        -import(io_lib) to the "Erlang code" section of their grammars,
        when they want to generate parsers inside a package hierarchy.

IMHO the patch is clearer (no packaging issues at all) and cleaner (it
does not interfere with "Erlang code" sections by adding unexpected
imports).

Regards,

alceste
--
Alceste Scalas <alceste>
CRS4 - http://www.crs4.it/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: yecc-absmodules.diff
Type: text/x-patch
Size: 2568 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-patches/attachments/20080214/1ac68566/attachment.bin>

Reply | Threaded
Open this post in threaded view
|

New yecc:file/2 option: parserpackage (R12B updates)

Alceste Scalas-3
Il giorno gio, 14/02/2008 alle 17.19 +0100, Alceste Scalas ha scritto:

> Il giorno gio, 14/02/2008 alle 14.43 +0100, Alceste Scalas ha scritto:
> > This option allows to generate parsers within Erlang packages: for
> > example, given the file src/foo/bar/parser.yrl, a call like
> >
> >         yecc:file(parser, [{parserpackage, 'foo.bar'}])
> >
> > will generate parser.erl with module 'foo.bar.parser' (instead of
> > 'parser' alone).
>
> The following patch may help, too: it makes the generated parsers always
> use absolute module references, by adding a leading dot to some function
> calls (both in yecc.erl and yeccpre.hrl).

D'oh, the previous patches were only tested with OTP-R11B-5 and don't
apply cleanly on newer OTP releases.  I'm sorry!

Here's an updated patch, tested with OTP-R12B-1, that implements both
the new 'parserpackage' option and absolute module references in
generated parsers.

Regards,

alceste
--
Alceste Scalas <alceste>
CRS4 - http://www.crs4.it/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: yecc-r12b-parserpackage.diff
Type: text/x-patch
Size: 7125 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-patches/attachments/20080215/09b04407/attachment.bin>