extend include directive to add rule prefix/suffix

Let the developers know what you think of the software and what can be done to either improve the CFDG language or the Context Free program.

Moderators: MtnViewJohn, chris, mtnviewmark

Post Reply
User avatar
kipling
Posts: 91
Joined: Wed Jun 18, 2008 2:36 am

extend include directive to add rule prefix/suffix

Post by kipling »

Is it possible to extend the parsing of include files to optionally add prefixes or suffixes rule and path names - both definitions and instances?
e.g. so that this:

Code: Select all

// ---- start foo.cfdg
include bar.cfdg prefix "bar_"
rule A{bar_A{s .5}}
rule bar_A .01{}
...
// ---- end foo.cfdg
// ---- start bar.cfdg
rule A{CIRCLE{} A{s .9 x 1 r 5}}
// ---- end bar.cfdg
is functionally equivalent to this:

Code: Select all

// ---- start foo.cfdg
include bar2.cfdg 
rule A{bar_A{s .5}}
rule bar_A .01{}
...
// ---- end foo.cfdg
// ---- start bar2.cfdg
rule bar_A{CIRCLE{} bar_A{s .9 x 1 r 5}}
// ---- end bar2.cfdg
This would just need some on-the-fly translation while parsing include files. If it is done, the only decision (as I can see it) is how nested includes are handled. There are two obvious options, either of which would work.
Obviously I am asking this to make CF a little more modular, while still permitting messing around with the internals of imported rules - not fully encapsulated. It would be fun to do some mashups of gallery designs without having to recode them to remove name clashes.

User avatar
MtnViewJohn
Site Admin
Posts: 882
Joined: Fri May 06, 2005 2:26 pm
Location: Mountain View, California
Contact:

Re: extend include directive to add rule prefix/suffix

Post by MtnViewJohn »

I think I would prefer to implement namespaces, a common feature in many languages.

Code: Select all

// ---- start foo.cfdg
namespace bar {
include bar.cfdg
}

rule A{bar::A{s .5}}
rule bar::A .01{}
...
// ---- end foo.cfdg
// ---- start bar.cfdg
rule A{CIRCLE{} A{s .9 x 1 r 5}}
// ---- end bar.cfdg
In addition to allowing includes without name clashes, this would allow you to directly copy someone's code into your cfdg file without worrying about name clashes.

Code: Select all

namespace bar {
rule A{CIRCLE{} A{s .9 x 1 r 5}}
}

rule A{bar::A{s .5}}
rule bar::A .01{}
...

User avatar
kipling
Posts: 91
Joined: Wed Jun 18, 2008 2:36 am

Re: extend include directive to add rule prefix/suffix

Post by kipling »

yes, that would do the job.

Post Reply