April 21, 2010 tools.ctfe for D1 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ellery Newcomer | On 20.04.2010 01:49, Ellery Newcomer wrote: > Are there any good libraries for ctfe/code generation? > > I don't know, things like parsing support for compile time strings, string formatting, type <-> string > > My project seems to be growing ctfe, and it's all horribly hacky and ugly code. This might be useful if you're on D1: http://dsource.org/projects/scrapple/browser/trunk/tools/tools/ctfe.d Contents: * ctToString(int) * ctAtoi(string) * ctToLower(string) * ctFind(string, string) * ctFind(string, char) * ctRFind(string, string) * ctStripL(string) * ctStripR(string) * ctStrip(string) * ctSlice(ref string, string where, bool cutOff = true) * ctReplace(string, string, string) * ctBetween(string text, string from, string to, bool adhere_right = false) * ctReplace(string, string, string{, string, string}) * Table parsing code (ctTableHeight, ctTableWidth, ctTableUnrollColMajor, ctTableUnroll, ctTableUnrollColumn, ctTableLookup and related) * ctExpand (turns "foo, bar(0, 1)baz" into "|foo|bar0baz|bar1baz", used for simpler enum generation) |
April 21, 2010 Re: ctfe library | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | bearophile wrote:
> Don:
>> I've found that the function below improves things immensely. I might propose it for std.metastrings in the next Phobos release.
>
> Can you tell me what this function can be useful for?
>
> Thank you, bye,
> bearophile
If you have recursive mixins (such as appears in many of the examples posted by downs), it lets you get rid of the horrible `\"` and backslashes which appear everywhere.
|
April 21, 2010 Re: tools.ctfe for D1 | ||||
---|---|---|---|---|
| ||||
Posted in reply to FeepingCreature | FeepingCreature Wrote:
> On 20.04.2010 01:49, Ellery Newcomer wrote:
> > Are there any good libraries for ctfe/code generation?
> >
> > I don't know, things like parsing support for compile time strings, string formatting, type <-> string
> >
> > My project seems to be growing ctfe, and it's all horribly hacky and ugly code.
>
> This might be useful if you're on D1: http://dsource.org/projects/scrapple/browser/trunk/tools/tools/ctfe.d
>
> Contents:
>
> * ctToString(int)
> * ctAtoi(string)
> * ctToLower(string)
> * ctFind(string, string)
> * ctFind(string, char)
> * ctRFind(string, string)
> * ctStripL(string)
> * ctStripR(string)
> * ctStrip(string)
> * ctSlice(ref string, string where, bool cutOff = true)
> * ctReplace(string, string, string)
> * ctBetween(string text, string from, string to, bool adhere_right = false)
> * ctReplace(string, string, string{, string, string})
> * Table parsing code (ctTableHeight, ctTableWidth, ctTableUnrollColMajor, ctTableUnroll, ctTableUnrollColumn, ctTableLookup and related)
> * ctExpand (turns "foo, bar(0, 1)baz" into "|foo|bar0baz|bar1baz", used for simpler enum generation)
When will Phobos D1 plus be released?
|
April 21, 2010 Re: tools.ctfe for D1 | ||||
---|---|---|---|---|
| ||||
Posted in reply to FeepingCreature | On 04/21/2010 05:43 AM, FeepingCreature wrote:
> On 20.04.2010 01:49, Ellery Newcomer wrote:
>> Are there any good libraries for ctfe/code generation?
>>
>> I don't know, things like parsing support for compile time strings,
>> string formatting, type<-> string
>>
>> My project seems to be growing ctfe, and it's all horribly hacky and
>> ugly code.
>
> This might be useful if you're on D1: http://dsource.org/projects/scrapple/browser/trunk/tools/tools/ctfe.d
>
Looks like itś exactly what I want, thanks!
A couple notes:
Is there any particular license associated with it? (whatever tangoś is would be fine)
When I try to compile, I get forward referencing errors and had to take out the import to tools.compat
|
April 21, 2010 Re: tools.ctfe for D1 | ||||
---|---|---|---|---|
| ||||
Posted in reply to FeepingCreature | Also, are there any examples for usage of the table parsing functions? And to whom do I give attribution? |
April 22, 2010 Re: tools.ctfe for D1 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ellery Newcomer | On 21.04.2010 16:43, Ellery Newcomer wrote: > On 04/21/2010 05:43 AM, FeepingCreature wrote: >> On 20.04.2010 01:49, Ellery Newcomer wrote: >>> Are there any good libraries for ctfe/code generation? >>> >>> I don't know, things like parsing support for compile time strings, string formatting, type<-> string >>> >>> My project seems to be growing ctfe, and it's all horribly hacky and ugly code. >> >> This might be useful if you're on D1: http://dsource.org/projects/scrapple/browser/trunk/tools/tools/ctfe.d >> > > Looks like itś exactly what I want, thanks! > > A couple notes: > > Is there any particular license associated with it? (whatever tangoś is > would be fine) > Feel free to use it as you wish. > When I try to compile, I get forward referencing errors and had to take out the import to tools.compat > Yeah, nevermind that, it just defines string as char[] .. or used to, I think that's in tools.text nowadays. tools.ctfe is pretty independent from the rest of tools. > Also, are there any examples for usage of the table parsing functions? Here's one from my IF language, for converting dynamic into native types: union { bool b; int i; string s; float f; Scope sr; } T to(T)() { const string Table = ` | bool | int | string | float | Scope -----------+---------------+-------------+----------------------+---------+---------- Boolean | b | b | b?q{true}p:q{false}p | ø | ø Integer | i != 0 | i | Format(i) | i | ø String | s == q{true}p | atoi(s) | s | atof(s) | ø Float | ø | cast(int) f | Format(f) | f | ø ScopeRef | !!sr | ø | (sr?sr.fqn:q{(null:r)}p) | ø | sr ScopeValue | sr.value().to!(T) | sr.value().to!(T) | sr.value().to!(T) | sr.value().to!(T) | sr`; mixin(ctTableUnrollColMajor(Table, /* First parameter is the outer template, $COL substituting with the column name, and $BODY substituting with the inner template*/ `static if (is(T == $COL)) switch (flatType) { $BODY default: throw new Exception(Format("Invalid type: ", flatType)); } else `, /* Second parameter is the inner template, $ROW substituting with the row name and $CELL with the cell's content. `case FlatType.$ROW: static if (q{$CELL}p == "ø") throw new Exception(q{Cannot convert $ROW to $COL: }p~to!(string)~q{! }p); else return $CELL; ` ).litstring_expand() /* expand q{}p into ""s with correct nesting */ ~ `static assert(false, "Unsupported type: "~T.stringof); `); } > And to whom do I give attribution? Attribution is not necessary. I'm glad someone finds it useful. |
April 23, 2010 Re: tools.ctfe for D1 | ||||
---|---|---|---|---|
| ||||
Posted in reply to FeepingCreature | well, here you are: http://www.dsource.org/projects/dexcelapi/browser/trunk/src/dxl/util/ctfe.d and here is where I use it: http://www.dsource.org/projects/dexcelapi/browser/trunk/src/dxl/biff/Enums.d I don't think it's worth the effort of changing that stuff to work with your table parsing, but if you make your tables work with '\u2500' and friends, I might do it.. On 04/22/2010 12:36 PM, FeepingCreature wrote: > On 21.04.2010 16:43, Ellery Newcomer wrote: >> On 04/21/2010 05:43 AM, FeepingCreature wrote: >>> On 20.04.2010 01:49, Ellery Newcomer wrote: >>>> Are there any good libraries for ctfe/code generation? >>>> >>>> I don't know, things like parsing support for compile time strings, >>>> string formatting, type<-> string >>>> >>>> My project seems to be growing ctfe, and it's all horribly hacky and >>>> ugly code. >>> >>> This might be useful if you're on D1: >>> http://dsource.org/projects/scrapple/browser/trunk/tools/tools/ctfe.d >>> >> >> Looks like itś exactly what I want, thanks! >> >> A couple notes: >> >> Is there any particular license associated with it? (whatever tangoś is >> would be fine) >> > > Feel free to use it as you wish. > >> When I try to compile, I get forward referencing errors and had to take >> out the import to tools.compat >> > > Yeah, nevermind that, it just defines string as char[] .. or used to, I think that's in tools.text nowadays. tools.ctfe is pretty independent from the rest of tools. > >> Also, are there any examples for usage of the table parsing functions? > > Here's one from my IF language, for converting dynamic into native types: > > union { > bool b; > int i; > string s; > float f; > Scope sr; > } > T to(T)() { > const string Table = ` > | bool | int | string | float | Scope > -----------+---------------+-------------+----------------------+---------+---------- > Boolean | b | b | b?q{true}p:q{false}p | ø | ø > Integer | i != 0 | i | Format(i) | i | ø > String | s == q{true}p | atoi(s) | s | atof(s) | ø > Float | ø | cast(int) f | Format(f) | f | ø > ScopeRef | !!sr | ø | (sr?sr.fqn:q{(null:r)}p) | ø | sr > ScopeValue | sr.value().to!(T) | sr.value().to!(T) | sr.value().to!(T) | sr.value().to!(T) | sr`; > mixin(ctTableUnrollColMajor(Table, > /* First parameter is the outer template, $COL substituting with the column name, and $BODY substituting with the inner template*/ > `static if (is(T == $COL)) > switch (flatType) { > $BODY > default: throw new Exception(Format("Invalid type: ", flatType)); > } > else `, > /* Second parameter is the inner template, $ROW substituting with the row name and $CELL with the cell's content. > `case FlatType.$ROW: > static if (q{$CELL}p == "ø") > throw new Exception(q{Cannot convert $ROW to $COL: }p~to!(string)~q{! }p); > else return $CELL; > ` > ).litstring_expand() /* expand q{}p into ""s with correct nesting */ ~ `static assert(false, "Unsupported type: "~T.stringof); `); > } > > >> And to whom do I give attribution? > > Attribution is not necessary. I'm glad someone finds it useful. |
Copyright © 1999-2021 by the D Language Foundation