compile-time regex redux
janderson
askme at me.com
Thu Feb 8 22:41:42 PST 2007
kenny wrote:
> BCS wrote:
>> Walter Bright wrote:
>>> kenny wrote:
>>>
>>>> I know I'm asking for a lot, but the way templates handle string are
>>>> still kinda weird to me. Would string parsing in this sort of way be
>>>> absolutely impossible with templates? I have not had good luck with it.
>>>
>>>
>>> I just haven't thought about this enough. Certainly, however, solving
>>> the problem in a more general, D-ish way than regex would be a much
>>> bigger win. Regex works only for a subset of problems (can't do
>>> recursive descent parsing with it).
>>
>> As I see it the biggest problem with compile time parsing in D is that
>> building non linear structure is a pain. Tuples implicitly cated when
>> passed together an this make some things really hard. Allowing a tuple
>> to be a member of another tuple would put D template in the same class
>> as LISP.
>>
>> Another things that might make things easier is some way to mark a
>> template as "evaluate to value and abandon". This would cause the
>> template to be processed but none of the symbols generated by it would
>> be kept, only the value. Of course, suitable restrictions would apply.
>
> so it would be like writing normal D code inside of a template? Could we
> use phobos or do more metastring functions like find, strip, etc. need
> to be reinvented in D. Or can I take those functions and just put a
> wrapper around it? I think this is getting into the security issues
> again, but something like this:
>
> auto my_text = meta trim_whitespace(import("myxml.xml")); // obviously a
> better keyword should be used, and can only be used in global scope too.
>
> where trim_whitespace is an actual function that is actually defined up
> in the file somewhere, and will be compiled, used on the import file,
> then discarded and the result stored into auto my_text? A day or so ago,
> someone mentioned a .rc compiler. I personally would use it to parse
> stuff for interface elements .. to generate them dynamically. We already
> have libraries to parse XML (XHTML), CSS, and other config type things.
I don't see any security issues if the compile-time language is
restrictive enough. You could still load in files using the new import
command.
> It would be SUPER AWESOME to be able to just re-use them as a template
> without any other extra work!!! Oh man, that has me really excited, if
> that's possible :)
>
> woah!
I agree, this is only a sub-set of what could be done. You could even
try out / invent new language features for D before suggesting them on
the newsgroup and post the code. Of course that may be a possibility
with regex as well.
-Joel
More information about the Digitalmars-d
mailing list