Re: Getting the current line number
Geoffrey Alan Washburn <[email protected]>
| Newsgroups | gmane.comp.lang.sml.smlnj |
|---|---|
| Message-ID | <[email protected]> |
John Reppy wrote:
> No, but you might be able to run your sml code through the C preprocessor
> to get that information. I don't know it any SML implementation provides
> this feature, but it might be a useful thing to standardize on (also
> __FILE__).
Ah, __FILE__ would be good too, but I hadn't even thought about that
yet. I'm working on an interpreter/compiler, and I was thinking it
might be useful to fill the line/file fields of syntatic structures
created by the program with the program line and file that created them.
> After thinking about it a bit more, I realized that the following hack
> would work. First, define the following helper function
>
> fun file_line ex = let
> val [s] = SMLofNJ.exnHistory ex
> val (f, r) = Substring.splitl (fn #":" => false | _ => true)
> (Substring.full s)
> val ln = Substring.takel (fn #"." => false | _ => true)
> (Substring.triml 1 r)
> in
> {file = Substring.string f, line = Substring.string ln}
> end;
>
> then you can get the file and line info at a given source code location
> by embedding the following code:
>
> file_line ((raise Fail "") handle ex => ex);
That's quite clever :-) But admittedly too heavyweight for my current
needs, but perhaps I'll use this in a later pass. Thanks!
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl