[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: line numbers using read
From: |
Peter S. Christopher |
Subject: |
Re: line numbers using read |
Date: |
Fri, 26 Dec 2003 16:07:12 -0600 (CST) |
Hi listers,
Yes I know ... I'm replying to my own question. I realized that
the `source-property' mechanism with the (read-enable 'positions) is what
I need. So if I read in my santas-list example to a variable named `data'
I can get the line number of the `billy' clause via
================================
(read-enable 'positions)
......
......
(display (cadddr data)) ; displays `(billy (parents non-abusive))'
(newline)
(display (source-property (cadddr data) 'line)) ; displays `3'
(newline)
================================
Also, one can get an A-list of ALL the properties using source-properties.
Sorry for the noise folks.
Pete
On Fri, 26 Dec 2003, Peter S. Christopher wrote:
> Hi listers,
>
> I have an issue that has been biting at me. Suppose that I create
> an input file syntax that is fairly complicated. For example:
>
> (santas-list
> (bobby toy-truck)
> (cindy doll)
> (billy (parents non-abusive)))
>
> Now it is easy enough to read this in using `(read port)'. However, if
> this list is long and the user messes the input file up, I don't know
> how to tell the user where the error is. That is, Suppose that
> `santas-list' is a few hundred elements long. I want to be able to
> tell the user where they messed up: something like
>
> In subexpression `(billy (parents non-abusive))'
> ON LINE 4: Santa cannot give `billy' `non-abusive' `parents'
>
> The crux of my question is: how do I find out that the `billy'
> subexpression started on line 4 USING READ?
>
> The last part of my question is important, I only want to use the read
> call to do the parsing. Naturally, there are more complicated solutions
> where someone hand-rolls there own version of read -- lets not go into
> that right now.
>
> Now, I ask this question because in libguile/read.c the function
> scm_lreadr (which seems to be the meat of the read routine) makes many
> weak hash inserts to a hash table called `scm_source_whash'. I am
> ASSUMING that one can take a expression (list of symbols), look it up
> in this hash and get it's line/column number. *** Is this true? ***
>
> I assume that `scm_eval' uses this hash when it needs to flag an
> error. So why (I think) couldn't I when I'm dealing with santas-list.
>
> Any thoughts, clarifications or comments would be appreciated.
>
> Pete
>
>
>
>
>
> _______________________________________________
> Guile-user mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/guile-user
>