<br><br><div class="gmail_quote">On Wed, Nov 28, 2012 at 10:40 PM, Daniel N <span dir="ltr"><<a href="mailto:ufo@orbiting.us" target="_blank">ufo@orbiting.us</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thanks to the wonderful UDA implementation in 2.061, I thought of a little hack, which may interest at least someone.<br>
<br>
I'm using it for prototyping ctfe ast transformations together with: <a href="https://github.com/PhilippeSigaud/Pegged" target="_blank">https://github.com/<u></u>PhilippeSigaud/Pegged</a></blockquote><div><br></div><div>
Aha!</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Yes, it was possible to do similar stuff before and "examples/dgrammar.d" from Pegged is quite impressive, but not bug free.<br></blockquote><div><br></div><div>No kidding :)</div><div>I've a few contributors who're helping me stabilize / make the engine better. We will tackle the D grammar afterwards. It does make a good testing ground for when I want to push the CTFE throttle.</div>
<div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This UDA-line-hack-way is actually significantly cleaner, because when using __LINE__ you are certain that there will be at least one [__LINE__] which is not inside a string or comment on the attributed line... this allows one to make a very limited grammar/parser which doesn't have to know/parse/understand the entire file.<br>
</blockquote><div><br></div><div>I don't understand what you're trying to do. Could you please explain it a bit more? UDA's a quite new and I'd be very interested in their interaction with compile-time code manipulation.</div>
<div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
If anyone else have fun UDA hacks, considering that it's a new feature, please share.<br>
<br>
import std.string;<br>
import std.range;<br>
<br>
struct magic<br>
{<br>
  [__LINE__] int var1;<br>
  [__LINE__] int var2;<br>
  [__LINE__] int var3;<br>
}<br>
<br>
enum dsrc = import(__FILE__).splitLines(<u></u>KeepTerminator.yes);<br>
<br>
string parse()<br>
{<br>
  string result = "";<br>
<br>
  foreach(m; __traits(allMembers, magic))<br>
    result ~= dsrc.drop(__traits(<u></u>getAttributes, mixin("magic." ~ m))[0]-1).takeOne().front;<br></blockquote><div><br></div><div>What I don't get is how the [__LINE__] part in magic contains significant info.</div>
<div><br></div><div><br></div></div>