comp.lang.ada
 help / color / mirror / Atom feed
* How to extend packages
@ 2008-06-06 17:00 snoopysalive
  2008-06-06 17:24 ` witmer
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: snoopysalive @ 2008-06-06 17:00 UTC (permalink / raw)


Hi, Ada-folks!

I'd like to extend the GNAT.Regpat a little bit, so that it contains
additional operations like Split (the same as in Perl or Ruby) or Join
(dito).

When speaking of "extending" I mean it in the sense of e.g. Java where
extending a class means that the child class contains all the public
or protected operations and attributes as the super class. Perhaps you
know now, what I want to achieve. I want to have an extended "child"
package of GNAT.Regpat. In the end it should have an own name like
e.g. "Mine.Regex" and contain all operation etc. of its "super"
package plus the operations I'll additionally implement.

I've been trying for hours now, so I'm passing this question to you.
How to extend package?

Thanks,
Matthias



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to extend packages
  2008-06-06 17:00 How to extend packages snoopysalive
@ 2008-06-06 17:24 ` witmer
  2008-06-06 17:45 ` Sébastien Morand
  2008-06-06 18:16 ` Georg Bauhaus
  2 siblings, 0 replies; 11+ messages in thread
From: witmer @ 2008-06-06 17:24 UTC (permalink / raw)


On Jun 6, 1:00 pm, "snoopysal...@googlemail.com"
<snoopysal...@googlemail.com> wrote:
> Hi, Ada-folks!
>
> I'd like to extend the GNAT.Regpat a little bit, so that it contains
> additional operations like Split (the same as in Perl or Ruby) or Join
> (dito).
>
> When speaking of "extending" I mean it in the sense of e.g. Java where
> extending a class means that the child class contains all the public
> or protected operations and attributes as the super class. Perhaps you
> know now, what I want to achieve. I want to have an extended "child"
> package of GNAT.Regpat. In the end it should have an own name like
> e.g. "Mine.Regex" and contain all operation etc. of its "super"
> package plus the operations I'll additionally implement.
>
> I've been trying for hours now, so I'm passing this question to you.
> How to extend package?
>
> Thanks,
> Matthias

I don't there's a way to directly do what you want, but if I'm
understanding you correctly, this should do it:

--"Parent" spec
package Parent is
    procedure Proc_1;
    procedure Proc_2;
    --etc...
end Parent;

--"Child" spec
with Parent;

package Child is
    procedure Proc_1 renames Parent.Proc1;
    procedure Proc_2 renames Parent.Proc2;
    --and so on...

    --Child members go here
end Child;



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to extend packages
  2008-06-06 17:00 How to extend packages snoopysalive
  2008-06-06 17:24 ` witmer
@ 2008-06-06 17:45 ` Sébastien Morand
  2008-06-07 14:21   ` Stephen Leake
  2008-06-07 16:04   ` Simon Wright
  2008-06-06 18:16 ` Georg Bauhaus
  2 siblings, 2 replies; 11+ messages in thread
From: Sébastien Morand @ 2008-06-06 17:45 UTC (permalink / raw)


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

snoopysalive@googlemail.com a �crit :
> Hi, Ada-folks!
> 
> I'd like to extend the GNAT.Regpat a little bit, so that it contains
> additional operations like Split (the same as in Perl or Ruby) or Join
> (dito).
> 
> When speaking of "extending" I mean it in the sense of e.g. Java where
> extending a class means that the child class contains all the public
> or protected operations and attributes as the super class. Perhaps you
> know now, what I want to achieve. I want to have an extended "child"
> package of GNAT.Regpat. In the end it should have an own name like
> e.g. "Mine.Regex" and contain all operation etc. of its "super"
> package plus the operations I'll additionally implement.
> 
> I've been trying for hours now, so I'm passing this question to you.
> How to extend package?

Try this:

with GNAT.Regpat; use GNAT.Regpat;

package GNAT.Regpat.Extended is
end GNAT.Regpat.Extended;

Then when you use GNAT.Regpat.Extended, GNAT.Regpat is available too.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)

iD8DBQFISXer+zV9xm4PlDQRAg3JAJ9C0PKClnt6uc1Tjl85b1zvZfQrmgCfcQgm
1tLnIgHiSGjifzvMyBvwOgc=
=JX0R
-----END PGP SIGNATURE-----



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to extend packages
  2008-06-06 17:00 How to extend packages snoopysalive
  2008-06-06 17:24 ` witmer
  2008-06-06 17:45 ` Sébastien Morand
@ 2008-06-06 18:16 ` Georg Bauhaus
  2 siblings, 0 replies; 11+ messages in thread
From: Georg Bauhaus @ 2008-06-06 18:16 UTC (permalink / raw)


snoopysalive@googlemail.com wrote:
> Hi, Ada-folks!
> 
> I'd like to extend the GNAT.Regpat a little bit, so that it contains
> additional operations like Split (the same as in Perl or Ruby) or Join
> (dito).

A Split subprogram is available in the AWK section of the GNAT library.

> When speaking of "extending" I mean it in the sense of e.g. Java where
> extending a class means that the child class contains all the public
> or protected operations and attributes as the super class.

You can't extend packages in Java either ;-) Like you have said,
you extend a class and so in Ada, you extend a type T by deriving
a new type D from T. You can do that in the same package, or in a nested
package, or in a child package, or in some other package.
Since GNAT.Regpat should not normally be touched (it lives in compiler
file space), you would indeed write a child package in this case;
but note that a child _package_ is a child in the sence of a
hierarchical library of modules, like "util" would be a
"child package" of "java" in "java.util" if you did use Ada terms
for describing Java packages.



> Perhaps you
> know now, what I want to achieve. I want to have an extended "child"
> package of GNAT.Regpat. In the end it should have an own name like
> e.g. "Mine.Regex" and contain all operation etc. of its "super"
> package plus the operations I'll additionally implement.

Just in case you only need more RE matching capabilities,
be sure to look an GNAT.Spitbol.Patterns. SPITBOL patterns have
everything that Perl5 REs have, including a working \G.

> I've been trying for hours now, so I'm passing this question to you.
> How to extend package?

You don't.



 -- Georg



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to extend packages
  2008-06-06 17:45 ` Sébastien Morand
@ 2008-06-07 14:21   ` Stephen Leake
  2008-06-07 16:04   ` Simon Wright
  1 sibling, 0 replies; 11+ messages in thread
From: Stephen Leake @ 2008-06-07 14:21 UTC (permalink / raw)


S�bastien Morand <seb.morand@gmail.com> writes:

> snoopysalive@googlemail.com a �crit :
>> Hi, Ada-folks!
>> 
>> I'd like to extend the GNAT.Regpat a little bit, so that it contains
>> additional operations like Split (the same as in Perl or Ruby) or Join
>> (dito).
>> 
>> When speaking of "extending" I mean it in the sense of e.g. Java where
>> extending a class means that the child class contains all the public
>> or protected operations and attributes as the super class. Perhaps you
>> know now, what I want to achieve. I want to have an extended "child"
>> package of GNAT.Regpat. In the end it should have an own name like
>> e.g. "Mine.Regex" and contain all operation etc. of its "super"
>> package plus the operations I'll additionally implement.
>> 
>> I've been trying for hours now, so I'm passing this question to you.
>> How to extend package?
>
> Try this:
>
> with GNAT.Regpat; use GNAT.Regpat;
>
> package GNAT.Regpat.Extended is
> end GNAT.Regpat.Extended;

This is probably the best approach.

> Then when you use GNAT.Regpat.Extended, GNAT.Regpat is available too.

This is not true. To be precise:

Suppose GNAT.Regpat declares 'foo', and GNAT.Regpat.Extended declares
'bar'.

with GNAT.Regpat.Extended;
package A is
...
end A;

Within A, you can say GNAT.Regpat.Extended.foo, or GNAT.Regpat.bar,
but 'foo' and 'bar' by themselves are not visible.

with GNAT.Regpat.Extended;
package B is
    use GNAT.Regpat.Extended;
...
end B;

Within B, you can say GNAT.Regpat.Extended.foo, or GNAT.Regpat.bar.
'foo' is visible by itself, but 'bar' is not.

with GNAT.Regpat.Extended;
package C is
    use GNAT.Regpat.Extended;
    use GNAT.Regpat;
...
end C;

Within C, 'foo' and 'bar' are both visible.

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to extend packages
  2008-06-06 17:45 ` Sébastien Morand
  2008-06-07 14:21   ` Stephen Leake
@ 2008-06-07 16:04   ` Simon Wright
  2008-06-07 21:50     ` snoopysalive
  1 sibling, 1 reply; 11+ messages in thread
From: Simon Wright @ 2008-06-07 16:04 UTC (permalink / raw)


S�bastien Morand <seb.morand@gmail.com> writes:

> with GNAT.Regpat; use GNAT.Regpat;

This is not necessary; the parent's spec (including the private part)
is directly visible within the child.

Though I'm not sure what help that would be in future, since in 4.3.0
the spec is ..

   with System.Regpat;

   package GNAT.Regpat renames System.Regpat;

> package GNAT.Regpat.Extended is
> end GNAT.Regpat.Extended;

But the only private type in Regpat is Pattern_Matcher. Is knowledge
of Pattern_Matcher required in order to write OP's extensions? If so,
OP will have to write a child (of System.Regpat, I think).



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to extend packages
  2008-06-07 16:04   ` Simon Wright
@ 2008-06-07 21:50     ` snoopysalive
  2008-06-08 11:09       ` Simon Wright
  0 siblings, 1 reply; 11+ messages in thread
From: snoopysalive @ 2008-06-07 21:50 UTC (permalink / raw)


Ok, I've tried out Sébastien Morand's solution but it's still not
working. To be honest, it's possible that I'm just using the compiler
in a wrong way.

Here's my code:

------------------
-- s-regext.ads --
------------------

with System.Regpat;

package System.Regpat.Extended is
end System.Regpat.Extended;

------------------
-- s-regext.adb --
------------------

pragma No_Body;

-------------
-- rex.adb --
-------------

with System.Regpat.Extended;

procedure Rex is
begin
   null;
end Rex;



When compiling I get this messages:

$ gnatmake rex.adb
gnatbind -x rex.ali
error: "s-regext.ali" not found, "s-regext.ads" must be compiled
gnatmake: *** bind failed.


So, I try to comile s-regext.ads first and get this message:

$ gnatmake s-regext.ads
gnatmake: not allowed to compile "s-regext.ads"; use -a switch, or
compile file with "-gnatg" switch


When trying the -a switch:

$ gnatmake -a s-regext.ads
gcc -gnatpg -c s-regext.ads
s-regext.ads:1:12: warning: no entities of "Regpat" are referenced
gnatmake: "s-regext.ads" compilation error


When trying the -gnatg switch:

$ gnatmake -gnatg s-regext.ads
gnatmake: not allowed to compile "s-regext.ads"; use -a switch, or
compile file with "-gnatg" switch


I don't really understand what's happening here because when
simulating this kind of "inheritance" with packages written by myself,
it is working. Here's the example code:

--------------
-- test.ads --
--------------

with Ada.Text_IO;

package Test is

	procedure Say_Hello;

end Test;


--------------
-- test.adb --
--------------

package body Test is

	procedure Say_Hello is
	begin
		Ada.Text_IO.Put_Line ("Say_Hello");
	end Say_Hello;

end Test;


------------------
-- test-run.ads --
------------------

with Test;

package Test.Run is

	procedure Say_Something;

end Test.Run;


------------------
-- test-run.adb --
------------------

package body Test.Run is
	use Test;

	procedure Say_Something is
	begin
		Ada.Text_IO.Put_Line ("Say_Something");
	end Say_Something;

end Test.Run;


--------------
-- main.adb --
--------------

with Test.Run;

procedure Main is
begin
	Test.Say_Hello;
	Test.Run.Say_Something;
end Main;



$ gnatmake main.adb
gcc -c main.adb
gnatbind -x main.ali
gnatlink main.ali

$ ./main
Say_Hello
Say_Something


So, it seems as if it's not possible to extend packages of the
standard library. Or am I interpreting this in a wrong way?

Last but not least: Thanks for all your answers to my question.

Thanks,
Matthias



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to extend packages
  2008-06-07 21:50     ` snoopysalive
@ 2008-06-08 11:09       ` Simon Wright
  2008-06-09 22:38         ` snoopysalive
  0 siblings, 1 reply; 11+ messages in thread
From: Simon Wright @ 2008-06-08 11:09 UTC (permalink / raw)


Nearly there, I think.

You must use the -a switch, because your new code is an extension to
the compiler library. But one of the GNAT rules for compiling the
compiler library is that warnings are treated as errors. So you have
to fix your code so that it creates no warning messages. One way of
doing this is by using pragma Warnings (Off)! but this should only be
temporary or very very local.



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to extend packages
  2008-06-08 11:09       ` Simon Wright
@ 2008-06-09 22:38         ` snoopysalive
  2008-06-10  5:40           ` Simon Wright
  0 siblings, 1 reply; 11+ messages in thread
From: snoopysalive @ 2008-06-09 22:38 UTC (permalink / raw)


Ok, my codes are compiling and working now. Thanks once more. But,
Simon, can you explain me, where to use "pragma Warnings (Off)"
correctly? Thank you.



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to extend packages
  2008-06-09 22:38         ` snoopysalive
@ 2008-06-10  5:40           ` Simon Wright
  2008-06-14  8:45             ` snoopysalive
  0 siblings, 1 reply; 11+ messages in thread
From: Simon Wright @ 2008-06-10  5:40 UTC (permalink / raw)


"snoopysalive@googlemail.com" <snoopysalive@googlemail.com> writes:

> Ok, my codes are compiling and working now. Thanks once more. But,
> Simon, can you explain me, where to use "pragma Warnings (Off)"
> correctly? Thank you.

This suppresses thw warning that was causing trouble ..

   with System.Regpat;
   pragma Warnings (Off, System.Regpat);

   package System.Regpat.Extended is
   end System.Regpat.Extended;



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to extend packages
  2008-06-10  5:40           ` Simon Wright
@ 2008-06-14  8:45             ` snoopysalive
  0 siblings, 0 replies; 11+ messages in thread
From: snoopysalive @ 2008-06-14  8:45 UTC (permalink / raw)


Ah, okay! Now I have it. Thank you once more!



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2008-06-14  8:45 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-06 17:00 How to extend packages snoopysalive
2008-06-06 17:24 ` witmer
2008-06-06 17:45 ` Sébastien Morand
2008-06-07 14:21   ` Stephen Leake
2008-06-07 16:04   ` Simon Wright
2008-06-07 21:50     ` snoopysalive
2008-06-08 11:09       ` Simon Wright
2008-06-09 22:38         ` snoopysalive
2008-06-10  5:40           ` Simon Wright
2008-06-14  8:45             ` snoopysalive
2008-06-06 18:16 ` Georg Bauhaus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox